0

Trying to take MySQL polygons to GeoJSON. My SQL query is Okay and works in PhpMyAdmin and I'm trying to modify some code that works for points. I think I'm close but stuck.

In PhpMyAdmin the records are returned and the geom field returns: {"type": "Polygon", "coordinates": [[[-111.4754251.....

I'm having trouble inserting this in my formatted geometry array.

 $sql = "SELECT `FID`, `STATE_NAME`, `SUB_REGION`, `STATE_ABBR`, `POP2010`, `POP10_SQMI`, `MALES`, `FEMALES`, `SQMI`, ST_AsGeoJSON(`geom`) FROM `usa` WHERE 1";

    $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

    while ($res = mysqli_fetch_array($result,MYSQLI_ASSOC)) {

        $msg [] = array(
                'type' => 'Feature',
                'geometry' => array(
                    $res[ST_AsGeoJSON('geom')],
                ), 
                'properties' => array(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.