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.
110 righe
4.9 KiB
110 righe
4.9 KiB
2 anni fa
|
<?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;
|
||
|
}
|
||
|
|
||
|
|
||
|
//$_SESSION['cataparticella'] = str_replace(' ', '',$_GET['estremiCatastali']);
|
||
|
//echo "CATA PARTICELLA = ".$_SESSION['cataparticella']."<br>";
|
||
|
$arraymappale = explode(';', $_SESSION['cataparticella']);
|
||
|
|
||
|
if (count($arraymappale) > 0) {
|
||
|
|
||
|
foreach( $arraymappale as $index => $mappale ) {
|
||
|
|
||
|
if(!$query = @pg_query("SELECT id FROM ".$_SESSION['COMUNE_PROV'].".particelle WHERE comune = '".$_SESSION['COMUNE_BELF']."' AND mappale ='".$mappale."';"))
|
||
|
die("Error query CERCA PARTICELLA: " . pg_last_error($conn));
|
||
|
|
||
|
if (pg_numrows($query) > 0){
|
||
|
|
||
|
while($rowparticelle = pg_fetch_assoc($query)) {
|
||
|
$gidquery[] = $rowparticelle['id'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$valorearray = count($gidquery);
|
||
|
//echo "VALORE ARRAY = ".$valorearray."<br>";
|
||
|
$stringa = implode(' OR id=', $gidquery);
|
||
|
$_SESSION['QUERY_CDU'] = $stringa;
|
||
|
//echo '<br>STRINGA: '.$_SESSION['QUERY_CDU']."<br>";
|
||
|
$_SESSION['GET_CDU'] = 1;
|
||
|
|
||
|
} else {
|
||
|
unset($_SESSION['cataparticella']);
|
||
|
unset($_SESSION['QUERY_CDU']);
|
||
|
$_SESSION['GET_CDU'] = 0;
|
||
|
}
|
||
|
|
||
|
// 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'].";";
|
||
|
|
||
|
$rs = pg_query($conn, $sql_catasto);
|
||
|
if (!$rs) {echo "ERROR GEOM PARTICELLE.\n"; } else { /*echo "QUERY OKKEY <br><br>";*/ }
|
||
|
|
||
|
$output = '';
|
||
|
$rowOutput = '';
|
||
|
|
||
|
while ($row = pg_fetch_assoc($rs)) {
|
||
|
$_SESSION['CENTER'] = $row['lat'] .", ".$row['long'];
|
||
|
$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 . '}, "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 . ' ] }';
|
||
|
//$var=fopen("data/comune".$comuneuser.".json","w");
|
||
|
$_SESSION['SELECT_PARTICELLA'] = $particella;
|
||
|
|
||
|
|
||
|
if ($valorearray >= 1){
|
||
|
// ########## 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['CENTER'] = $lat .", ".$lng;
|
||
|
$_SESSION['ZOOM'] = 18;
|
||
|
|
||
|
|
||
|
// ########## CALCOLO BOUND PARTICELLA
|
||
|
if (!$strbound = @pg_query("SELECT ST_YMax(ST_Buffer(ST_Transform(geom,4326),0.15)) as ymax, ST_XMax(ST_Buffer(ST_Transform(geom,4326),0.15)) as xmax, ST_YMin(ST_Buffer(ST_Transform(geom,4326),0.15)) as ymin, ST_XMin(ST_Buffer(ST_Transform(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)) {
|
||
|
$_SESSION['BOUND'] = "[" . $rowbound['ymin'] . ", " . $rowbound['xmin'] . "],[" . $rowbound['ymax'] . ", " . $rowbound['xmax'] . "]";
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
|
||
|
$rs_comune = "SELECT bound FROM public.comuni WHERE cod_belf = '" . $_SESSION['COMUNE_BELF'] . "'";
|
||
|
$result = pg_query($conn, $rs_comune) or die('Query failed4');
|
||
|
$row_comune = pg_num_rows($result);
|
||
|
if ($row_comune > 0) {
|
||
|
while ($comunesession = pg_fetch_assoc($result)) {
|
||
|
$_SESSION['BOUND'] = $comunesession['bound'];
|
||
|
|
||
|
}
|
||
|
}
|
||
|
$_SESSION['CENTER'] = $_SESSION['LAT'] .", ".$_SESSION['LONG'];
|
||
|
$_SESSION['ZOOM'] = 17; }
|
||
|
|
||
|
?>
|