【问题标题】:PHP - Convert xy .shp coordinates to Google Maps lat/lngPHP - 将 xy .shp 坐标转换为谷歌地图 lat/lng
【发布时间】:2017-09-06 22:22:10
【问题描述】:

我正在开发一个可以加载 .shp 文件的 Web 应用程序。这个想法是识别这个文件,然后在谷歌地图中显示每个多边形。我可以在 php.ini 中读取形状文件。问题是我不知道如何将 .shp 中使用的坐标系转换为识别谷歌地图以进行地图操作的坐标系。这些是 .shp 文件的一些坐标以及该文件中使用的坐标系:

坐标系(.prj 文件):

LOCAL_CS["CH1903+ / LV95",UNIT["metre",1,AUTHORITY["EPSG","9001"]]]

解释的 .shp 记录:

Record number: 1
Array
(
    [bounding_box] => Array
        (
            [xmin] => 2645165.87317
            [xmax] => 2645166.87317
            [ymin] => 1132483.62903
            [ymax] => 1132484.62903
        )

    [numparts] => 1
    [parts] => Array
    (
        [0] => Array
            (
                [numrings] => 1
                [rings] => Array
                    (
                        [0] => Array
                            (
                                [numpoints] => 5
                                [points] => Array
                                    (
                                        [0] => Array
                                            (
                                                [x] => 2645165.87317
                                                [y] => 1132484.62903
                                            )

                                        [1] => Array
                                            (
                                                [x] => 2645166.87317
                                                [y] => 1132484.62903
                                            )

                                        [2] => Array
                                            (
                                                [x] => 2645166.87317
                                                [y] => 1132483.62903
                                            )

                                        [3] => Array
                                            (
                                                [x] => 2645165.87317
                                                [y] => 1132483.62903
                                            )

                                        [4] => Array
                                            (
                                                [x] => 2645165.87317
                                                [y] => 1132484.62903
                                            )

                                    )

                            )

                    )

            )

    )

[wkt] => POLYGON((2645165.87317 1132484.62903, 2645166.87317 1132484.62903, 2645166.87317 1132483.62903, 2645165.87317 1132483.62903, 2645165.87317 1132484.62903)))
Array
(
    [_deleted] => 
    [ID] => 1
    [red] => 58.818
    [Comment] => 
    [Rate] => 0.000
)

Record 2 [...]

注意:为了读取 .shp 文件,我使用 gasparesganga/php-shapefile 库,https://github.com/gasparesganga/php-shapefile

【问题讨论】:

  • 您正在寻找的术语可能是“reproject”,我不确定 PHP 中有哪些工具。您需要从瑞士坐标系 (EPSG:2056?) 重新投影到投影的 WGS84 坐标 EPSG:3857,另请参阅 this GIS SE question

标签: php google-maps coordinates shapefile


【解决方案1】:

您可以使用库 Proj4php https://github.com/proj4php/proj4php 重新投影您的坐标。

$proj4 = new Proj4php();

// Your initial projection information from your .prj file
$srcProj    = new Proj('LOCAL_CS["CH1903+ / LV95",UNIT["metre",1,AUTHORITY["EPSG","9001"]]]', $proj4);

// WGS84 (for google map)
$dstProj  = new Proj('EPSG:4326', $proj4);

// Your original point
$srcPoint = new Point(2645165.87317, 1132484.62903, $srcProj);

// Create your new point in WGS84 projection
$dstPoint = $proj4->transform($dstProj, $srcPoint);

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多