mappe per georeferenziazione
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

90 righe
4.0 KiB

<?php if (session_id() == "")session_start();ob_start(); ?>
<?php include_once "cfg_srv.php" ?>
<?php
function escapeJsonString($value) { # list from www.json.org: (\b backspace, \f formfeed)
$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
$result = str_replace($escapers, $replacements, $value);
return $result;
}
// ####### POLYGON ####### //
$sql_polygon = "SELECT id, notes, ST_AsGeoJSON(geom, 4326, 1) AS geojson FROM interventi_polygon WHERE idpratica = ".$_SESSION['IDPRATICA']."";
$rs_polygon = pg_query($conn, $sql_polygon);
if (!$rs_polygon) {echo "ERROR - POLYGON.\n"; } else { /*echo "QUERY OKKEY <br><br>";*/ }
$output = ''; $rowOutput = '';
while ($row = pg_fetch_assoc($rs_polygon)) {
$rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "properties": {';
$props = '';
$id = '';
foreach ($row as $key => $val) {
if ($key != "geojson") {
$props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"';
}
if ($key == "id") { $id .= ',"id":"' . escapeJsonString($val) . '"'; }
}
$rowOutput .= $props . '}, "geometry": ' . $row['geojson'] . '';
$rowOutput .= $id;
$rowOutput .= '}';
$output .= $rowOutput;
}
$_SESSION['INT_POLYGON'] = '{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4326" } }, "features": [ ' . $output . ' ] }';
// ####### LINE ####### //
$sql_line = "SELECT id, notes, ST_AsGeoJSON(geom, 4326, 1) AS geojson FROM interventi_line WHERE idpratica = ".$_SESSION['IDPRATICA']."";
$rs_line = pg_query($conn, $sql_line);
if (!$rs_line) {echo "ERROR - LINE.\n"; } else { /*echo "QUERY OKKEY <br><br>";*/ }
$output = ''; $rowOutput = '';
while ($row = pg_fetch_assoc($rs_line)) {
$rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "properties": {';
$props = '';
$id = '';
foreach ($row as $key => $val) {
if ($key != "geojson") {
$props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"';
}
if ($key == "id") { $id .= ',"id":"' . escapeJsonString($val) . '"'; }
}
$rowOutput .= $props . '}, "geometry": ' . $row['geojson'] . '';
$rowOutput .= $id;
$rowOutput .= '}';
$output .= $rowOutput;
}
$_SESSION['INT_LINE'] = '{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4326" } }, "features": [ ' . $output . ' ] }';
// ####### POINT ####### //
$sql_point = "SELECT id, notes, ST_AsGeoJSON(geom, 4326, 1) AS geojson FROM interventi_point WHERE idpratica = ".$_SESSION['IDPRATICA']."";
$rs_point = pg_query($conn, $sql_point);
if (!$rs_point) {echo "ERROR - POINT.\n"; } else { /*echo "QUERY OKKEY <br><br>";*/ }
$output = ''; $rowOutput = '';
while ($row = pg_fetch_assoc($rs_point)) {
$rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "properties": {';
$props = '';
$id = '';
foreach ($row as $key => $val) {
if ($key != "geojson") {
$props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"';
}
if ($key == "id") { $id .= ',"id":"' . escapeJsonString($val) . '"'; }
}
$rowOutput .= $props . '}, "geometry": ' . $row['geojson'] . '';
$rowOutput .= $id;
$rowOutput .= '}';
$output .= $rowOutput;
}
$_SESSION['INT_POINT'] = '{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4326" } }, "features": [ ' . $output . ' ] }';
?>