Skip to content

Instantly share code, notes, and snippets.

@mtoonen
Last active April 12, 2016 08:15
Show Gist options
  • Save mtoonen/dc33661215bffcfb37820afe6fe97a20 to your computer and use it in GitHub Desktop.
Save mtoonen/dc33661215bffcfb37820afe6fe97a20 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<gml:Surface gml:id="ID2">
<gml:patches>
<gml:PolygonPatch>
<gml:exterior>
<gml:LinearRing>
<gml:posList>0 0 0 1 1 1 1 0 0 0</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:PolygonPatch>
</gml:patches>
</gml:Surface>
<?xml version="1.0"?>
<gml:Surface>
<gml:surfaceMember>
<gml:Surface gml:id="ID2">
<gml:patches>
<gml:PolygonPatch>
<gml:exterior>
<gml:LinearRing>
<gml:posList>0 0 0 1 1 1 1 0 0 0</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:PolygonPatch>
</gml:patches>
</gml:Surface>
</gml:surfaceMember>
</gml:Surface>
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
org.geotools.xml.Configuration configuration = new org.geotools.gml3.GMLConfiguration();
org.geotools.xml.Parser parser = new org.geotools.xml.Parser(configuration);
// Original gml snippet which failed
//String exampleString = "<gml:MultiSurface gml:id=\"id.f4e80081824b48ca9754558371125be3\"><gml:surfaceMember><gml:Surface gml:id=\"id.1004c5c688a6471fbf2b5c42054e0339\" srsName=\"urn:ogc:def:crs:EPSG::28992\"><gml:patches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList>139693.376 419978.411 139675.069 419971.055 139634.307 419954.669 139633.145 419954.201 139612.624 419945.945 139613.839 419943.733 139628.533 419917.004 139638.949 419898.131 139654.115 419904.284 139674.171 419912.416 139687.148 419917.593 139700.126 419922.776 139714.122 419928.554 139702.423 419957.444 139693.376 419978.411</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:patches></gml:Surface></gml:surfaceMember><gml:surfaceMember><gml:Surface gml:id=\"id.937e0adcff5b48c6b06b34330139d0ca\" srsName=\"urn:ogc:def:crs:EPSG::28992\"><gml:patches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList>139656.677 420063.567 139656.53 420063.509 139657.972 420059.901 139669.301 420031.559 139676.449 420013.678 139681.916 420000 139685.938 419989.938 139708.297 419999.354 139709.866 420000 139713.377 420001.445 139731.775 420009.02 139756.081 420019.048 139761.352 420021.223 139763.393 420021.938 139752.044 420049.156 139745.856 420064.33 139741.683 420065.892 139741.268 420066.043 139731.774 420069.49 139714.694 420076.177 139701.958 420081.593 139681.098 420073.115 139656.677 420063.567</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:patches></gml:Surface></gml:surfaceMember></gml:MultiSurface>";
// Simplified gml snippet that fails
String exampleString = "<?xml version=\"1.0\"?><gml:Surface><gml:surfaceMember><gml:Surface gml:id=\"ID2\"><gml:patches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList>0 0 0 1 1 1 1 0 0 0</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:patches></gml:Surface></gml:surfaceMember></gml:Surface>";
// GML snippet with removed surfaceMember tags (and removed extra Surface tag). This one works
//String exampleString = "<?xml version=\"1.0\"?><gml:Surface gml:id=\"ID2\"><gml:patches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList>0 0 0 1 1 1 1 0 0 0</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:patches></gml:Surface>";
exampleString = exampleString.replaceAll("gml:", "");
InputStream stream = new ByteArrayInputStream(exampleString.getBytes(StandardCharsets.UTF_8));
Object o = parser.parse(stream);
assertEquals(MultiPolygon.class, o.getClass());
MultiPolygon mp = (MultiPolygon)o;
assertFalse(mp.isEmpty());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment