我是Postgis和geojson的初学者,
我应该从geojson中提取每个几何并将它们作为多边形存储在postgis数据库中
对于geojson中的每个条目,我希望能够像在json中一样将其几何分别存储在数据库中
在数据库中,几何类型为:
ALTER TABLE public.a_final ADD COLUMN geometry geometry (Polygon, 4326);
到目前为止我所做的:
$geojson = file_get_contents("o/1.geojson");
//echo $geojson;
$array = json_decode($geojson, TRUE);
echo "<pre>";
print_r($array);
echo "</pre>";
foreach($array['features'] as $type){
$layer = $type['properties']['Layer'];
$SubClasses = $type['properties']['SubClasses'];
$ExtendedEntity = $type['properties']['ExtendedEntity'];
$Linetype = $type['properties']['Linetype'];
$EntityHandle = $type['properties']['EntityHandle'];
$Text = $type['properties']['Text'];
$geometry = $type['geometry'];
}
GeoJSON:
Array
(
[type] => FeatureCollection
[features] => Array
(
[0] => Array
(
[type] => Feature
[properties] => Array
(
[Layer] => Green Area
[SubClasses] => AcDbEntity: AcDbPolyline
[ExtendedEntity] =>
[Linetype] =>
[EntityHandle] => 6B
[Text] =>
)
[geometry] => Array
(
[type] => LineString
[coordinates] => Array
(
[0] => Array
(
[0] => 708305.979
[1] => 385139.794
)
[1] => Array
(
[0] => 708433.3
[1] => 384989.4
)
[2] => Array
(
[0] => 708434.8
[1] => 384987.7
)
[3] => Array
(
[0] => 708400.454
[1] => 384958.526
)
[4] => Array
(
[0] => 708259.989
[1] => 385100.729
)
[5] => Array
(
[0] => 708305.979
[1] => 385139.794
)
)
)
)
[1] => Array
(
[type] => Feature
[properties] => Array
(
[Layer] => Green Area
[SubClasses] => AcDbEntity: AcDbPolyline
[ExtendedEntity] =>
[Linetype] =>
[EntityHandle] => 6C
[Text] =>
)
[geometry] => Array
(
[type] => LineString
[coordinates] => Array
(
[0] => Array
(
[0] => 702461.518
[1] => 381980.706
)
[1] => Array
(
[0] => 702436.783
[1] => 381924.255
)
[2] => Array
(
[0] => 702427.496
[1] => 381927.398
)
[3] => Array
(
[0] => 702452.871
[1] => 381985.312
)
[4] => Array
(
[0] => 702461.518
[1] => 381980.706
)
)
)
)
答案 0 :(得分:0)
您无需完成将GeoJSON转换为SQL的所有繁琐工作,只需使用ST_GeomFromGeoJSON()
将其扔到PostgreSQL中即可。然后,您只需执行以下操作即可:
<xsl:for-each-group select="$nodes" group-adjacent="boolean(self::p[@id = array:subarray($list-levels, $level)])">