Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jts-dev] Possible bug in the CoordinateXYM class?

That looks like a bug in the Geotools code.  (It seems odd that apparently both M and Z values are stored into the CoordinateSequence.M ordinate position?). It's likely that this code has not been changed to reflect the more specific way that JTS now stores Z and M values in coordinates. 

The JTS API is working as designed. Unfortunately the API is more complicated to use since the introduction of different coordinate types.

The difference between CoordinateSequence.M and CoordinateXYM.M is very unfortunate.  All I can say is that the CoordinateSequence.M Javadoc has the disclaimer: "This constant assumes XYZM coordinate sequence definition".


 

On Tue, Nov 24, 2020 at 1:00 AM Eivind Rønnevik <eivind.ronnevik@xxxxxxxxx> wrote:
Hi all,

I have been trying to read a shapefile using the Geotools libraries, but I get an exception like this when I attempt to iterate the features:

java.lang.IllegalArgumentException: Invalid ordinate index: 3
at org.locationtech.jts.geom.CoordinateXYM.setOrdinate(CoordinateXYM.java:146)
at org.locationtech.jts.geom.impl.CoordinateArraySequence.setOrdinate(CoordinateArraySequence.java:305)
at org.geotools.data.shapefile.shp.PolygonHandler.readCoordinates(PolygonHandler.java:311)
at org.geotools.data.shapefile.shp.PolygonHandler.read(PolygonHandler.java:142)
at org.geotools.data.shapefile.shp.ShapefileReader$Record.shape(ShapefileReader.java:113)
at org.geotools.data.shapefile.ShapefileFeatureReader.getGeometry(ShapefileFeatureReader.java:238)
at org.geotools.data.shapefile.ShapefileFeatureReader.hasNext(ShapefileFeatureReader.java:181)


I have been using Geotools (and JTS) successfully for 8-10 years, so I don't consider myself a rookie as such, but still there might be something I have misunderstood here, and I am by far any expert on GIS matters. But this is the first time I have met such an exception despite having processed hundreds of shapefiles before.

I attempted to debug this case, and doing so I found something which I wonder if could be the cause of the problem above.

First of all, the library versions in play:
- JTS: 1.17.1
- Geotools: 24.0

Then, some parameters pulled out from the operation in question:
flatFeature: false
dimensions: 2
numParts: 1
numPoints: 1099
shapeType = PolygonM


Then, when the PolygonHandler of Geotools is going to read the coordinates, it invokes the following:
image.png

So when setting the ordinateIndex, Geotools makes use of CoordinateSequence.M from JTS.
It is defined like:
int M = 3;

But then when the CoordinateXYM.class is going to handle this setOrdinate() operation, despite M (with value 3) being passed from Geotools, we end up in the default case and throw an exception. And if we check the definition of "M" in the CoordinateXYM.class, it is defined as
public static final int M = 2;
image.png

So this is what my question boils down to, the definition of M is different in these two classes:

org.locationtech.jts.geom.CoordinateXYM.CLASS
public static final int M = 2;

org.locationtech.jts.geom.CoordinateSequence.CLASS
int M = 3;


Is that correct?

Unfortunately I cannot supply the shapefile in question as it holds sensitive data.

Kind Regards,
Eivind Rønnevik

_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/jts-dev

Back to the top