java - 使用 Java(首选 JTS)以编程方式将英国国家网格(EPSG :7405), 坐标转换为纬度和经度坐标)

标签 java gis jts

有没有办法使用Java将(英国国家网格(10图网格引用),)转换为纬度/经度?

例如,我有 558832.516608631,180065.50201851176,并且想使用 Java 或 JTS 生成纬度/经度。

我见过使用 Javacript 的问题/解决方案,但没有单独使用 Java 的解决方案。

我已经使用 JTS 尝试过:

   Coordinate c = new Coordinate(394028.93262359675,806122.3097467106);

    com.vividsolutions.jts.geom.Point p = gf.createPoint(c);

    CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:3785");
    MathTransform mathTransform = CRS.findMathTransform(utmCrs, DefaultGeographicCRS.WGS84, false);
    com.vividsolutions.jts.geom.Point p1 = (com.vividsolutions.jts.geom.Point) JTS.transform(p, mathTransform);

    System.out.println(p1.getCoordinate());

但坐标不会转换为我可以在谷歌地图中使用的纬度/经度。

谢谢。

http://www.movable-type.co.uk/scripts/latlong-os-gridref.html 我相信包含一个forumla来做到这一点,但我宁愿使用java lib。

这是我试图修复的 GeoJson 多边形: https://gist.githubusercontent.com/boundaries-io/089ca86fdc88b1065f5ee3dd12af684b/raw/e9f8b54ae17d835ad8560fcb81d693201235e386/example.geojson

尝试使用:

CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:7405");

但是,

org.opengis.referencing.operation.OperationNotFoundException: No transformation available from system "CompoundCRS[OSGB 1936 / British National Grid + ODN height]" to "GeographicCRS[WGS84(DD)]".
    at  

最终的解决方案是使用:

CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:27700");

最佳答案

不确定这是否有帮助,因为它确实涉及 GeoTools 和 JTS,但我之前已经成功使用过。我不知道它的转换功能有多全面。

  public static Geometry transform(Geometry inputFeature, CoordinateReferenceSystem source, CoordinateReferenceSystem target) {
    Geometry out = null;
    try {
      final MathTransform mathTransform = CRS.findMathTransform(source, target, true);
      out = JTS.transform(inputFeature, mathTransform);
    } catch (Exception e) {
      LOGGER.error("Exception occurred during transform for input: " + inputFeature, e);
    }
    return out;
  }

这是我对这些对象的导入

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridEnvelope2D;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.OverviewPolicy;

import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.jaitools.jts.CoordinateSequence2D;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;

这是我的 POM 条目,您可能需要它

       <dependency>

            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>15-RC1</version>
        </dependency>
<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-geojson</artifactId>
  <version>15-RC1</version>
</dependency>



        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>15-RC1</version>
        </dependency>

        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-wms</artifactId>
            <version>15-RC1</version>
        </dependency>

希望这会有所帮助,如果您已经在运行数据库服务器,我还采取了使用 PostGIS 或 Oracle 空间等方法在 sql 中进行转换的方法。

更新:

我认为它适用于这个特定案例 这段代码:

 Coordinate c = new Coordinate(394028.93262359675,806122.3097467106);

      com.vividsolutions.jts.geom.Point p = GEOMETRY_FACTORY.createPoint(c);

      CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:3785");
      Geometry transform = transform(p, utmCrs, DefaultGeographicCRS.WGS84);

生成了这个geom(在WKT中) 点(3.5396221256107805 7.270235925793633)

这对我来说看起来不错(至少直观上)

关于java - 使用 Java(首选 JTS)以编程方式将英国国家网格(EPSG :7405), 坐标转换为纬度和经度坐标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46690657/

相关文章:

javascript - 从 OpenLayers3 中的图层组获取图层名称属性

postgresql - 使用 Postgis 和 pgRouting 的行车路线

java - 使用 Java Topology Suite 或 GeoTools 解析 GeoJSON 文件

java - 对 VoronoiDiagramBuilder.setClipEnvelope 使用多边形而不是矩形

java - 如何在警报对话框android java中获取默认选中复选框的值

java - Android 应用计算自己的 MD5 校验和

java - 游戏计时器生成随机数而不是倒计时

java - "isProbablePrime"真的需要花费大部分时间来读取文件吗?

Android getLatitude() 返回大地纬度或地心纬度?

java - 如何将 JTS-Geometry 转换为 AWT-Shape?