Código:
El JSON (GeoJSON) que obtengo sale de este modo:$query = "Select a_code, name, id_observation, long_4326, lat_4326, obs_date, id_observation_font, id_image_observation, main_co, author, image, ST_AsGeoJSON(geom, 7) AS geojson FROM observations WHERE id_observation_font != 3 ORDER BY id_observation"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); $geojson = array( 'type' => 'FeatureCollection', 'features' => array() ); $i = 0; while ($line = pg_fetch_assoc($result)) { $feature = array( 'type' => 'Feature', 'id' => $i++, 'properties' => $data[]=$line, 'geometry' => json_decode($line['geojson'], true), ); array_push($geojson['features'], $feature); } $localiza = json_encode($geojson, JSON_UNESCAPED_UNICODE); $conta = "../data/observations.json";
Código:
Como veis, la observación 51 tiene varias imágenes, pero no lo obtengo agrupado. No se si con un FOREACH... { "type":"Feature", "id":22, "properties":{ "a_code":"151", "name":"one Name", "id_observation":"51", "long_4326":"-x.xxx", "lat_4326":"xx.xxx", "obs_date":"2015-03-17", "id_observation_font":"1", "id_image_observation":"30", "main_co":"f", "author":"John", "image":"data/IMG1.JPG", "geojson":"{\"type\":\"Point\",\"coordinates\":[-x.x,xx.xx]}"}, "geometry":{ "type":"Point", "coordinates":[-x.x,xx.xx]} }, { "type":"Feature", "id":23, "properties":{ "a_code":"151", "name":"one Name", "id_observation":"51", "long_4326":"-x.xxx", "lat_4326":"xx.xxx", "obs_date":"2015-03-17", "id_observation_font":"1", "id_image_observation":"29", "main_co":"f", "author":"John", "image":"data/IMG2.JPG", "geojson":"{\"type\":\"Point\",\"coordinates\":[-x.x,xx.xx]}"}, "geometry":{ "type":"Point", "coordinates":[-x.x,xx.xx]} }, { "type":"Feature", "id":24, "properties":{ "a_code":"715", "name":"other name", "id_observation":"52", "long_4326":"-x.xxx", "lat_4326":"xx.xxx", "obs_date":"2015-06-01", "id_observation_font":"1", "id_image_observation":"31", "main_co":"t", "author":"Phill", "image":"data/IMG32.JPG", "geojson":"{\"type\":\"Point\",\"coordinates\":[-x.x,xx.xx]}"}, "geometry":{ "type":"Point","coordinates":[-x.x,xx.xx]} }