Php 如何使用数据库中的数据创建LineString geoJson?
好的,我知道如何将php格式的数据转换为geojson格式的点类型,但我不知道如何将其转换为线字符串类型这是代码,所以问题是如何将坐标数据转换为一个数组:Php 如何使用数据库中的数据创建LineString geoJson?,php,json,postgresql,geojson,Php,Json,Postgresql,Geojson,好的,我知道如何将php格式的数据转换为geojson格式的点类型,但我不知道如何将其转换为线字符串类型这是代码,所以问题是如何将坐标数据转换为一个数组: include('testcon.php'); $query=pg_query($connect,"SELECT number, state, data, latitude, long " . "FROM schema.table " . "WHERE number = '63
include('testcon.php');
$query=pg_query($connect,"SELECT number, state, data, latitude,
long "
. "FROM schema.table "
. "WHERE number = '63' AND "
. "data BETWEEN '2018-12-01 00:00:00' and '2018-12-01 23:59:59'
limit 200 ");
# Try query or error
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
# Loop through rows to build feature arrays
while($row = pg_fetch_array($query)) {
$feature = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
# Pass Longitude and Latitude Columns here
'coordinates' => array($row['long'], $row['lat'])
),
# Pass other attribute columns here
'properties' => array(
'indicativ' => $row['number'],
'stare' => $row['state'],
)
);
# Add feature arrays to feature collection array
array_push($geojson['features'], $feature);
}
header('Content-type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$conn = NULL;
?>
解决了
$pointlist=array();
while($row = pg_fetch_assoc($query)) {
$pointlist[]=array($row['long'], $row['lat']);
};
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array(
#);
#$feature = array(
'type' => 'Feature',
'geometry' => array(
'type'=> 'LineString',
'coordinates'=> $pointlist
)));
我创建了一个空数组,然后循环遍历来自lat和long列的所有数据,然后在坐标中得到variabel