-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindirizzo_results_2geojson.php
executable file
·199 lines (146 loc) · 6.32 KB
/
indirizzo_results_2geojson.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
#################################
# Catasto urbano
################################
// recupera la variabile idSoggetto
//$idsog=trim($_GET["idSog"]);
if (!$_GET["s"]){
exit;
}
$s=$_GET["s"];
$c=$_GET["c"];
$d=$_GET["d"];
################################### carlo ######################################################
// recupera il nominativo cercato, attraverso $idsoggetto della tabella PersonaFisica o PersonaGiuridica
//$nominativo=htmlspecialchars($_GET["nome"]);
//$nominativo=$_GET["n"];
################################### carlo fine ###################################################
// connette a catasto.db
$conn_c = new SQLite3('catasto.db');
// IMPOSTA LA QUERY per trovare le particelle al NCTR tramite idSoggetto $$idsog
// * modificata query -> eliminato il raggruppamento per id_immobile che escludeva le particelle graffate nella
// creazione del geojson
$query_nceu="
select
'IND'.'idImmobile',
ltrim(II.foglio,'0') as fg,
ltrim(II.numero,'0') as map,
ltrim(II.subalterno,'0') as sub,
ltrim('UI'.'zona','0') as zona,
CASE
WHEN 'UI'.'categoria'<>'A10'
THEN replace( 'UI'.'categoria', '0', '/' )
ELSE replace( 'UI'.'categoria', '10', '/10' )
END as categoria,
ltrim('UI'.'classe','0') as classe,
CASE
WHEN substr('UI'.'categoria',1,1)='A'
THEN ('UI'.'consistenza'||' vani')
WHEN substr('UI'.'categoria',1,1)='B'
THEN ('UI'.'consistenza'||' mc')
WHEN substr('UI'.'categoria',1,1)='C'
THEN ('UI'.'consistenza'||' mq')
ELSE ''
END as consistenza,
'€ '||' '||'UI'.'renditaEuro' as rendita,
(ltrim('UI'.'piano1','0')||' '||ltrim('UI'.'piano2','0')||' '||ltrim('UI'.'piano3','0')||' '||ltrim('UI'.'piano4','0')) as piano,
'COD_TOPONIMO'.'decodifica' as d,
'COD_TOPONIMO'.'decodifica'||' '||'IND'.'indirizzo'||' ' ||ltrim('IND'.'civico1','0')||' ' ||ltrim('IND'.'civico2','0')||' ' ||ltrim('IND'.'civico3','0') as indirizzo,
ltrim('IND'.'civico1','0')||' ' ||ltrim('IND'.'civico2','0')||' ' ||ltrim('IND'.'civico3','0') as civic
from 'IDENTIFICATIVI_IMMOBILIARI' as 'II','INDIRIZZI' as 'IND'
left join
'COD_TOPONIMO'
on
'COD_TOPONIMO'.'codice' = 'IND'.'toponimo'
left join
'UNITA_IMMOBILIARI' as 'UI'
on
'UI'.'idImmobile'='IND'.'idImmobile'
where 'II'.'idImmobile'='IND'.'idImmobile' AND d like '%" .$d."%' AND indirizzo like '%".$s."%' AND civic like '%".$c."%'
GROUP BY 'IND'.'idImmobile'
ORDER BY 'IND'.'idImmobile'";
## imposto il limite di tempo, in secondi, per eseguire la query . Di default è 30 s
## impostato il limite di tempo ad 1 h -> 3600 sec
set_time_limit(3600);
//esegue la query
$rs_c = $conn_c->query($query_nceu);
### Apre la collezione GeoJson delle feature geometriche da particelle
$geojsonp = array(
'type' => 'FeatureCollection',
'features' => array()
);
################# Estrae gli elementi: fa' un loop su tutti i record di catasto e ricerca in particelle
while ($row_c = $rs_c->fetchArray(SQLITE3_ASSOC)) {
//APRE ->estrae i dati per effettuare la query su spatialite
// occhio al formato del foglio e mappale che si cerca in Arenzano foglio - '0025' mappale '1100'
$f=str_pad($row_c['fg'],4,'0',STR_PAD_LEFT) ;
$m=$row_c['map'];
#echo $f . " --- " . $m;
# Connect to SQLite database
$conn_p = new SQLite3('catasto_cart_4326.sqlite');
# Build SQL SELECT statement and return the geometry as a GeoJSON element
# $conn_p->exec("SELECT load_extension('mod_spatialite.so')");
$conn_p->loadExtension('mod_spatialite.so');
#$sql = "SELECT foglio, mappale, AsGeoJSON(geometry) as geom FROM Particelle where foglio='0025' and mappale='1100'";
$sqlp = "SELECT foglio, mappale, AsGeoJSON(geometry) as geom FROM Particelle where foglio= '" . $f ."' AND mappale= '" . $m ."' ";
$rs_p = $conn_p->query($sqlp);
if (!$rs_p) {
echo 'An SQL error occured.\n';
exit;
}
# APRE Loop through rows to build feature arrays
while($row_p = $rs_p->fetchArray()) {
//echo $row_p['foglio'] . " -- " . $row_p['mappale'];
$featurep = array
(
'type' => 'Feature',
'geometry' => json_decode($row_p['geom'], true),
# Pass other attribute columns here
'properties' => array
(
'foglio' => $row_p['foglio'],
'mappale' => $row_p['mappale'],
# qui sotto inseriamo dei dati dalle tighe del db catasto
# carlo magari dati + significativi qui modificando la query sopra sul catasto.db
'sub' => $row_c['sub'],
//'denominazione' => $nominativo,
//'titolo' => $row_c['titolo'],
'zona' => $row_c['zona'],
'cat' => $row_c['categoria'],
'cons' => $row_c['consistenza'],
'indirizzo' => $row_c['indirizzo'],
'piano' => $row_c['piano'],
'rendita' => $row_c['rendita'],
'idImm' => $row_c['idImmobile']
)
);
# Add feature arrays to feature collection array
array_push($geojsonp['features'], $featurep);
} // CHIUDE Loop through rows to build feature arrays
$nomefileGeojson = ($d."_".$s."_".$c);
$conn_p->close();
$conn_p = NULL;
} // CHIUDE -> estrae i dati per effettuare la query su spatialite
# ritorna il geojosn al consumer per poter interrogare ed aprire in qgis ad esempio
# ma anche in leaflet
header('Content-type: application/json');
#echo json_encode($geojsonp, JSON_PRETTY_PRINT);
#echo json_encode($geojson, JSON_NUMERIC_CHECK);
# Creiamo la directory se non esiste e scriviamo il risultato nella /tmp/cxc
# di unix
$curdir=getcwd();
if (!is_dir( $curdir . '/tmp/cxcout')) {
mkdir( $curdir . '/tmp/cxcout', 0777, true);
}
$filename='/tmp/cxcout/' . $nomefileGeojson . '_NCEU' . '.geojson';
$sysfilename=$curdir . $filename;
$fh = fopen($sysfilename, 'w');
fwrite($fh, json_encode($geojsonp, JSON_PRETTY_PRINT));
fclose($fh);
# closing the DB connection
$conn_c->close();
$conn_c = NULL;
header("Location: ./ll/mappa_urb.html?geojsonfile=" . ".." . $filename);
die();
exit;
?>