1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <?php
$idc=pg_connect('host=INFO-SIG
dbname=db31_test
user=********
password=********');
$tableau = array();
$sql = "SELECT geom, id_sentier FROM amenagement.veloroutes";
$rs = pg_query($idc, $sql);
$geojson = array(
'type ' => 'FeatureCollection' ,
'features' => array ()
);
//Parcourez les lignes pour créer des tableaux d'entités
while ( $row = pg_fetch_assoc ($rs)) {
$feature = array(
'id' => $row['id_sentier'],
'type' => 'Feature' ,
'geometry' => array(
'type' => 'MultiLineString' ,
# Passez les colonnes Longitude et Latitude ici
'coordinates' => array($row['geom'])
),
# Passez les autres colonnes d'attribut ici
'properties' => array(
'id_sentier' => $row['id_sentier'],
)
);
# Ajouter des tableaux d'entités au tableau de collection d'entités
array_push($geojson['features'], $feature );
}
header ( ' Content-type: application / json ' );
echo json_encode( $geojson , JSON_NUMERIC_CHECK ); |
Partager