在openlayers中,我们可以简单地将EPSG:900913转换为EPSG:4326
我正在寻找一个能做到这一点的java库。
我找到了这个,http://www.jhlabs.com/java/maps/proj/index.html
但是文档是c++格式的
我不知道怎么用它。
如果有人知道这一点,
请发布一个简单的代码
发布于 2010-02-18 23:44:15
另一种选择是使用OpenSource 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/
发布于 2011-05-17 04:49:31
Geotools可能是最好的库。看一看他们的CRS tutorial,使用以下命令从一个坐标系转换到另一个坐标系看起来很简单:
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。
发布于 2018-01-13 07:48:41
我知道这是近8年前的事了,但也许这能帮助另一个勇敢的旅行者。
我们不得不离开GeoTools,因为它是LGPL,这是我们的法律人员所不允许的。
我刚刚将我们的代码移动到使用proj4j (https://trac.osgeo.org/proj4j/)。它看起来不像是在积极开发,但它可以满足我们的简单需求。此外,许可是Apache2.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;
}https://stackoverflow.com/questions/2217083
复制相似问题