'FeatureCollection', 'features' => array() ); // Add edges to GeoJSON array while($edge=pg_fetch_assoc($query)) { $feature = array( 'type' => 'Feature', 'geometry' => json_decode($edge['geojson'], true), 'crs' => array( 'type' => 'EPSG', 'properties' => array('code' => '4326') ), 'properties' => array( 'id' => $edge['id'], 'length' => $edge['length'] ) ); // Add feature array to feature collection array array_push($geojson['features'], $feature); } // Close database connection pg_close($dbcon); // Return routing result header('Content-type: application/json',true); echo json_encode($geojson); ?>