php - 到 Geojson 的 PDO 语句
问题描述
为了在传单中使用它,我需要将我从Mysql查询到的PDO数据转换为geojson格式。
我在这里找到了一个解决方案来为json执行此操作json_encode()
,但我找不到geojson_encode()
使用 php 的类比函数或算法。
那么有解决方案吗?
解决方案
我通过阅读这个问题解决了我的问题
要将您从 Mysql 查询的数据转换为 geojson ,只需尝试以下代码:
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
$reponses=$bdd->query('SELECT * FROM `nyc_taxi_data_2014` LIMIT 0,30 ');
while ($data=$reponses->fetch())
{
$marker = array(
'type' => 'Feature',
'features' => array(
'type' => 'Feature',
'properties' => array(
'pickup_time' => "".$data['pickup_datetime']
),
"geometry" => array(
'type' => 'Point',
'coordinates' => array(
$data['pickup_longitude'],
$data['pickup_latitude']
)
)
)
);
array_push($geojson['features'], $marker['features']);
}
echo json_encode($geojson);
推荐阅读
- python - 使用 SQLalchemy 连接到 MySql 数据库时出错
- python - 合并具有不同行数的 DataFrame,并具有一个包含值总和的新列
- python - jsonload JSONDecodeError:无效的控制字符在
- javascript - 如何在 Javascript 中使用 FileReader() 以不同的方法读取 2 个不同的文件
- python - 网页抓取/将数据转换为 Python 中的表格数据
- graph - 是否可以将 Grafana 注释不放在面板底部?
- r - 如何遍历 R 中的列进行 T 检验?
- flutter - 来自路由参数的 FutureBuilder
- python - Python中熊猫表的散点图
- flutter - 如何通过在 Flutter 中按下图标来更改屏幕?