У меня есть координата в формате EPSG: 3857, и мне нужно преобразовать ее в EPSG: 4326.Для трансформации я использую геотрусы.Когда я посмотрел каждый пример, который я смог найти, но я, кажется, получил исключение, которое нигде не объясняется.
Вот что я пытаюсь сделать.
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.
Если кто-нибудь скажет мне, что я делаю здесь, я был бы очень признателен.