【发布时间】:2019-03-05 22:41:06
【问题描述】:
我有一个格式为 EPSG:3857 的坐标,需要将其转换为 EPSG:4326。对于转换,我使用 geotools。当查找我能找到的每个示例时,我似乎得到了一个没有在任何地方解释的异常。
这是我尝试做的。
private CoordinateReferenceSystem sourceCRS;
private CoordinateReferenceSystem targetCRS;
private GeoCoordinate transform(GeoCoordinate geoCoordinate)
throws FactoryException,
TransformException {
CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);
this.sourceCRS = factory.createCoordinateReferenceSystem("EPSG:3857");
this.targetCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
// Or i try to use the CRS directly, that does not change anything
// this.targetCRS = CRS.decode("EPSG:4326");
// this.sourceCRS = CRS.decode("EPSG:3857");
MathTransform transform = CRS.findMathTransform(this.sourceCRS, this.targetCRS, false);
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
Point point =
geometryFactory.createPoint(new Coordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()));
Point targetPoint = (Point) JTS.transform(point, transform);
return new GeoCoordinate(targetPoint.getX(), targetPoint.getY());
}
执行此代码时,我总是遇到以下异常:
org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:3857" from authority "EPSG" found for object of type "EngineeringCRS".
尝试创建 sourceCRS 时抛出异常。
如果有人能告诉我我在这里做错了什么,我将不胜感激。
【问题讨论】:
-
你见过这个吗? -> osgeo-org.1560.x6.nabble.com/…
-
这确实是个问题,非常感谢
-
我会把它变成一个答案,以防链接失效。
标签: java openlayers geotools