普通网友 2018-07-10 10:20
浏览 51
已采纳

对Geojson的PDOStatement

In order to use it in leaflet, i need to convert my data queried from Mysql with PDO to geojson format.

I find here a solution to do that for json with json_encode(), but i can't find an analogical geojson_encode() function or algorithme with php.

so is there a solution ?

  • 写回答

1条回答 默认 最新

  • dtr53557 2018-07-10 11:16
    关注

    I Solved My problem by reading this issue

    to have your queried data from Mysql converted to geojson , just try this code :

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图