我正在处理一项简单的任务:使用
从EPSG代码创建CoordinateReferenceSystem
String code = "26910";
CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSAuthorityFactory
("EPSG",null).createCoordinateReferenceSystem(code);
此代码段产生:
`Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.hsqldb.lib.FrameworkLogger
at org.hsqldb.persist.Logger.getEventLogger(Unknown Source)
at org.hsqldb.persist.Logger.logInfoEvent(Unknown Source)
at org.hsqldb.persist.Logger.closePersistence(Unknown Source)
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDataSource.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDataSource.getConnection(Unknown Source)
at org.geotools.referencing.factory.epsg.DirectEpsgFactory.getConnection(DirectEpsgFactory.java:3196)
at org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:436)
at org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:133)
at org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:235)
at org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:119)
at org.geotools.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:667)
at org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:501)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:437)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:365)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:145)
at org.geotools.referencing.ReferencingFactoryFinder.getAuthorityFactory(ReferencingFactoryFinder.java:220)
at org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactory(ReferencingFactoryFinder.java:440)`
我对使用hsqldb感兴趣。 hsqldb-2.2.8.jar在CLASSPATH中。我应该如何在java代码中组织数据库连接?
更新
我的主要目标是使用GeoTools处理坐标转换,但似乎并不容易。请参阅下面的错误代码:
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.geotools.geojson.geom.GeometryJSON;
import com.vividsolutions.jts.geom.Geometry;
import org.geotools.geometry.jts.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
//------------------------------
CoordinateReferenceSystem sourceCRS = null;
CoordinateReferenceSystem targetCRS = null;
try {
sourceCRS = CRS.decode("epsg:4326");
System.out.println("SOURCE \n" + sourceCRS);
targetCRS = CRS.decode("epsg:23032");
System.out.print("\nTARGET \n" + targetCRS);
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
GeometryJSON jsonReader = new GeometryJSON();
Geometry sourceGeometry = jsonReader.read(new FileInputStream("simple-geometry.json"));
System.out.println("\n" + sourceGeometry.getCoordinate().toString());
//the problem's here
Geometry targetGeometry = JTS.transform(sourceGeometry, transform);
} catch (FactoryException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
重点是我的IDE无法解析JTS.transform(/ ... /)。
我在CLASSPATH中有gt-epsg-hsql-13.0,gt-geojson-13.0,gt-jts-wrapper-13.0,gt-opengis-13.0,gt-referencing-13.0,jts-1.13。
我的pom.xml是:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>geotools_test_3</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>${geotools.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
有人知道这似乎是什么问题吗?
答案 0 :(得分:1)
生成坐标系的最简单方法是使用以下代码:
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>${geotools.version}</version>
</dependency>
确保您的pom文件中包含以下内容
{{1}}