将经度和纬度转换为 Alber 投影上的图像 X、Y 像素坐标

Convert Longitude and Latitude to image X, Y pixel coordinates on Alber's projection

我从雷达上得到很多坐标,这些坐标的格式与 Google 地图坐标几乎相同,我不太确定,但我问了公司,他们告诉我为了得到坐标Alber的投影,我需要做的是:

You will then be able to create 2 CoordinateReferenceSystem (i.e. coordinate systems), set one as default (which is lon/lat), and set the other with the WKT string (which will be projected x/y). Then you can easily create 2 MathTransform to convert in both directions.

这是阿尔伯投影的 OGC WKT:

PROJCS["unnamed",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.2572235629972,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Albers_Conic_Equal_Area"],
    PARAMETER["standard_parallel_1",31.996308],
    PARAMETER["standard_parallel_2",33.996308],
    PARAMETER["latitude_of_center",32.996308],
    PARAMETER["longitude_of_center",35.415901],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,AUTHORITY["EPSG","9001"]]]

所以据我所知,我需要从 long/lat 转换为 WKT 投影以显示在 Alber 的投影地图图像上。

所以在GeoTools中我使用了下面的代码:

    CoordinateReferenceSystem source = CRS.decode("EPSG:4326");
    CoordinateReferenceSystem target = CRS.parseWKT("PROJCS[\"unnamed\", GEOGCS[\"WGS 84\", DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\",6378137,298.2572235629972, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\",0], UNIT[\"degree\",0.0174532925199433], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Albers_Conic_Equal_Area\"], PARAMETER[\"standard_parallel_1\",31.996308], PARAMETER[\"standard_parallel_2\",33.996308], PARAMETER[\"latitude_of_center\",32.996308], PARAMETER[\"longitude_of_center\",35.415901], PARAMETER[\"false_easting\",0], PARAMETER[\"false_northing\",0], UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]]");
    MathTransform transform = CRS.findMathTransform(source, target, true);

    Coordinate c = JTS.transform(new Coordinate(34, 35), new Coordinate(), transform);
    System.out.println(c.toString());

这就是我得到的输出:

(-38422.86847540497, 111410.0483012808, NaN)

现在,可能是因为错误的source坐标系,但是默认long/lat系统是什么意思?

即使我解决了这个问题,我怎样才能让它在我的地图图像上显示这些点?我的意思是它必须知道图像的 width/height 不是吗?

此阿尔伯斯投影 WKT 从 EPSG 4326 投影到距零点的距离(以米为单位)(参见参数)。我们怎么知道它是不是米?因为 WKT 有一个 set UNIT 标签显示为米单位。

那我是怎么用的呢?

我的公司给了我两个文件,地图 JPEG 文件和一个 XML 地图常量文件。

该地图常量 XML 文件包含从该地图的零点到地图角点的距离。所以如果你在地图上至少有一个点,你可以找到所有东西。

将其转换为地图需要了解的事项X/Y:

  • 每个像素是多少公里(在我的例子中是 1.6 正好是 1 英里)
  • 地图上至少有一个距离零点的已知点

我是这样做的:

        MathTransform transform = CRS.findMathTransform(epsg4326, targetWKT, true);

        DirectPosition2D srcDirectPosition2D
                = new DirectPosition2D(epsg4326, latitude, longitude);
        DirectPosition2D destDirectPosition2D
                = new DirectPosition2D();
        transform.transform(srcDirectPosition2D, destDirectPosition2D);

        double transX = destDirectPosition2D.x;
        double transY = destDirectPosition2D.y;

        int kmPerPixel = mapImage.getWidth / 1024; // It is known to me that my map is 1024x1024km ...

        double x = zeroPointX + ( (transX * 0.001) * kmPerPixel);
        double y = zeroPointY + ( ( (transX * -1) * 0.001) * kmPerPixel);

zeroPointX 和 Y 可以通过相同的计算得到,无需添加,就像我在角上所做的那样,在地图上的距离点上。

可能会对某些人有所帮助,所以我发布了我的想法。