java 变换投影 EPSG:900913 到 EPSG:4326

发布于 2024-08-20 12:44:12 字数 313 浏览 15 评论 0原文

在开放层中 我们可以简单地将 EPSG:900913 转换为 EPSG:4326
我正在寻找一个可以做到这一点的 Java 库。
在这里我发现了这个, http://www.jhlabs.com/java/maps/proj/index.html html

但文档是用 c++ 编写的
我不知道如何使用它。


如果有人知道的话,
请发布一个简单的代码

in the openlayers
we can simple transform EPSG:900913 to EPSG:4326
I'm look for a java lib can do that.
here I found this,
http://www.jhlabs.com/java/maps/proj/index.html

but the document is in c++
I don't know how to use it.

If anyone konw that,
please post a simple code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情栀口红 2024-08-27 12:44:12

我知道这是近 8 年前的事了,但也许这可以帮助另一个勇敢的旅行者。

我们不得不放弃 GeoTools,因为它是 LGPL,这是我们的法律人员不允许的。

我刚刚将代码移至使用 proj4j (https://trac.osgeo.org/proj4j/) 。它看起来不像是在积极开发,但它可以满足我们的简单需求。此外,许可证是 Apache 2.0,更加宽松。

它可以通过 Maven 获得,因此变得很容易: http:// /search.maven.org/#artifactdetails%7Corg.osgeo%7Cproj4j%7C0.1.0%7Cjar

它不直接支持 EPSG:900913,因为它并不是真正的官方标准。它确实支持 EPSG:3857,这是同样的事情。

这是执行您正在寻找的操作的片段:

public Point2D.Double transform(Point2D.Double point, String sourceCRS, String targetCRS) {
    Point2D.Double destPosition = new Point2D.Double();

    CRSFactory factory = new CRSFactory();
    CoordinateReferenceSystem srcCrs = factory.createFromName(sourceCRS); // Use "EPSG:3857" here instead of 900913.
    CoordinateReferenceSystem destCrs = factory.createFromName(targetCRS); // Use "EPSG:4326 here.
    CoordinateTransform transform = new CoordinateTransformFactory().createTransform(srcCrs, destCrs);

    ProjCoordinate srcCoord = new ProjCoordinate(point.getX(), point.getY());
    ProjCoordinate destCoord = new ProjCoordinate();
    transform.transform(srcCoord, destCoord);
    destPosition.setLocation(destCoord.x, destCoord.y);

    return destPosition;
}

I understand that this is from almost 8 years ago, but maybe this can help another intrepid traveller.

We had to move away from GeoTools because it's LGPL, which is not allowed by our legal folk.

I just moved our code to use proj4j (https://trac.osgeo.org/proj4j/). It doesn't look like it's being actively developed, but it works for our simple needs. Also, the license is Apache 2.0, which is much more permissive.

It's available via Maven, so that makes it easy: http://search.maven.org/#artifactdetails%7Corg.osgeo%7Cproj4j%7C0.1.0%7Cjar.

It doesn't directly support EPSG:900913, since it's not really the official standard. It does support EPSG:3857, which is the same thing.

Here's a snippet doing what you're looking for:

public Point2D.Double transform(Point2D.Double point, String sourceCRS, String targetCRS) {
    Point2D.Double destPosition = new Point2D.Double();

    CRSFactory factory = new CRSFactory();
    CoordinateReferenceSystem srcCrs = factory.createFromName(sourceCRS); // Use "EPSG:3857" here instead of 900913.
    CoordinateReferenceSystem destCrs = factory.createFromName(targetCRS); // Use "EPSG:4326 here.
    CoordinateTransform transform = new CoordinateTransformFactory().createTransform(srcCrs, destCrs);

    ProjCoordinate srcCoord = new ProjCoordinate(point.getX(), point.getY());
    ProjCoordinate destCoord = new ProjCoordinate();
    transform.transform(srcCoord, destCoord);
    destPosition.setLocation(destCoord.x, destCoord.y);

    return destPosition;
}
毁我热情 2024-08-27 12:44:12

Jerry Huxtable 在您引用的页面确实是用Java编写的,如下载中所示。 com.jhlabs.map.proj.ProjectionFactory 类包含一个名为 fromPROJ4Specification() 的方法,该方法返回一个 com.jhlabs.map.proj.Projection代码>.您可以使用 OpenLayers 站点上指定的 EPSG:900913 参数来创建所需的投影。

900913:
+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0
+x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs

您还应该查看 OpenMap

Jerry Huxtable's delightful Globe Applet on the page you cited is indeed written in Java, as seen in the download. The class com.jhlabs.map.proj.ProjectionFactory contains a method named fromPROJ4Specification(), which returns a com.jhlabs.map.proj.Projection. You can use the EPSG:900913 parameters specified on the OpenLayers site to create the desired projection.

900913:
+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0
+x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs

You should also look at OpenMap.

天冷不及心凉 2024-08-27 12:44:12

另一种选择是使用开源 GIS Java 库 GeoTools:

http://geotools.org/

有关投影类的详细信息这里:

http://geotools.org/javadocs/org/ geotools/referencing/operation/projection/MapProjection.html

所有投影的多种不同格式的投影定义可以从以下位置下载:

http://www.spatialreference.org/

例如 http:// www.spatialreference.org/ref/epsg/4326/

Another option is to use the OpenSource GIS Java library GeoTools:

http://geotools.org/

Details on the projection classes here:

http://geotools.org/javadocs/org/geotools/referencing/operation/projection/MapProjection.html

Projection definitions in many different formats for all projections can be downloaded from:

http://www.spatialreference.org/

E.g. http://www.spatialreference.org/ref/epsg/4326/

呆橘 2024-08-27 12:44:12

Geotools 可能是最好的库。看看他们的 CRS 教程,从一个转变看起来很简单坐标系到另一个使用:

CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);

可以使用以下方式检索 CRS 引用:

CRS.decode("EPSG:4326")

根据 javadoc

Geotools is probably the best library to use for this. Taking a look at their CRS tutorial, it looks trivial to transform from one coordinate system to another using:

CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);

Your CRS references can be retrieved using:

CRS.decode("EPSG:4326")

Per the javadoc.

花辞树 2024-08-27 12:44:12

同样有趣的是: Proj4j

Proj4J 是一个 Java 库,用于将点坐标从一个地理坐标系转换为另一个,包括数据转换。
该库的核心是PROJ.4 C库的移植。

Also interesting: Proj4j

Proj4J is a Java library to transform point coordinates from one geographic coordinate system to another, including datum transformations.
The core of this library is a port of the PROJ.4 C library.

jJeQQOZ5 2024-08-27 12:44:12

似乎有一个新的 Apache 项目,它可能是上述开源项目的更新替代方案:

http ://sis.apache.org/

它作为 proj4 的替代品:

https://sis.apache.org/book/en/developer-guide.html

There seems to be a new Apache project, which may be a more up to date alternative for the open source projects mentioned above:

http://sis.apache.org/

It presents itself as an alternative for proj4:

https://sis.apache.org/book/en/developer-guide.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文