gpt4 book ai didi

java - 如何在 JTS 中将 jts.geom.Geometry 对象的坐标从 Lat、Long 转换为 Long、Lat

转载 作者:行者123 更新时间:2023-11-29 09:40:47 25 4
gpt4 key购买 nike

我有一个类型为 (com.vividsolutions.jts.geom.Geometry) 的几何对象。它目前处于纬度、经度形式,我想翻转坐标,以便它的经度纬度,以便我可以将它以 GeoJSON 格式用于 mongodb。

我看到的约束是:a) 我想为其翻转坐标的输入是一个 Geometry 对象。b) 几何对象将是多边形类型或多边形。c) 我想在类型转换为 Polygon/multipolygon 之前翻转坐标

我试过 geo.reverse() 但它不起作用。

同样,我尝试使用:CRSAuthorityFactory 工厂 = CRS.getAuthorityFactory(true);CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");

还有另一个选项,但我没有看到它起作用。

谢谢!

最佳答案

您可以使用坐标过滤器来反转给定几何中的所有 x 和 y 值。

private static class InvertCoordinateFilter implements CoordinateFilter {
public void filter(Coordinate coord) {
double oldX = coord.x;
coord.x = coord.y;
coord.y = oldX;
}
}

然后这样应用过滤器:

// Invert Coordinates since GeoJSON likes them that way
myGeometryObj.apply(new InvertCoordinateFilter());

关于java - 如何在 JTS 中将 jts.geom.Geometry 对象的坐标从 Lat、Long 转换为 Long、Lat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27623620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com