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 47 48 49 50 51 52 53 54 55 56 57 58 59
|
<?php
include ("dbconfig.php");
error_reporting(E_ALL);
ini_set("display_errors", 1);
header("Access-Control-Allow-Origin: *");
$user_id = $dbcon ->real_escape_string(strip_tags($_GET['user_id'],ENT_QUOTES));
$current_file = $dbcon ->real_escape_string(strip_tags($_GET['current_file'],ENT_QUOTES));
$user_token = $dbcon ->real_escape_string(strip_tags($_POST['user_token'],ENT_QUOTES));
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
try {
$dbcon = new PDO("pgsql:host=".$pghost.";port=".$pgport.";dbname=mfy_".$user_id.";user=".$pguser.";password=".$pgpass."");
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbcon->prepare("SELECT cat, public.ST_AsGeoJSON(public.ST_Transform((geom),4326),6) AS geojson FROM :current_file._linestring");
$stmt->bindValue(":currentfile", $current_file, PDO::PARAM_INT);
if($stmt->execute()){
$id_count = 0;
while($rowset = $stmt->fetch(PDO::FETCH_ASSOC)){
$properties = $rowset;
unset($properties['geojson']);
unset($properties['geom']);
$feature = array(
'type' => 'Feature',
'id' => $id_count,
'properties' => $properties,
'geometry' => json_decode($rowset['geojson'], true)
);
array_push($geojson['features'], $feature);
$id_count++;
}
header('Content-Type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$dbcon = null;
exit;
} else {
header('Content-Type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$dbcon = null;
exit;
}
} catch (PDOException $e) {
header('Content-Type: application/json');
echo json_encode($geojson, JSON_NUMERIC_CHECK);
$dbcon = null;
exit;
}
?> |
Partager