首页 > 解决方案 > 点燃 JTS WGS84

问题描述

我一直在尝试在 Apache Ignite 中使用与 GPS 坐标相关的 JTS。到目前为止,我不确定它们如何或是否可以交互。例如,如果我计算两个几何图形之间的距离,我将有一个平面距离,但我如何将其转换回地球表面的距离?

这里是我使用的一些代码作为参考,虽然我不确定转换是否正确,但这不是问题的根源:

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();
}

那么也许 JTS 不是用来在地球上执行地理定位的?否则你会知道我在哪里可以找到这种用法的参考资料吗?

供参考使用的库:

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'

谢谢

标签: ignitejtswgs84

解决方案


如果您正在寻找以米为单位的距离,您可以使用 GeoTools 库 GeodeticCalculator。简而言之,JTS 处理几何,GeoTools(和其他库)旨在帮助处理地理。

http://docs.geotools.org/stable/userguide/library/referencing/calculator.html http://docs.geotools.org/stable/javadocs/org/geotools/referencing/GeodeticCalculator.html


推荐阅读