geotools 程序(gradle 构建)中的 NoSuchAuthorityCodeExcpetion 在坐标系之间转换
NoSuchAuthorityCodeExcpetion in geotools program (gradle build) converting between coordinate systems
我有一个 java geotools 程序可以在两个坐标系之间转换坐标。它尝试在坐标系 ESPG:4326 和 ESPG:5179.
之间转换
我在我的代码中尝试执行这一行时收到以下异常:
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)
我的测试程序:
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();
}
}
我的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')
}
我认为依赖gt-main
和gt-referencing
就足够了。
我需要添加以下依赖项
implementation group: 'org.geotools', name: 'gt-epsg-hsql', version: '20.2'
implementation group: 'org.geotools', name: 'gt-epsg-extension', version: '20.2'
我有一个 java geotools 程序可以在两个坐标系之间转换坐标。它尝试在坐标系 ESPG:4326 和 ESPG:5179.
之间转换我在我的代码中尝试执行这一行时收到以下异常:
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)
我的测试程序:
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();
}
}
我的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')
}
我认为依赖gt-main
和gt-referencing
就足够了。
我需要添加以下依赖项
implementation group: 'org.geotools', name: 'gt-epsg-hsql', version: '20.2'
implementation group: 'org.geotools', name: 'gt-epsg-extension', version: '20.2'