Multilinestring 기하 필드를 데이터베이스에서 geojson 데이터로 변환하는 쿼리를 실행하는 PHP 코드가 있습니다. 이 코드는 다중 다각형 및 점 기하 데이터에 대해서는 잘 작동하지만 다중 선 문자 기하학 필드를 구문 분석하는 동안 약간의 오류가 있습니다. 나는 \를 제거하려고하면ST_asGeoJson for Multilinestring for php 전단지
<?php
include('../config.php'); // the db config file
function createFeature() {
$feature = new stdClass();
$feature->type = 'Feature';
$feature->geometry = new stdClass();
$feature->geometry->type = 'Multilinestring';
$feature->properties = new stdClass();
return $feature;
}
function createCollection() {
$collection = new stdClass();
$collection->type = 'FeatureCollection';
$collection->features = array();
return $collection;
}
$query = 'SELECT ST_AsGeoJson(geom) as geom,name FROM table_name';
if($result = pg_query($query)) {
$collection = createCollection();
while($row = pg_fetch_row($result))
{
$feature = createFeature();
$feature->geometry = $row[0];
$feature->properties->name=$row[1];
$collection->features[] = $feature;
}
echo (json_encode($collection,JSON_NUMERIC_CHECK));
}
내가 코드를 실행에 얻을 응답은
{"type":"FeatureCollection",
"features":
[
{
"type":"Feature",
"geometry":
"{\"type\":\"MultiLineString\",
\"coordinates\":[[[73.9750168196755,15.2410462374959],
[73.974612433675,15.2415698937723],
[73.9733813019535,15.2431183375569],
[73.9727337832775,15.2439091075613]]]
}",
"properties":{"name":"NH - 17"}
}
]
}
이다 슬래시 기능을 사용하여 내가 여전히 오류가
echo stripslashes(json_encode($collection,JSON_NUMERIC_CHECK));
을 위해서 stripslashes
SyntaxError: Unexpected token t in JSON at position 72
오류는 주로 기하학 값 앞에 큰 따옴표가 있기 때문에 발생합니다. 그것을 해결하는 방법을 모르십시오.
geojson으로 다중 선 문자 기하 데이터를 가져 오는 다른 방법이 있습니까?