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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2217083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:06:40  来源:igfitidea点击:

java transform projection EPSG:900913 to EPSG:4326

javamap-projectionscartographyepsg

提问by

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

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

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

但是文档是用c++写的,
我不知道怎么用。


If anyone konw that,
please post a simple code


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

回答by trashgod

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

您引用的页面上Jerry Huxtable 令人愉快的Globe Applet确实是用 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

You should also look at OpenMap.

您还应该查看OpenMap

回答by geographika

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

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

http://geotools.org/

http://geotools.org/

Details on the projection classes here:

此处投影类的详细信息:

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

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/

http://www.spatialreference.org/

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

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

回答by disrvptor

Geotoolsis 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:

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);

Your CRS references can be retrieved using:

可以使用以下方法检索您的 CRS 参考:

CRS.decode("EPSG:4326")

Per the javadoc.

根据javadoc

回答by Jamie

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

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

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

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

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.

我只是将我们的代码移动到使用 proj4j ( https://trac.osgeo.org/proj4j/)。它看起来并没有被积极开发,但它可以满足我们的简单需求。此外,许可证是 Apache 2.0,它更宽松。

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

它可以通过 Maven 获得,因此很容易: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.

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

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;
}

回答by pxp

Also interesting: Proj4j

同样有趣: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.

Proj4J 是一个 Java 库,用于将点坐标从一个地理坐标系转换为另一个地理坐标系,包括基准面转换。这个库的核心是 PROJ.4 C 库的一个端口。

回答by keesp

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

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

http://sis.apache.org/

http://sis.apache.org/

It presents itself as an alternative for proj4:

它表现为 proj4 的替代方案:

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

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