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.
80 righe
3.5 KiB
80 righe
3.5 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; |
|
} |
|
|
|
echo "CATAPARTICELLA = ".$_SESSION['cataparticella']."<br>"; |
|
/**/ |
|
if (strlen($_SESSION['cataparticella']) > 2 ) { |
|
// ########## CALCOLA CENTROIDE PARTICELLA |
|
if(!$strcoordinate = @pg_query("SELECT ST_X(ST_Transform(ST_Centroid(ST_Union(geom)),4326)) as long, |
|
ST_Y(ST_Transform(ST_Centroid(ST_union(geom)),4326)) as lat |
|
FROM ".$_SESSION['COMUNE_PROV'].".particelle WHERE comune = '".$_SESSION['COMUNE_BELF']."' AND id=".$_SESSION['QUERY_CDU'].";")) |
|
die("Errore CENTRO COMUNE: " . pg_last_error($conn)); |
|
while($rowcoord = pg_fetch_assoc($strcoordinate)) { $_SESSION['CENTER'] = $rowcoord['lat'] .", ".$rowcoord['long']; } |
|
|
|
$_SESSION['ZOOM'] = 18; |
|
|
|
// ########## CALCOLO BOUND PARTICELLE |
|
|
|
if(!$strbound = @pg_query("SELECT ST_YMax(ST_Buffer(ST_Transform(ST_Union(geom),4326),0.15)) as ymax, ST_XMax(ST_Buffer(ST_Transform(ST_Union(geom),4326),0.15)) as xmax, ST_YMin(ST_Buffer(ST_Transform(ST_Union(geom),4326),0.15)) as ymin, ST_XMin(ST_Buffer(ST_Transform(ST_Union(geom),4326),0.15)) as xmin |
|
FROM ".$_SESSION['COMUNE_PROV'].".particelle WHERE comune = '".$_SESSION['COMUNE_BELF']."' AND id=".$_SESSION['QUERY_CDU'].";")) |
|
die("ERROR BOUND: " . pg_last_error($conn)); |
|
while($rowbound = pg_fetch_assoc($strbound)) { |
|
// ---------- ESTENSIONE MAPPA |
|
$_SESSION['BOUND'] = "[".$rowbound['ymin'].", ".$rowbound['xmin']."],[".$rowbound['ymax'].", ".$rowbound['xmax']."]"; |
|
} |
|
|
|
|
|
// CALCOLA GEOMETRIA PARTICELLA |
|
$sql_catasto = "SELECT ST_AsGeoJSON(ST_Transform(geom,4326)) AS cata_geojson, round(ST_Area(geom)::numeric,2) as area |
|
FROM ".strtolower($_SESSION['COMUNE_PROV']).".particelle WHERE comune = '".$_SESSION['COMUNE_BELF']."' AND id=".$_SESSION['QUERY_CDU'].";"; |
|
|
|
# Try query or error |
|
$rs = pg_query($conn, $sql_catasto); |
|
if (!$rs) { |
|
echo "ERROR GEOM PARTICELLE.\n"; |
|
} else { |
|
// echo "QUERY OKKEY <br><br>"; |
|
} |
|
|
|
# Build GeoJSON |
|
$output = ''; |
|
$rowOutput = ''; |
|
|
|
while ($row = pg_fetch_assoc($rs)) { |
|
// $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['geojson'] . ', "properties": {'; |
|
$rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "properties": {'; |
|
$props = ''; |
|
$id = ''; |
|
foreach ($row as $key => $val) { |
|
if ($key != "cata_geojson") { |
|
$props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"'; |
|
} |
|
if ($key == "id") { |
|
$id .= ',"id":"' . escapeJsonString($val) . '"'; |
|
} |
|
} |
|
// $rowOutput .= $props . '}'; |
|
$rowOutput .= $props . '}, "geometry": ' . $row['cata_geojson'] . ''; |
|
$rowOutput .= $id; |
|
$rowOutput .= '}'; |
|
$output .= $rowOutput; |
|
} |
|
|
|
$particella = '{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4326" } }, "features": [ ' . $output . ' ] }'; |
|
$_SESSION['SELECT_PARTICELLA'] = $particella; |
|
|
|
|
|
} else { |
|
|
|
$_SESSION['ZOOM'] = 12; |
|
} |
|
|
|
?>
|
|
|