NoSuchAuthorityCodeExcpetion in geotools program (gradle build) converting between coordinate systems

大兔子大兔子 提交于 2021-01-28 02:58:08

问题


I have a java geotools program to convert a coordinate between two coordinate systems. It attempts to convert between coordinate system ESPG:4326 and ESPG:5179.

I receive the following exception when trying to execute this line in my code:

CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

Exception in thread "main" org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:4326" from authority "EPSG" found for object of type "EngineeringCRS".
    at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.noSuchAuthorityException(CartesianAuthorityFactory.java:137)
    at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createEngineeringCRS(CartesianAuthorityFactory.java:129)
    at org.geotools.referencing.factory.epsg.CartesianAuthorityFactory.createCoordinateReferenceSystem(CartesianAuthorityFactory.java:120)
    at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:780)
    at org.geotools.referencing.factory.ThreadedAuthorityFactory.createCoordinateReferenceSystem(ThreadedAuthorityFactory.java:636)
    at org.geotools.referencing.DefaultAuthorityFactory.createCoordinateReferenceSystem(DefaultAuthorityFactory.java:177)
    at org.geotools.referencing.CRS.decode(CRS.java:517)
    at org.geotools.referencing.CRS.decode(CRS.java:440)
    at main.main(main.java:13)

My test program:

import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Coordinate;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;

import javax.xml.crypto.dsig.TransformException;

public class main {

    public static void main(String[] args)  throws Exception {
        CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
        CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:5179");
        double coordinateX = 1307285;
        double coordinateY = 2229260;
        Coordinate in = new Coordinate(coordinateX, coordinateY);
        Coordinate out = in;

        MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
        Coordinate result = JTS.transform(in, out, transform);
        result.toString();
    }
}

My build.gradle:

plugins {
id 'java'
}
repositories {
    flatDir {
        dirs 'libs'
    }
    maven {
        url "http://download.osgeo.org/webdav/geotools/"
    }
    mavenCentral()
}
dependencies {
    implementation group: 'org.geotools', name: 'gt-main', version: '20.2'
    implementation('org.geotools:gt-referencing:20.2') {
        exclude group: 'javax.units', module: 'jsr108' 
    }
    files('libs/js4108-0.01.jar')
}

I thought it was sufficient to depend on gt-main and gt-referencing.


回答1:


I needed to add the following dependencies

implementation group: 'org.geotools', name: 'gt-epsg-hsql', version: '20.2'
implementation group: 'org.geotools', name: 'gt-epsg-extension', version: '20.2'

This is documented in geotools referencing documentation



来源:https://stackoverflow.com/questions/54423871/nosuchauthoritycodeexcpetion-in-geotools-program-gradle-build-converting-betwe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!