JTS + reading geodata: Number of points must be 0 or >3

405 Views Asked by At

I'm trying to read some geodate from file. I'm using the geotools package in java. I have the geodata available as kml, gml and.shp, those are pretty big files. Those come from an external bron and are formatted correctly.

When I want to read tools, GeoTools uses JTS. I also tried working with JTS directly but I get the same error message. The error I get is:

java.lang.IllegalArgumentException: Number of points must be 0 or >3
    at com.vividsolutions.jts.geom.LinearRing.validateConstruction(LinearRing.java:98)
    at com.vividsolutions.jts.geom.LinearRing.<init>(LinearRing.java:90)
    at com.vividsolutions.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:324)
    at com.vividsolutions.jts.geom.GeometryFactory.createLinearRing(GeometryFactory.java:314)

I get this error halfway through the file. I checked all files manually: all "linearrings" have more than three points. It also doesn't matter which file I'm trying to read.

Code snippet:

File file = new File(bwkFilePath);
Map map = new HashMap();
map.put("url", file.toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);

A part from a KML-file

<MultiGeometry>
<Polygon>
<altitudeMode>
relativeToGround
</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
 5.301275,50.883145,1 5.301244,50.883233,1 5.301302,50.88329999999999,1 5.301146,50.883552,1 5.301037,50.883757,1 5.301124,50.88386299999999,1 5.301524,50.884123,1 5.301924,50.88421500000001,1 5.302014,50.884129,1 5.301751,50.88367,1 5.301275,50.883145,1 
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Point>
<coordinates>
5.30152,50.883681,0
</coordinates>
</Point>
</MultiGeometry>
1

There are 1 best solutions below

2
On

All linearring must have 3 point at least and also their first point and last point must be same.

in this example its true but may be your file contains wrong one.