// 创建个点用于转换 val geometryFactory: GeometryFactory = JTSFactoryFinder.getGeometryFactory val coord: Coordinate = newCoordinate(121, 32) val point: Point = geometryFactory.createPoint(coord)
val mathTransform = CRS.findMathTransform(CRS.decode("EPSG:4490"), CRS.decode("EPSG:4528")) val newPoint: Point = JTS.transform(point, mathTransform).asInstanceOf[Point]
// 创建个点用于转换 val geometryFactory: GeometryFactory = JTSFactoryFinder.getGeometryFactory val coord: Coordinate = newCoordinate(121, 32) val point: Point = geometryFactory.createPoint(coord)
val hints = newHints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true) val factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints) val mathTransform = CRS.findMathTransform(factory.createCoordinateReferenceSystem("EPSG:4490"), factory.createCoordinateReferenceSystem("EPSG:4528")) val newPoint: Point = JTS.transform(point, mathTransform).asInstanceOf[Point]
通过手动指定了轴序,转出来的结果就是正确的了。
SuperMap iObject for Spark
我是在 Spark 环境下使用坐标转换,超图的 SuperMap iObject for Spark 中也引了一下这个方法。这里改成超图 iObject 里的方法。
// 创建个点用于转换 val geometryFactory: GeometryFactory = JTSFactoryFinder.getGeometryFactory val coord: Coordinate = newCoordinate(121, 32) val point: Point = geometryFactory.createPoint(coord)
val hints = newHints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true) val factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints) val mathTransform = CRSTransform.findMathTransform(factory.createCoordinateReferenceSystem("EPSG:4490"), factory.createCoordinateReferenceSystem("EPSG:4528")) val newPoint: Point = CRSTransform.transform(point, mathTransform).asInstanceOf[Point]