I have been trying to use JTS within Apache Ignite in correlation with GPS coordinates. So far I am not sure how or if those could interact. For example if I calculate a distance between two geometries, I will have a planar distance, but how would I convert it back to distance at the surface of the earth ?
For reference here is some code I used, I am not sure the transformations are correct though, but it's not the root of the problem:
Coordinate coord1 = convertToRect(resultCoord.y, resultCoord.x, 0.0);
Coordinate coord2 = convertToRect(latitude, longitude, 0.0);
double dist = new GeometryFactory().createPoint(coord1).distance(new GeometryFactory().createPoint(coord2));
...
private Coordinate convertToRect(Double lat, Double lon, Double alt) {
MathTransform ecefTransform = org.geotools.referencing.CRS.findMathTransform(DefaultGeographicCRS.WGS84_3D, DefaultGeocentricCRS.CARTESIAN);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Point p = geometryFactory.createPoint(new Coordinate(lat, lon, alt));
Geometry tp = JTS.transform(p, ecefTransform);
return tp.getCoordinate();
}
So maybe JTS is not meant to be used to perform geolocation on earth ? Otherwise would you know where I could find references of such usage ?
For reference the used libs:
compile 'org.opengis:geoapi:3.0.1'
compile 'org.geotools:gt-api:2.7.5'
compile 'org.geotools:gt-shapefile:2.7.5'
compile group: 'org.apache.ignite', name: 'ignite-geospatial', version: '2.5.2'
Thanks
If you are looking for distance in meters, you could use the GeoTools libraries GeodeticCalculator. As a shorthand, JTS handles geometry and GeoTools (and other libraries) are designed to help with geography.
http://docs.geotools.org/stable/userguide/library/referencing/calculator.html http://docs.geotools.org/stable/javadocs/org/geotools/referencing/GeodeticCalculator.html