PHP-如何使用PHP创建GEOJSON文件

时间:2019-05-06 07:16:28

标签: javascript php geojson

我想从Php构建Linestring函数以将其转换为GeoJson。该函数如下:

var linea = { "type": "FeatureCollection",
    "features": [
     { "type": "Feature",
        "geometry": {
          "type": "LineString",
          "coordinates": [[102.0, 0.0], [103.0, 1.0]]
          },
        "properties": {
          "name": "enlace"
                }
        }

       ]
     }

代码如下:

$geojson = array(
   'type'      => 'FeatureCollection',
   'features'  => array()
);

while($row = mysql_fetch_assoc($consulta)) {
    $feature = array(
        'type' => 'Feature', 
        'geometry' => array(
            'type' => 'LineString',
            'coordinates' => array($row['lon'], $row['lat'])
        ),
        'properties' => array(
            'name' => $row['equipo'],
            )
        );
    array_push($geojson['features'], $feature);
}

}

$variable="var geonokia= " .json_encode($geojson); 
file_put_contents('D:\equipo.js',$variable);

如何创建由2个纬度和2个经度组成的数组来创建直线?

“'coordinates'=> array($ row ['lon'],$ row ['lat'])”

用于创建

“坐标”:[[102.0,0.0],[103.0,1.0]] ----- >>> 2分

0 个答案:

没有答案