我使用 geotools 8.4 为 OS Mastermap 中的 GML 文件编写了一个解析器。有一部分我仍然有问题。xsd的这个片段:
<complexType name="RoadLinkType">
<complexContent>
<extension base="osgb:AbstractFeatureType">
<sequence>
<element name="polyline" type="gml:GeometryPropertyType"/>
<element name="directedNode" type="osgb:directedNodeAssociationType" minOccurs="2" maxOccurs="2"/>
</sequence>
</extension>
</complexContent>
</complexType>
gml 文件中的部分:
<osgb:RoadLink fid='osgb4000000023204016'>
<osgb:polyline>
<gml:LineString srsName='osgb:BNG'>
<gml:coordinates>516609.000,257678.000 516615.000,257733.000 516618.000,257786.000</gml:coordinates>
</gml:LineString>
</osgb:polyline>
<osgb:directedNode orientation='-' xlink:href='#osgb4000000027916595'/>
<osgb:directedNode orientation='+' gradeSeparation='1' xlink:href='#osgb4000000028203009'/>
</osgb:RoadLink>
它被解析得几乎正确,即折线是正确的(我得到一个类 com.vividsolutions.jts.geom.LineString),但我只得到一个(而不是两个)directedNode。
我的代码:
GML gml = new GML(Version.GML3);
CRSAuthorityFactory crsFac = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
CoordinateReferenceSystem osgbCrs = crsFac.createCoordinateReferenceSystem("EPSG:27700");
gml.setCoordinateReferenceSystem(osgbCrs);
SimpleFeatureIterator iter = gml.decodeFeatureIterator(in);
while (iter.hasNext())
{
SimpleFeature feature = iter.next();
System.out.println("id: " + feature.getID());
System.out.println("polyline: " + feature.getAttribute("polyline"));
Object dnode = feature.getAttribute("directedNode");
System.out.println("directedNode: '" + dnode + "'\t" + dnode.getClass());
}
和输出:
id: osgb4000000023204016
polyline: LINESTRING (516609 257678, 516615 257733, 516618 257786)
directedNode: '{orientation=-, href=#osgb4000000027916595}' class java.util.HashMap
我究竟做错了什么?为什么我不同时得到两个directedNode?如何绑定到真正的 Java 对象?