【问题标题】:Why do i get a NoSuchAuthorityCodeException when creating a CoordinateReferenceSystem?为什么在创建 CoordinateReferenceSystem 时会出现 NoSuchAuthorityCodeException?
【发布时间】: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 时抛出异常。

如果有人能告诉我我在这里做错了什么,我将不胜感激。

【问题讨论】:

标签: java openlayers geotools


【解决方案1】:

来自 Oscar Fonts 的回答: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. 

【讨论】:

猜你喜欢
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 2018-12-15
  • 2016-08-13
  • 2018-11-10
  • 1970-01-01
  • 2012-11-19
  • 2015-01-14
相关资源
最近更新 更多