locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.95k stars 440 forks source link

Reading the M value in GeoTools? #469

Open Nathipha opened 5 years ago

Nathipha commented 5 years ago

This is more a question than an issue but I hope that someone's still able to help me:

I'm using the GeoTools library (version "23-SNAPSHOT", downloaded through Maven), which also includes jts, and while I managed to make it write CoordinateXYZMs into a ".shp" file I simply can't get it to read the "m" value again.

Coordinate c = myGeometry.getCoordinate(); //c.getM() returns "NaN"
CoordinateXYZM cxyzm = new CoordinateXYZM(c); //cxyzm.getM() returns "0.0"

How do I accomplish this? Do I need a specific type of reader to properly pass the m value through, so "getM()" returns the actual one?

jnh5y commented 5 years ago

@Nathipha this is a good question. We've added some to the Measure support in JTS recently and we may not have wired everything through in GeoTools. @jodygarnett and I think about those kinds of things (as time allows).

Would you mind sharing a sample of your JTS+GeoTools code in this issue? Also, at some point, we may need to raise an issue/JIRA with GeoTools.

Nathipha commented 5 years ago

Thanks for your fast reply!

Of course, I posted the code on StackExchange and also asked for help with the import there. I got this answer:

From a quick look at the ShapeFile reading code it appears that GeoTools just reads the M value and throws it away. So it looks like what you are trying to do is impossible. I haven't tested it but if you change line 89 [src/main/java/org/geotools/data/shapefile/shp/PointHandler.java] to cs.setOrdinate(0, CoordinateSequence.M, buffer.getDouble()); it should work.

Unfortunately I haven't managed to import the Git project (I use Eclipse+Maven) properly yet, so I can't change the code and test it.

I'm also going to open an issue on their website (if possible).

You can find my code for writing the shapefile here and this code I use for reading.

Edit: I opened an issue.