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 39 40 41 42 43 44 45 46
| if(isset($_POST['action']) && !empty($_POST['action']) && $_POST['action']=="markerBuffer") {
$conn_marker = new PDO('pgsql:host=localhost;dbname=blablabla','blabla','blabla');
$conn_marker->exec("SET NAMES 'UTF8'");
$sql_marker = "SELECT St_AsGeoJSON(st_transform(the_geom,4326)) as geojson,
nom,
type,
sous_type,
region,
surf_km
FROM data.aoc
WHERE st_intersects(st_buffer(st_transform(st_setSRID(st_makepoint(".$_POST['lng'].",".$_POST['lat']."),4326),2154),50000),the_geom);";
$rs = $conn_marker->query($sql_marker);
if (!$rs) {
echo 'Echec SQL';
exit;
}
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
# Loop through rows to build feature arrays
while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
$properties = $row;
# Remove geojson and geometry fields from properties
unset($properties['geojson']);
unset($properties['geom']);
$feature = array(
'type' => 'Feature',
'geometry' => json_decode($row['geojson'], true),
'properties' => $properties
);
# Add feature arrays to feature collection array
array_push($geojson['features'], $feature);
}
header('Content-type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
pg_close($conn_marker);
}
$conn_marker = NULL;
$_SESSION['var_lat'] = $_POST['lat'];
$_SESSION['var_lng'] = $_POST['lng']; |
Partager