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

Converting British National Grid (EPSG:7405), coordinates into latitude and longitude coordinates Using Java( JTS prefered ) programmatically

有没有办法用Java把(英国国家网格(10图网格参考),)转换成lat/long?

例如,我有一个 558832.516608631,180065.50201851176 并想使用 Java 或 JTS 生成 lat/long。

我见过 questions/solutions 使用 Java 脚本,但没有单独使用 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());

但坐标不会转换为我可以在 google 地图中使用的 lat/long。

谢谢。

http://www.movable-type.co.uk/scripts/latlong-os-gridref.html 我相信包含一个论坛来执行此操作,但我宁愿使用 java 库。

这是我要修复的 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 spatial 之类的方法在 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)

我觉得不错(至少从直觉上看)

哎呀,除非我在某处弄错了,否则英国国家网格 EPSG:27700. EPSG:3785 是一个已弃用的流行墨卡托投影。

但您也可以查看 EPSG:7405 声明为 OSGB 1936 / 英国国家电网 + ODN 高度。事实上,我认为你想要这个,因为你在评论中引用了 SGB1936,EPSG:7405 是 OSGB 1936,而 EPSG:27700 是 OSBG36。

事实上,EPSG:27700可以在任何工具上毫无问题地使用,因为它不依赖于特定的高度网格。相比之下,EPSG:7405 更准确,因为它明确使用 ODN 高度数据...但需要将其加载到转换器工具中。它可以在真正的 Proj4 安装上完成(但对它的解释远远超出我目前的知识范围),并且可能会也可能不会在 Java 工具中完成。关于它的问题应该在 Geographic Information Sytems. But if a 2 meter precision is acceptable, just convert from EPSG:27700 to EPSG:4326 (WGS84 lat-lon). Using the online tool from epsg.io 上提问,你的示例点 394028.93262359675,806122.3097467106 在香港仔中心的 lon=-2°6'1.122", lat=57°8'45.42" 转换。