| 1 | <?php
|
|---|
| 2 | require("config.php");
|
|---|
| 3 | $lat=$_REQUEST['lat'];
|
|---|
| 4 | $lon=$_REQUEST['lon'];
|
|---|
| 5 | if ( !is_numeric($lat) or !is_numeric($lon) ) die;
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | // From: http://www.sitepoint.com/forums/showthread.php?656315-Adding-Distance-To-GPS-Coordinates-To-Get-Bounding-Box&p=4519646&viewfull=1#post4519646
|
|---|
| 9 | function new_coords($lat, $lon, $bearing, $distance)
|
|---|
| 10 | {
|
|---|
| 11 | // Radius of Earth in meters
|
|---|
| 12 | $radius = 6371000;
|
|---|
| 13 |
|
|---|
| 14 | // New latitude in degrees.
|
|---|
| 15 | $new_lat = rad2deg(asin(sin(deg2rad($lat)) * cos($distance / $radius) + cos(deg2rad($lat)) * sin($distance / $radius) * cos(deg2rad($bearing))));
|
|---|
| 16 |
|
|---|
| 17 | // New longitude in degrees.
|
|---|
| 18 | $new_lon = rad2deg(deg2rad($lon) + atan2(sin(deg2rad($bearing)) * sin($distance / $radius) * cos(deg2rad($lat)), cos($distance / $radius) - sin(deg2rad($lat)) * sin(deg2rad($new_lat))));
|
|---|
| 19 |
|
|---|
| 20 | // Assign new latitude and longitude to an array to be returned to the caller.
|
|---|
| 21 | $coord['lat'] = $new_lat;
|
|---|
| 22 | $coord['lon'] = $new_lon;
|
|---|
| 23 |
|
|---|
| 24 | return $coord;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // Boundary box 20x20 meters around the point
|
|---|
| 28 | $x1_coor = new_coords($lat, $lon, 315, 10); // Left upper point
|
|---|
| 29 | $x2_coor = new_coords($lat, $lon, 135, 10); // Right down point
|
|---|
| 30 |
|
|---|
| 31 | $x1_lon = $x1_coor['lon'];
|
|---|
| 32 | $x2_lon = $x2_coor['lon'];
|
|---|
| 33 | $x1_lat = $x1_coor['lat'];
|
|---|
| 34 | $x2_lat = $x2_coor['lat'];;
|
|---|
| 35 |
|
|---|
| 36 | $boundary_polygon=($x1_lon) . " " . ($x1_lat) . ", " . ($x1_lon) . " " . ($x2_lat) . ", " . ($x2_lon) . " " . ($x2_lat) . ", " . ($x2_lon) . " " . ($x1_lat) . ", " . ($x1_lon) . " " . ($x1_lat);
|
|---|
| 37 |
|
|---|
| 38 | header('Content-Type: application/json');
|
|---|
| 39 |
|
|---|
| 40 | $data = array();
|
|---|
| 41 |
|
|---|
| 42 | $data["coordinates"] = array( "lat" => "$lat", "lon" => "$lon");
|
|---|
| 43 | $data["source"] = "cuzk:ruian";
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | // building
|
|---|
| 47 | $query="
|
|---|
| 48 | select s.kod,
|
|---|
| 49 | s.pocet_podlazi, a.nazev zpusob_vyuziti, s.plati_od, s.pocet_bytu, s.dokonceni,
|
|---|
| 50 | s.zpusob_vyuziti_kod, a.osmtag_k, a.osmtag_v
|
|---|
| 51 | from rn_stavebni_objekt s
|
|---|
| 52 | left outer join osmtables.zpusob_vyuziti_objektu a on s.zpusob_vyuziti_kod = a.kod
|
|---|
| 53 | where st_contains(s.hranice,st_transform(st_geomfromtext('POINT(".$lon." ".$lat.")',4326),900913))
|
|---|
| 54 | and not s.deleted
|
|---|
| 55 | limit 1;
|
|---|
| 56 | ";
|
|---|
| 57 | $result=pg_query($CONNECT,$query);
|
|---|
| 58 |
|
|---|
| 59 | if (pg_num_rows($result) > 0)
|
|---|
| 60 | {
|
|---|
| 61 | $row = pg_fetch_array($result, 0);
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | $data["stavebni_objekt"] =
|
|---|
| 65 | array( "ruian_id" => $row["kod"],
|
|---|
| 66 | "pocet_podlazi" => $row["pocet_podlazi"],
|
|---|
| 67 | "zpusob_vyuziti" => $row["zpusob_vyuziti"],
|
|---|
| 68 | "zpusob_vyuziti_kod" => $row["zpusob_vyuziti_kod"],
|
|---|
| 69 | "zpusob_vyuziti_key" => $row["osmtag_k"],
|
|---|
| 70 | "zpusob_vyuziti_val" => $row["osmtag_v"],
|
|---|
| 71 | "pocet_bytu" => $row["pocet_bytu"],
|
|---|
| 72 | "dokonceni" => $row["dokonceni"],
|
|---|
| 73 | "plati_od" => $row["plati_od"]
|
|---|
| 74 | );
|
|---|
| 75 |
|
|---|
| 76 | // Reported issues on building
|
|---|
| 77 | $query="
|
|---|
| 78 | select nb.user_nick, nb.datum, nbd.popis, nb.poznamka
|
|---|
| 79 | from neplatne_budovy nb, neplatne_budovy_duvod nbd
|
|---|
| 80 | where nb.duvod = nbd.id and nb.kod = ".$row["kod"]."
|
|---|
| 81 | ;
|
|---|
| 82 | ";
|
|---|
| 83 | $result=pg_query($CONNECT,$query);
|
|---|
| 84 |
|
|---|
| 85 | if (pg_num_rows($result) > 0)
|
|---|
| 86 | {
|
|---|
| 87 | $row = pg_fetch_array($result, 0);
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | $data["nahlaseny_problem"] =
|
|---|
| 91 | array( "uzivatel" => $row["user_nick"],
|
|---|
| 92 | "datum" => $row["datum"],
|
|---|
| 93 | "duvod" => $row["popis"],
|
|---|
| 94 | "poznamka" => $row["poznamka"]
|
|---|
| 95 | );
|
|---|
| 96 | } else
|
|---|
| 97 | {
|
|---|
| 98 | $data["nahlaseny_problem"] = array();
|
|---|
| 99 | }
|
|---|
| 100 | } else
|
|---|
| 101 | {
|
|---|
| 102 | $data["stavebni_objekt"] = array();
|
|---|
| 103 | $data["nahlaseny_problem"] = array();
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | // Ghosts: Buildings without geometry in close neighbourhood
|
|---|
| 110 | $query="
|
|---|
| 111 | select * from (
|
|---|
| 112 | select s.kod,
|
|---|
| 113 | s.pocet_podlazi, a.nazev zpusob_vyuziti, s.plati_od, s.pocet_bytu, s.dokonceni,
|
|---|
| 114 | s.zpusob_vyuziti_kod, a.osmtag_k, a.osmtag_v,
|
|---|
| 115 | s.definicni_bod,
|
|---|
| 116 | st_distance( (st_transform(s.definicni_bod,4326))::geography, (st_setsrid(st_makepoint(".$lon.",".$lat."),4326))::geography ) dist
|
|---|
| 117 | from rn_stavebni_objekt s
|
|---|
| 118 | left outer join osmtables.zpusob_vyuziti_objektu a on s.zpusob_vyuziti_kod = a.kod
|
|---|
| 119 | where st_intersects(s.definicni_bod, st_transform(st_geometryfromtext(
|
|---|
| 120 | 'POLYGON (( $boundary_polygon ))' ,4326),900913))
|
|---|
| 121 | and not s.deleted
|
|---|
| 122 | and s.hranice is null
|
|---|
| 123 | order by definicni_bod <->
|
|---|
| 124 | st_transform(st_setsrid(st_makepoint(".$lon.",".$lat."),4326),900913)
|
|---|
| 125 | limit 5) as x
|
|---|
| 126 | order by dist;
|
|---|
| 127 | ";
|
|---|
| 128 | $result=pg_query($CONNECT,$query);
|
|---|
| 129 |
|
|---|
| 130 | if (pg_num_rows($result) > 0)
|
|---|
| 131 | {
|
|---|
| 132 | $so = array();
|
|---|
| 133 | for ($i = 0; $i < pg_num_rows($result); $i++)
|
|---|
| 134 | {
|
|---|
| 135 | $row = pg_fetch_array($result, $i);
|
|---|
| 136 | array_push($so,
|
|---|
| 137 | array( "ruian_id" => $row["kod"],
|
|---|
| 138 | "pocet_podlazi" => $row["pocet_podlazi"],
|
|---|
| 139 | "zpusob_vyuziti" => $row["zpusob_vyuziti"],
|
|---|
| 140 | "zpusob_vyuziti_kod" => $row["zpusob_vyuziti_kod"],
|
|---|
| 141 | "zpusob_vyuziti_key" => $row["osmtag_k"],
|
|---|
| 142 | "zpusob_vyuziti_val" => $row["osmtag_v"],
|
|---|
| 143 | "pocet_bytu" => $row["pocet_bytu"],
|
|---|
| 144 | "dokonceni" => $row["dokonceni"],
|
|---|
| 145 | "plati_od" => $row["plati_od"],
|
|---|
| 146 | "vzdalenost" => $row["dist"]
|
|---|
| 147 | ));
|
|---|
| 148 | }
|
|---|
| 149 | $data["so_bez_geometrie"] = $so;
|
|---|
| 150 | } else
|
|---|
| 151 | $data["so_bez_geometrie"] = array();
|
|---|
| 152 |
|
|---|
| 153 | // Addresses
|
|---|
| 154 | if ($data["stavebni_objekt"]["ruian_id"] > 0)
|
|---|
| 155 | {
|
|---|
| 156 | $query="
|
|---|
| 157 | select am.kod as adresni_misto_kod,
|
|---|
| 158 | am.stavobj_kod,
|
|---|
| 159 | st_asgeojson(st_transform(am.definicni_bod, 4326)) as pozice,
|
|---|
| 160 | CASE
|
|---|
| 161 | WHEN s.typ_kod = 1 THEN 'Číslo popisné'
|
|---|
| 162 | WHEN s.typ_kod = 2 THEN 'Číslo evidenční'
|
|---|
| 163 | WHEN s.typ_kod = 3 THEN 'bez č.p./č.e.'
|
|---|
| 164 | ELSE ''
|
|---|
| 165 | END cislo_typ,
|
|---|
| 166 | am.cislo_domovni,
|
|---|
| 167 | am.cislo_orientacni_hodnota || coalesce(am.cislo_orientacni_pismeno, '') cislo_orientacni,
|
|---|
| 168 | am.adrp_psc psc,
|
|---|
| 169 | ul.kod ulice_kod, ul.nazev ulice,
|
|---|
| 170 | c.kod cast_obce_kod, c.nazev cast_obce,
|
|---|
| 171 | momc.kod mestska_cast_kod, momc.nazev mestska_cast,
|
|---|
| 172 | ob.kod obec_kod, ob.nazev obec,
|
|---|
| 173 | ok.kod okres_kod, ok.nazev okres,
|
|---|
| 174 | vu.kod kraj_kod, vu.nazev kraj
|
|---|
| 175 | from ruian.rn_adresni_misto am
|
|---|
| 176 | left outer join rn_stavebni_objekt s on am.stavobj_kod = s.kod and not s.deleted
|
|---|
| 177 | left outer join osmtables.zpusob_vyuziti_objektu a on s.zpusob_vyuziti_kod = a.kod
|
|---|
| 178 | left outer join rn_ulice ul on am.ulice_kod = ul.kod and not ul.deleted
|
|---|
| 179 | left outer join rn_cast_obce c on c.kod = s.cobce_kod and not c.deleted
|
|---|
| 180 | left outer join rn_momc momc on momc.kod = s.momc_kod and not momc.deleted
|
|---|
| 181 | left outer join rn_obec ob on coalesce(ul.obec_kod, c.obec_kod) = ob.kod and not ob.deleted
|
|---|
| 182 | left outer join rn_okres ok on ob.okres_kod = ok.kod and not ok.deleted
|
|---|
| 183 | left outer join rn_vusc vu on ok.vusc_kod = vu.kod and not vu.deleted
|
|---|
| 184 | where am.stavobj_kod = ".$data["stavebni_objekt"]["ruian_id"]."
|
|---|
| 185 | and not am.deleted
|
|---|
| 186 | order by st_distance( (st_transform(am.definicni_bod,4326))::geography,
|
|---|
| 187 | (st_setsrid(st_makepoint(".$lon.",".$lat."),4326))::geography)
|
|---|
| 188 | ;
|
|---|
| 189 | ";
|
|---|
| 190 |
|
|---|
| 191 | $result=pg_query($CONNECT,$query);
|
|---|
| 192 | $error= pg_last_error($CONNECT);
|
|---|
| 193 | if (pg_num_rows($result) > 0)
|
|---|
| 194 | {
|
|---|
| 195 | $am = array();
|
|---|
| 196 | for ($i = 0; $i < pg_num_rows($result); $i++)
|
|---|
| 197 | {
|
|---|
| 198 | $row = pg_fetch_array($result, $i);
|
|---|
| 199 | $geometry=json_decode($row["pozice"], true);
|
|---|
| 200 | array_push($am,
|
|---|
| 201 | array("ruian_id" => $row["adresni_misto_kod"],
|
|---|
| 202 | "pozice" => $geometry['coordinates'],
|
|---|
| 203 | "budova_kod" => $row["stavobj_kod"],
|
|---|
| 204 | "cislo_typ" => $row["cislo_typ"],
|
|---|
| 205 | "cislo_domovni" => $row["cislo_domovni"],
|
|---|
| 206 | "cislo_orientacni" => $row["cislo_orientacni"],
|
|---|
| 207 | "ulice_kod" => $row["ulice_kod"],
|
|---|
| 208 | "ulice" => $row["ulice"],
|
|---|
| 209 | "cast_obce_kod" => $row["cast_obce_kod"],
|
|---|
| 210 | "cast_obce" => $row["cast_obce"],
|
|---|
| 211 | "mestska_cast_kod" => $row["mestska_cast_kod"],
|
|---|
| 212 | "mestska_cast" => $row["mestska_cast"],
|
|---|
| 213 | "obec_kod" => $row["obec_kod"],
|
|---|
| 214 | "obec" => $row["obec"],
|
|---|
| 215 | "okres_kod" => $row["okres_kod"],
|
|---|
| 216 | "okres" => $row["okres"],
|
|---|
| 217 | "kraj_kod" => $row["kraj_kod"],
|
|---|
| 218 | "kraj" => $row["kraj"],
|
|---|
| 219 | "psc" => $row["psc"]
|
|---|
| 220 | ));
|
|---|
| 221 | }
|
|---|
| 222 | $data["adresni_mista"] = $am;
|
|---|
| 223 | } else
|
|---|
| 224 | {
|
|---|
| 225 | // echo "error: $error\n";
|
|---|
| 226 | $data["adresni_mista"] = array();
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 | else
|
|---|
| 230 | {
|
|---|
| 231 | $query="
|
|---|
| 232 | select am.kod as adresni_misto_kod,
|
|---|
| 233 | am.stavobj_kod,
|
|---|
| 234 | st_asgeojson(st_transform(am.definicni_bod, 4326)) as pozice,
|
|---|
| 235 | CASE
|
|---|
| 236 | WHEN s.typ_kod = 1 THEN 'Číslo popisné'
|
|---|
| 237 | WHEN s.typ_kod = 2 THEN 'Číslo evidenční'
|
|---|
| 238 | WHEN s.typ_kod = 3 THEN 'bez č.p./č.e.'
|
|---|
| 239 | ELSE ''
|
|---|
| 240 | END cislo_typ,
|
|---|
| 241 | am.cislo_domovni,
|
|---|
| 242 | am.cislo_orientacni_hodnota || coalesce(am.cislo_orientacni_pismeno, '') cislo_orientacni,
|
|---|
| 243 | am.adrp_psc psc, ul.nazev ulice, c.nazev cast_obce,
|
|---|
| 244 | momc.nazev mestska_cast,
|
|---|
| 245 | ob.nazev obec, ok.nazev okres, vu.nazev kraj,
|
|---|
| 246 | st_distance( (st_transform(am.definicni_bod,4326))::geography, (st_setsrid(st_makepoint(".$lon.", ".$lat."),4326))::geography ) dist
|
|---|
| 247 | from ( select kod, stavobj_kod,
|
|---|
| 248 | cislo_domovni, cislo_orientacni_hodnota, cislo_orientacni_pismeno,
|
|---|
| 249 | ulice_kod, adrp_psc,
|
|---|
| 250 | definicni_bod
|
|---|
| 251 | from ruian.rn_adresni_misto
|
|---|
| 252 | where not deleted
|
|---|
| 253 | order by definicni_bod <->
|
|---|
| 254 | st_transform(st_setsrid(st_makepoint(".$lon.", ".$lat."),4326),900913)
|
|---|
| 255 | limit 100) as am
|
|---|
| 256 | left outer join rn_stavebni_objekt s on am.stavobj_kod = s.kod and not s.deleted
|
|---|
| 257 | left outer join osmtables.zpusob_vyuziti_objektu a on s.zpusob_vyuziti_kod = a.kod
|
|---|
| 258 | left outer join rn_ulice ul on am.ulice_kod = ul.kod and not ul.deleted
|
|---|
| 259 | left outer join rn_cast_obce c on c.kod = s.cobce_kod and not c.deleted
|
|---|
| 260 | left outer join rn_momc momc on momc.kod = s.momc_kod and not momc.deleted
|
|---|
| 261 | left outer join rn_obec ob on coalesce(ul.obec_kod, c.obec_kod) = ob.kod and not ob.deleted
|
|---|
| 262 | left outer join rn_okres ok on ob.okres_kod = ok.kod and not ok.deleted
|
|---|
| 263 | left outer join rn_vusc vu on ok.vusc_kod = vu.kod and not vu.deleted
|
|---|
| 264 | where st_distance( (st_transform(am.definicni_bod,4326))::geography, (st_setsrid(st_makepoint(".$lon.", ".$lat."),4326))::geography ) < 100
|
|---|
| 265 | order by dist
|
|---|
| 266 | limit 5
|
|---|
| 267 | ;
|
|---|
| 268 | ";
|
|---|
| 269 |
|
|---|
| 270 | $result=pg_query($CONNECT,$query);
|
|---|
| 271 | $error= pg_last_error($CONNECT);
|
|---|
| 272 | if (pg_num_rows($result) > 0)
|
|---|
| 273 | {
|
|---|
| 274 | $am = array();
|
|---|
| 275 | for ($i = 0; $i < pg_num_rows($result); $i++)
|
|---|
| 276 | {
|
|---|
| 277 | $row = pg_fetch_array($result, $i);
|
|---|
| 278 | $geometry=json_decode($row["pozice"], true);
|
|---|
| 279 | array_push($am,
|
|---|
| 280 | array("ruian_id" => $row["adresni_misto_kod"],
|
|---|
| 281 | "pozice" => $geometry['coordinates'],
|
|---|
| 282 | "budova_kod" => $row["stavobj_kod"],
|
|---|
| 283 | "cislo_typ" => $row["cislo_typ"],
|
|---|
| 284 | "cislo_domovni" => $row["cislo_domovni"],
|
|---|
| 285 | "cislo_orientacni" => $row["cislo_orientacni"],
|
|---|
| 286 | "ulice" => $row["ulice"],
|
|---|
| 287 | "cast_obce" => $row["cast_obce"],
|
|---|
| 288 | "mestska_cast" => $row["mestska_cast"],
|
|---|
| 289 | "obec" => $row["obec"],
|
|---|
| 290 | "okres" => $row["okres"],
|
|---|
| 291 | "kraj" => $row["kraj"],
|
|---|
| 292 | "psc" => $row["psc"],
|
|---|
| 293 | "vzdalenost" => $row["dist"]
|
|---|
| 294 | ));
|
|---|
| 295 | }
|
|---|
| 296 | $data["adresni_mista"] = $am;
|
|---|
| 297 | } else
|
|---|
| 298 | {
|
|---|
| 299 | // echo "error: $error\n";
|
|---|
| 300 | $data["adresni_mista"] = array();
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | // land
|
|---|
| 306 | $query="
|
|---|
| 307 | select s.id, a.nazev as druh_pozemku, b.nazev as zpusob_vyuziti, s.plati_od
|
|---|
| 308 | from rn_parcela s
|
|---|
| 309 | left outer join osmtables.druh_pozemku a on s.druh_pozemku_kod = a.kod
|
|---|
| 310 | left outer join osmtables.zpusob_vyuziti_pozemku b on s.zpusob_vyu_poz_kod = b.kod
|
|---|
| 311 | where st_contains(s.hranice,st_transform(st_geomfromtext('POINT(".$lon." ".$lat.")',4326),900913))
|
|---|
| 312 | and not s.deleted
|
|---|
| 313 | limit 1;
|
|---|
| 314 | ";
|
|---|
| 315 |
|
|---|
| 316 | $result=pg_query($CONNECT,$query);
|
|---|
| 317 | $error= pg_last_error($CONNECT);
|
|---|
| 318 | if (pg_num_rows($result) > 0)
|
|---|
| 319 | {
|
|---|
| 320 | $row = pg_fetch_array($result, 0);
|
|---|
| 321 |
|
|---|
| 322 | $data["parcela"] =
|
|---|
| 323 | array( "ruian_id" => $row["id"],
|
|---|
| 324 | "druh_pozemku" => $row["druh_pozemku"],
|
|---|
| 325 | "zpusob_vyuziti" => $row["zpusob_vyuziti"],
|
|---|
| 326 | "plati_od" => $row["plati_od"]
|
|---|
| 327 | );
|
|---|
| 328 | } else
|
|---|
| 329 | {
|
|---|
| 330 | // echo "error: $error\n";
|
|---|
| 331 | $data["parcela"] = array();
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | // ulice
|
|---|
| 335 | $query="
|
|---|
| 336 | select u.kod, u.nazev as jmeno
|
|---|
| 337 | from ( select kod, nazev, definicni_cara
|
|---|
| 338 | from ruian.rn_ulice
|
|---|
| 339 | where not deleted
|
|---|
| 340 | order by definicni_cara <->
|
|---|
| 341 | st_transform(st_setsrid(st_makepoint(".$lon.",".$lat."),4326),900913)
|
|---|
| 342 | limit 500) as u
|
|---|
| 343 | where st_distance( (st_transform(u.definicni_cara,4326))::geography, (st_setsrid(st_makepoint(".$lon.",".$lat."),4326))::geography ) < 10
|
|---|
| 344 | order by st_distance( (st_transform(u.definicni_cara,4326))::geography,
|
|---|
| 345 | (st_setsrid(st_makepoint(".$lon.",".$lat."),4326))::geography)
|
|---|
| 346 | limit 1
|
|---|
| 347 | ;
|
|---|
| 348 | ";
|
|---|
| 349 |
|
|---|
| 350 | $result=pg_query($CONNECT,$query);
|
|---|
| 351 | $error= pg_last_error($CONNECT);
|
|---|
| 352 | if (pg_num_rows($result) > 0)
|
|---|
| 353 | {
|
|---|
| 354 | $row = pg_fetch_array($result, 0);
|
|---|
| 355 |
|
|---|
| 356 | $data["ulice"] =
|
|---|
| 357 | array( "ruian_id" => $row["kod"],
|
|---|
| 358 | "jmeno" => $row["jmeno"]);
|
|---|
| 359 | } else
|
|---|
| 360 | {
|
|---|
| 361 | // echo "error: $error\n";
|
|---|
| 362 | $data["ulice"] = array();
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | // cadastral area
|
|---|
| 366 | $query="
|
|---|
| 367 | select ku.kod, ku.nazev,
|
|---|
| 368 | ob.kod obec_kod, ob.nazev obec,
|
|---|
| 369 | ok.kod okres_kod, ok.nazev okres,
|
|---|
| 370 | vu.kod kraj_kod, vu.nazev kraj
|
|---|
| 371 | from rn_katastralni_uzemi ku
|
|---|
| 372 | left outer join rn_obec ob on ku.obec_kod = ob.kod and not ob.deleted
|
|---|
| 373 | left outer join rn_okres ok on ob.okres_kod = ok.kod and not ok.deleted
|
|---|
| 374 | left outer join rn_vusc vu on ok.vusc_kod = vu.kod and not vu.deleted
|
|---|
| 375 | where st_contains(ku.hranice,st_transform(st_geomfromtext('POINT(".$lon." ".$lat.")',4326),900913))
|
|---|
| 376 | and not ku.deleted
|
|---|
| 377 | limit 1;
|
|---|
| 378 | ";
|
|---|
| 379 |
|
|---|
| 380 | $result=pg_query($CONNECT,$query);
|
|---|
| 381 | $error= pg_last_error($CONNECT);
|
|---|
| 382 | if (pg_num_rows($result) > 0)
|
|---|
| 383 | {
|
|---|
| 384 | $row = pg_fetch_array($result, 0);
|
|---|
| 385 |
|
|---|
| 386 | $data["katastr"] =
|
|---|
| 387 | array( "ruian_id" => $row["kod"],
|
|---|
| 388 | "nazev" => $row["nazev"],
|
|---|
| 389 | "obec_kod" => $row["obec_kod"],
|
|---|
| 390 | "obec" => $row["obec"],
|
|---|
| 391 | "okres_kod" => $row["okres_kod"],
|
|---|
| 392 | "okres" => $row["okres"],
|
|---|
| 393 | "kraj_kod" => $row["kraj_kod"],
|
|---|
| 394 | "kraj" => $row["kraj"],
|
|---|
| 395 | );
|
|---|
| 396 | } else
|
|---|
| 397 | {
|
|---|
| 398 | $data["katastr"] = array();
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | echo json_encode($data);
|
|---|
| 402 |
|
|---|
| 403 | ?>
|
|---|