3

I wrote a Parser for a GML file from the OS Mastermap with geotools 8.4. With one part I still have a problem. This sniplet of the 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>

The part from the gml file:

<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>

It gets parsed nearly right, i.e. the polyline is correct (I get a class com.vividsolutions.jts.geom.LineString) but I only get one (instead of two) directedNode.

My code:

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());
}

And the output:

id: osgb4000000023204016
polyline: LINESTRING (516609 257678, 516615 257733, 516618 257786)
directedNode: '{orientation=-, href=#osgb4000000027916595}' class java.util.HashMap

What am I doing wrong? Why don't I get both directedNode? How can I do the binding to real Java Objects?

2

In the loop you are calling Object dnode = feature.getAttribute("directNode");. As described in the SimpleFeature's documentation, the call will return only one node, either the first or the last in the list, the documentation does not say. If you want to retrieve all nodes, you should call getAttributes(). While you need to check the names yourself, it would solve your problem.

While quite some time has passed, it might still be relevant to readers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.