PHP - 将xy .shp坐标转换为谷歌地图lat / lng

时间:2017-04-11 13:31:26

标签: php google-maps coordinates shapefile

我正在开发一个可以加载.shp文件的Web应用程序。我们的想法是识别此文件,然后在Google地图中显示每个多边形。我可以在php中读取形状文件。问题是我不知道如何将.shp中使用的坐标系转换为识别Google Maps进行地图操作的坐标系。这些是.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

1 个答案:

答案 0 :(得分: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);
相关问题