gpt4 book ai didi

php - 如何使用数据库中的数据创建 LineString geoJson?

转载 作者:行者123 更新时间:2023-11-29 14:02:43 25 4
gpt4 key购买 nike

好的,所以我知道如何将数据从 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;

?>

最佳答案

解决了

   $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
)));

我创建了一个空数组,然后遍历了来自纬度和经度列的所有数据,然后在坐标中得到了变量

关于php - 如何使用数据库中的数据创建 LineString geoJson?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53608790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com