gpt4 book ai didi

java - 从 EPSG :4326 to EPSG:31467 in Java/GWT server side 转换坐标

转载 作者:行者123 更新时间:2023-12-04 16:04:54 25 4
gpt4 key购买 nike

我一直在使用来自 https://ariasprado.name/2012/08/13/quick-and-dirty-coordinate-transforming-using-geotools.html#comment-792 的以下代码在我的 GWT 服务器端,并完全按照说明附加了所有必需的 jar。附加错误日志。任何帮助将不胜感激。提前致谢

    import org.geotools.geometry.DirectPosition2D;

import org.geotools.referencing.CRS;

import org.opengis.referencing.crs.CoordinateReferenceSystem;

import org.opengis.referencing.operation.MathTransform;

...

CoordinateReferenceSystem sourceCrs = CRS.decode("EPSG:25829");
CoordinateReferenceSystem targetCrs = CRS.decode("EPSG:4326");

double x = (double) 636497.59434;
double y = (double) 4778964.017375;

boolean lenient = true;
MathTransform mathTransform
= CRS.findMathTransform(sourceCrs, targetCrs, lenient);

DirectPosition2D srcDirectPosition2D
= new DirectPosition2D(sourceCrs, x, y);
DirectPosition2D destDirectPosition2D
= new DirectPosition2D();
mathTransform.transform(srcDirectPostion2D, destDirectPosition2D);

double transX = destDirectPosition2D.x;
double transY = destDirectPosition2D.y;


Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "MathTransformFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.operation.MathTransformFactory: Provider org.geotools.referencing.operation.DefaultMathTransformFactory not a subtype".
java.util.ServiceConfigurationError: org.opengis.referencing.operation.MathTransformFactory: Provider org.geotools.referencing.operation.DefaultMathTransformFactory not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:823)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:769)
at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:802)
at org.geotools.factory.FactoryRegistry.getUnfilteredProviders(FactoryRegistry.java:229)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:429)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:144)
at org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:194)
at org.geotools.referencing.ReferencingFactoryFinder.getMathTransformFactory(ReferencingFactoryFinder.java:504)
at org.geotools.referencing.factory.ReferencingFactoryContainer.getMathTransformFactory(ReferencingFactoryContainer.java:274)
at org.geotools.referencing.factory.ReferencingFactoryContainer.initialize(ReferencingFactoryContainer.java:181)
at org.geotools.referencing.factory.ReferencingFactoryContainer.getImplementationHints(ReferencingFactoryContainer.java:206)
at org.geotools.factory.FactoryRegistry.usesAcceptableHints(FactoryRegistry.java:551)
at org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:505)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:436)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:144)
at org.geotools.referencing.factory.ReferencingFactoryContainer.instance(ReferencingFactoryContainer.java:171)
at org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.<init>(ThreadedEpsgFactory.java:194)
at org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory.<init>(ThreadedHsqlEpsgFactory.java:132)
at org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory.<init>(ThreadedHsqlEpsgFactory.java:118)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:823)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:769)
at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:802)
at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:195)
at org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:177)
at org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:452)
at org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:88)
at org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:69)
at org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:250)
at org.geotools.referencing.CRS.decode(CRS.java:488)
at org.geotools.referencing.CRS.decode(CRS.java:416)
at com.interfacema.gis.server.logic.BorderServlet.transformCRS(BorderServlet.java:342)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "DatumFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.datum.DatumFactory: Provider org.geotools.referencing.factory.ReferencingObjectFactory not a subtype".
java.util.ServiceConfigurationError: org.opengis.referencing.datum.DatumFactory: Provider org.geotools.referencing.factory.ReferencingObjectFactory not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:823)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:769)
at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:802)
at org.geotools.factory.FactoryRegistry.getUnfilteredProviders(FactoryRegistry.java:229)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:429)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:144)
at org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:194)
at org.geotools.referencing.ReferencingFactoryFinder.getDatumFactory(ReferencingFactoryFinder.java:233)
at org.geotools.referencing.factory.ReferencingFactoryContainer.getDatumFactory(ReferencingFactoryContainer.java:232)
at org.geotools.referencing.factory.ReferencingFactoryContainer.initialize(ReferencingFactoryContainer.java:182)
at org.geotools.referencing.factory.ReferencingFactoryContainer.getImplementationHints(ReferencingFactoryContainer.java:206)
at org.geotools.factory.FactoryRegistry.usesAcceptableHints(FactoryRegistry.java:551)
at org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:505)
at org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:436)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:144)
at org.geotools.referencing.factory.ReferencingFactoryContainer.instance(ReferencingFactoryContainer.java:171)
at org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.<init>(ThreadedEpsgFactory.java:194)
at org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory.<init>(ThreadedHsqlEpsgFactory.java:132)
at org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory.<init>(ThreadedHsqlEpsgFactory.java:118)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:823)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:769)
at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:802)
at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:195)
at org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:177)
at org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:452)
at org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:88)
at org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:69)
at org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:250)
at org.geotools.referencing.CRS.decode(CRS.java:488)
at org.geotools.referencing.CRS.decode(CRS.java:416)
at com.interfacema.gis.server.logic.BorderServlet.transformCRS(BorderServlet.java:342)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "DatumFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.datum.DatumFactory: Provider org.geotools.referencing.factory.DatumAliases not a subtype"...


WARNING: Can't load a service for category "CSFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.cs.CSFactory: Provider org.geotools.referencing.factory.ReferencingObjectFactory not a subtype"...


WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.DefaultFactory not a subtype"...


WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.FactoryUsingWKT not a subtype"...


WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.LongitudeFirstFactory not a subtype"...

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.wms.AutoCRSFactory not a subtype"...

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.URN_AuthorityFactory not a subtype"...

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.HTTP_AuthorityFactory not a subtype"...

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.LongitudeFirstEpsgDecorator not a subtype"...

Mar 10, 2018 10:59:20 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory not a subtype"...

最佳答案

从代码来看,它实际上看起来还不错。 (我将在下面添加一个 CRSCoordinateTransformer 类,它绝对“适合我”。)

所以我假设是类路径问题。如果您拥有所有必需的库?我的猜测是您拥有 API 库但没有实际的实现。 GeoTools 提供坐标更改器(mutator)的不同实现。例如 gt2-epsg-hsql,它从嵌入式 HSQLDB 数据库加载转换。您是否包含其中一种 JAR,或者您是否只有 gt2-referencing

下面是 mvn dependency:tree 的一个片段,来自一个已知转换有效的项目:

[INFO] +- org.geotools:gt2-epsg-hsql:jar:2.4.5:compile
[INFO] | +- org.geotools:gt2-referencing:jar:2.4.5:compile
[INFO] | | +- java3d:vecmath:jar:1.3.1:compile
[INFO] | | \- org.geotools:gt2-metadata:jar:2.4.5:compile
[INFO] | | +- org.opengis:geoapi-nogenerics:jar:2.1.0:compile
[INFO] | | \- javax.units:jsr108:jar:0.01:compile
[INFO] | \- hsqldb:hsqldb:jar:1.8.0.7:compile

该版本可能已经很旧了,但这应该可以让您了解需要哪些库。如果您使用 Maven,请运行 mvn dependency:tree 并检查(和/或发布)输出。

现在 promise 的 CRSCoordinateTransformer 类:

package org.hisrc.stopdirect.service.impl;

import org.geotools.geometry.DirectPosition2D;
import org.geotools.referencing.CRS;
import org.hisrc.stopdirect.service.CoordinateTransformer;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

public class CRSCoordinateTransformer implements CoordinateTransformer {
private final MathTransform forwardMathTransform;
private final MathTransform reverseMathTransform;
private final CoordinateReferenceSystem sourceCoordinateReferenceSystem;
private final CoordinateReferenceSystem targetCoordinateReferenceSystem;

public CRSCoordinateTransformer() {
try {
sourceCoordinateReferenceSystem = CRS.decode("EPSG:31468");
targetCoordinateReferenceSystem = CRS.decode("EPSG:4326");
this.forwardMathTransform = CRS.findMathTransform(sourceCoordinateReferenceSystem,
targetCoordinateReferenceSystem, true);
this.reverseMathTransform = CRS.findMathTransform(targetCoordinateReferenceSystem,
sourceCoordinateReferenceSystem, true);
} catch (FactoryException fex) {
throw new ExceptionInInitializerError(fex);
}

}

@Override
public double[] lonLatToXY(double lon, double lat) throws TransformException {
DirectPosition2D srcDirectPosition2D = new DirectPosition2D(sourceCoordinateReferenceSystem, lat, lon);
DirectPosition2D destDirectPosition2D = new DirectPosition2D();
try {
reverseMathTransform.transform(srcDirectPosition2D, destDirectPosition2D);
return new double[] { destDirectPosition2D.y, destDirectPosition2D.x };
} catch (Error error) {
throw error;
}
}

@Override
public double[] xyToLonLat(double x, double y) throws TransformException {

DirectPosition2D srcDirectPosition2D = new DirectPosition2D(sourceCoordinateReferenceSystem, y, x);
DirectPosition2D destDirectPosition2D = new DirectPosition2D();
forwardMathTransform.transform(srcDirectPosition2D, destDirectPosition2D);

return new double[] { destDirectPosition2D.y, destDirectPosition2D.x };
}
}

关于java - 从 EPSG :4326 to EPSG:31467 in Java/GWT server side 转换坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49208121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com