添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a coordinate in the format EPSG:3857 and need to transform it to EPSG:4326. For the transformation I use geotools. When looked up every example I could find but I seem to get an exception that is not explained anywhere.

Here is what I try to do.

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

When executing this code I always get the following exception:

org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:3857" from authority "EPSG" found for object of type "EngineeringCRS".

The exception gets thrown when trying to create the sourceCRS.

If anyone could tell me what I do wrong here I would appreciate it very much.

From an answer by Oscar Fonts on: http://osgeo-org.1560.x6.nabble.com/Facing-NoSuchAuthorityCodeException-problem-when-deployed-GeoTools-on-server-td4885362.html

To decode a CRS code, you need access to the EPSG database, which it 
seems it's not present. 
* Make sure you add gt-epsg-hsql in your project, and its 
depencencies, if any (you could use other EPSG factories as well, but 
that's the most usual). 
* To see what factories are available, you can iterate through 
ReferencingFactoryFinder.getCRSAuthoriyFactories. See if 
ThreadedEpsgHsqlFactory is there. 
* Better use CRS.decode("EPSG:4326"), which will loop through all 
available factories, and is a more compact code. 
Hope this helps. 
                or you could link to the FAQ - docs.geotools.org/latest/userguide/library/referencing/faq.html
– Ian Turton
                Mar 5, 2019 at 18:09
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.