[英]How can i create a LineString geoJson with data from data base?
ok, so I know how to convert data from php to geojson format into point types but i dont understand how can I make this into a lineString type here is the code, so the question is how can i get the coordinates data into one array : 好的,所以我知道如何将数据从php转换为geojson格式转换为点类型,但是我不明白如何将其转换为lineString类型,这是代码,所以问题是如何将坐标数据转换为一个数组:
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;
?>
Solved it 解决了
$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
)));
i create an empty array and then looped through all the data from lat and long columns and than in coordinates i got the variabel 我创建一个空数组,然后遍历所有经纬度和经度列的数据,然后在坐标中得到了可变参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.