[Mapbender-commits] r10218 - trunk/mapbender/http/geoportal
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Aug 26 08:22:19 PDT 2019
Author: armin11
Date: 2019-08-26 08:22:19 -0700 (Mon, 26 Aug 2019)
New Revision: 10218
Modified:
trunk/mapbender/http/geoportal/gaz_geom_mobile.php
Log:
New gazetteer client module for the german gazetteer of the Federal Agency for Cartography and Geodesy - conf file with access key needed!
Modified: trunk/mapbender/http/geoportal/gaz_geom_mobile.php
===================================================================
--- trunk/mapbender/http/geoportal/gaz_geom_mobile.php 2019-08-26 09:38:01 UTC (rev 10217)
+++ trunk/mapbender/http/geoportal/gaz_geom_mobile.php 2019-08-26 15:22:19 UTC (rev 10218)
@@ -1,30 +1,8 @@
<?php
-# $Id$
-# http://www.mapbender.org/index.php/gaz_service.php
-# Copyright (C) 2002 CCGIS
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
-require_once(dirname(__FILE__)."/../../conf/geoportal.conf");
-require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
-require_once(dirname(__FILE__)."/../classes/class_json.php");
-
-//Check if the result should be delivered as a webservice
-
-
-IF ($_REQUEST['resultTarget'] != 'web') {
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../../conf/bkgGeocoding.conf");
+if ($_REQUEST['resultTarget'] != 'web') {
(isset($_SERVER["argv"][1]))? ($user_id = $_SERVER["argv"][1]) : ($e = new mb_exception("geom: user lacks!"));
(isset($_SERVER["argv"][2]))? ($sstr = $_SERVER["argv"][2]) : ($e = new mb_exception("geom: string lacks!"));
(isset($_SERVER["argv"][3]))? ($epsg = $_SERVER["argv"][3]) : ($e = new mb_exception("geom: epsg lacks!"));
@@ -32,7 +10,7 @@
} else {
$maxResults = 15; //set default
$outputFormat = 'json'; //set default
- $epsg = 25832;
+ $searchEPSG = 4326;
if (isset($_REQUEST["maxResults"]) & $_REQUEST["maxResults"] != "") {
//validate integer to 100 - not more
@@ -83,767 +61,61 @@
$epsg = $searchEPSG;
$searchThruWeb = true;
}
-
-
-$e = new mb_notice("maxResults: ".$maxResults);
-$con = pg_connect("host=".GEOMDB_HOST." port=".GEOMDB_PORT." dbname=".GEOMDB_NAME." user=".GEOMDB_USER." password=".GEOMDB_PASSWORD)
-or die('Verbindungsaufbau fehlgeschlagen: ' . pg_last_error());
-
-function replaceChars($text){
-// $search = array( "ä", "ö", "ü", "Ä", "Ö", "Ü", "tr.", "ß" );
-// $repwith = array("ae", "oe", "ue", "AE", "OE", "UE", "tr","ss");
-
- //if(CHARSET=="UTF-8")
- // $text = utf8_decode($text);
-
-// $ret = str_replace($search, $repwith, $text);
-
- //if(CHARSET=="UTF-8")
- // $ret = utf8_encode($ret);
-
-// return $ret;
-
- return $text;
-
-}
-
-
-/******* conf ***********************************/
-$factor = 1;
-if (intval($epsg) == 4326) $factor = 0.00001;
-/******* wohnplätze *******************/
-$bufferWP = 1000*$factor;
-$arrayWP = array();
-$arrayWPKey = array();
-
-/******* gemeinde *********************/
-$bufferG = 100*$factor;
-$arrayG = array();
-$toleranceG = 100*$factor;
-
-/******* kreis *********************/
-$bufferK = 100*$factor;
-$arrayK = array();
-$toleranceK = 1000*$factor;
-/******* verbandsgemeinde *********************/
-$bufferV = 100*$factor;
-$arrayV = array();
-$toleranceV = 1000*$factor;
-/******* strasse *********************/
-$bufferSTR = 175*$factor;
-$arraySTR = array();
-$toleranceSTR = 100*$factor;
-/******* Strasse / Hsnr ****************/
-$bufferSH = 75*$factor;
-$arraySH = array();
-$toleranceSH = 1000*$factor;
-
-
-$e = new mb_notice("gaz_geom_mobile was invoked with string:".$sstr);
-/****** Workflow *********************************/
-/**/
-$test = str_replace("ß", "ss", $sstr);
-$e = new mb_notice("replaced test string: ".$test);
-$astr = mbw_split(",",replaceChars($sstr));
-$e = new mb_notice("replaced string: ".$astr[0]." ".$astr[1]." ".$astr[2]);
-//if only one string without any comma is given
-if(count($astr) == 1){
-
- $astr[0] = trim($astr[0]);
- $e = new mb_notice("gaz_geom_mobile: only one string detected: ".$astr[0]);
- //check if there may be a postal code
- $plz = getPlz($astr[0]);
- //check if there is a housenumber
- $hsnr = getNr($astr[0]);
- if($plz != false){
-
- //checkSize($astr[0]);
- checkWP($plz, strtoupper(getCity($astr[0])));
- checkGfromWP();
+//$searchText = "fall 10, mend";
+$key = BKG_GEOCODING_KEY;
+$basUrl1 = "https://sg.geodatenzentrum.de/gdz_geokodierung__";
+$basUrl2 = "/geosearch?query=";
+$maxFeatures = 15;
+//exchange some letters
+//$e = new mb_exception("searchText1: ".$searchText);
+$searchText= str_replace('ß', 'SS', str_replace('Ü', 'UE', str_replace('Ä', 'AE', str_replace('Ö', 'OE', mb_strtoupper($searchText)))));
+//$e = new mb_exception("searchText2: ".$searchText);
+$invokeUrl = $basUrl1.$key.$basUrl2.$searchText."&srsName=EPSG%3A".$searchEPSG;
+$searchConnector = new connector($invokeUrl);
+$searchResult = $searchConnector->file;
+$gazetteerObject = json_decode($searchResult);
+//parse json
+$returnObject = new stdClass();
+$countGeonames = 0;
+$returnObject->totalResultsCount = 0;
+foreach ($gazetteerObject->features as $feature) {
+ switch ($feature->properties->typ) {
+ //Landkreis/Gemeinde/Wohnplatz/Haus
+ case "Haus":
+ $returnObject->geonames[$countGeonames]->title = $feature->properties->text." ("."Haus".")";
+ $returnObject->geonames[$countGeonames]->category = "haus";
+ break;
+ case "Geoname":
+ $returnObject->geonames[$countGeonames]->title = $feature->properties->text;
+ break;
+ case "Strasse":
+ $returnObject->geonames[$countGeonames]->title = $feature->properties->text." ("."Straße".")";
+ $returnObject->geonames[$countGeonames]->category = "str";
+ break;
+ case "Ort":
+ $returnObject->geonames[$countGeonames]->title = $feature->properties->text." ("."Ort".")";
+ break;
+ default:
+ $returnObject->geonames[$countGeonames]->title = $feature->properties->text;
+ break;
}
- else if($hsnr != false){
-
- }
- else if($hsnr == false && $plz == false){
- checkWP(false,strtoupper($astr[0]));
- checkG(strtoupper($astr[0]));
- checkGfromWP();
- checkK(strtoupper($astr[0]));
- checkVg($astr[0]);
- }
+ $returnObject->geonames[$countGeonames]->category = "haus";
+ $returnObject->geonames[$countGeonames]->minx = str_replace(',', '.', $feature->bbox[0]);
+ $returnObject->geonames[$countGeonames]->miny = str_replace(',', '.',$feature->bbox[1]);
+ $returnObject->geonames[$countGeonames]->maxx = str_replace(',', '.',$feature->bbox[2]);
+ $returnObject->geonames[$countGeonames]->maxy = str_replace(',', '.',$feature->bbox[3]);
+ $countGeonames++;
}
-//if 2 parts are given - the first one may be a combined or a single value
-// '56743 mendig' or 'ferdinand-sauerbruch-strasse 15' or 'koblenz' or 'mendig' or, or, or ...
-else if(count($astr) == 2){
- $e = new mb_notice("gaz_geom_mobile: two strings detected: ".$astr[0]." and ".$astr[1]);
- $astr[0] = trim($astr[0]);
- $astr[1] = trim($astr[1]);
- $ckeys = array();
- $cnames = array();
- $cmissing = array();
-
- $myplz = false;
- $mycity = false;
- $mystr = false;
- $mynr = false;
- $myzs = false;
- $both = array();
-
- // check first entry for postal code
- if(getPlz($astr[0])){
- $myplz = getPlz($astr[0]);
- $e = new mb_notice("gaz_geom_mobile: postalcode detected: ".$myplz);
- if(getNr($astr[1])){
- $mynr = getNr($astr[1]);
- $myzs = getAppendix($astr[1]);
- $mystr = getStrn($astr[1]);
- }
- else{
- $mystr = trim($astr[1]);
- }
- }
- //check first entry for number
- else if(getNr($astr[0])){
- $mynr = getNr($astr[0]);
- $myzs = getAppendix($astr[0]);
- $mystr = getStrn($astr[0]);
- $e = new mb_notice('gaz_geom_mobile: search for streetname: '.$mystr);
- //check if in second value there is a postalcode
- if(getPlz($astr[1])){
- $myplz = getPlz($astr[1]);
- }
- //maybe it will be a city name
- else{
- $mycity = trim($astr[1]);
- $e = new mb_notice('gaz_geom_mobile: search for city: '.$mycity);
- }
- }
- //check second for postal code
- else{
- if(getPlz($astr[1])){
- $myplz = getPlz($astr[1]);
- }
- if(getNr($astr[1])){
- $mynr = getNr($astr[1]);
- $myzs = getAppendix($astr[1]);
- $mystr = getStrn($astr[1]);
- $mycity = getCity($astr[0]);
- }
- else{
- array_push($both,$astr[0]);
- array_push($both,$astr[1]);
- }
- }
- // workflow
- if(count($both) == 2){
- $a = "%".strtoupper(trim($both[0]))."%";
- $b = "%".strtoupper(trim($both[1]))."%";
- //$a = strtoupper(trim($both[0]))."%";
- //$b = strtoupper(trim($both[1]))."%";
+$returnObject->totalResultsCount = $countGeonames;
-
- $v = array($a, $a);
- $t = array('s', 's');
- $sql = "SELECT DISTINCT * FROM (SELECT DISTINCT gem_schl_neu, gemeinde_neu AS gem FROM gemeinden ";
- $sql .= "WHERE gemeinde_upper LIKE $1";
- $sql .= "UNION SELECT DISTINCT gem_schl_neu, gemeinde_gem_teile AS gem FROM wohnplatz ";
- $sql .= "WHERE ewz_int IS NOT NULL AND gemeinde_gem_teile_upper LIKE $2";
- $sql .= ") AS str";
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- array_push($ckeys, $row['gem_schl_neu']);
- array_push($cnames, encode($row['gem']));
- array_push($cmissing, $b);
- }
- $v = array($b, $b);
- $t = array('s', 's');
- $sql = "SELECT DISTINCT * FROM (SELECT DISTINCT gem_schl_neu, gemeinde_neu AS gem FROM gemeinden ";
- $sql .= "WHERE gemeinde_upper LIKE $1 ";
- $sql .= "UNION SELECT DISTINCT gem_schl_neu, gemeinde_gem_teile AS gem FROM wohnplatz ";
- $sql .= "WHERE ewz_int IS NOT NULL AND gemeinde_gem_teile_upper LIKE $2";
- $sql .= ") AS str";
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- array_push($ckeys, $row['gem_schl_neu']);
- array_push($cnames, encode($row['gem']));
- array_push($cmissing, $a);
- }
-
- if(count($ckeys)>0){
- for($i=0; $i<count($ckeys); $i++){
-
- $v = array($ckeys[$i], $cmissing[$i]);
- $t = array('i', 's');
- $sql = "SELECT DISTINCT strassenname, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(the_geom) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferSTR.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferSTR.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferSTR.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferSTR.") as maxy ";
- $sql .= "FROM strassenschluessel WHERE gem_schl = $1 ";
- $sql .= " AND (strassenname_upper LIKE $2)";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- $show = encode($row["strassenname"])." ".$cnames[$i];
- $e = new mb_notice('gaz_geom_mobile: street found: '.$row["strassenname"]);
- stack_it($arraySTR,"str",$show,"str",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
- }
-
- }
- }
- else{
-// echo $myplz ."#";
-// echo $mycity ."#";
-// echo $mystr ."#";
-// echo $mynr ."#";
-// echo $myzs ."#";
-// print_r($both);
- checkSH($mystr,$mynr,$myzs,$myplz,$mycity);
- }
-}
-
-
-
-//$fillSH = checkSH("Akazienweg",30,false,56075,"Koblenz");
-
-xml_output();
-
-function checkMinLength($str) {
- global $searchThruWeb;
- if (strlen($str) < 3) {
- if ($searchThruWeb) {
- //errorOutput();
- null_json_output();
- } else {
- null_output();
- }
- die();
- }
+if ($returnObject->totalResultsCount == 0) {
+ $returnObject->geonames = array();
}
-//Strasse Hausnummer
-function checkSH($s,$h,$z,$p,$o){
- global $bufferSH, $arraySH, $epsg;
-
- if ($o && $s) {
- $str_schl = array();
- $str_schl_gem = array();
- $ckeys = array();
- $cnames = array();
- $a = "%".strtoupper(trim($o))."%";
- $v = array($a, $a);
- $t = array('s', 's');
- $sql = "SELECT DISTINCT * FROM (SELECT DISTINCT gem_schl_neu, gemeinde_neu AS gem FROM gemeinden ";
- $sql .= "WHERE gemeinde_upper LIKE $1 ";
- $sql .= "UNION SELECT DISTINCT gem_schl_neu, gemeinde_gem_teile AS gem FROM wohnplatz ";
- $sql .= "WHERE ewz_int IS NOT NULL AND gemeinde_gem_teile_upper LIKE $2";
- $sql .=") AS str";
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- array_push($ckeys, $row['gem_schl_neu']);
- array_push($cnames, $row['gem']);
- }
-
- if(count($ckeys)>0){
- for($i=0; $i<count($ckeys); $i++){
-
- $v = array($ckeys[$i], "%". strtoupper(trim($s)). "%");
- //$v = array($ckeys[$i], strtoupper(trim($s)). "%");
- $t = array('i', 's');
- $sql = "SELECT DISTINCT strassenschluessel ";
- $sql .= "FROM strassenschluessel WHERE gem_schl = $1 ";
- $sql .= " AND strassenname_upper ILIKE $2";
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- array_push($str_schl, $row['strassenschluessel']);
- $e = new mb_notice('gaz_geom_mobile: strassenschluessel: '.$row["strassenname"].' for '.$s.' found' );
- array_push($str_schl_gem, $cnames[$i]);
- }
- }
- //select all streetkeys
- if (count($str_schl > 0)) {
- $v = array($h);
- $t = array('i');
- $sql = "SELECT DISTINCT name, hausnummer, zusatz, plz, post_ortsname, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(the_geom) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferSH.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferSH.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferSH.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferSH.") as maxy ";
- $sql .= "FROM hauskoordinaten ";
- $sql .= "WHERE hausnummer = $1 AND strschl_gesamt IN (";
-
- for($i=0; $i<count($str_schl); $i++){
- if($i > 0){$sql .= ",";}
- $sql .= "$".($i+2);
- array_push($v,$str_schl[$i]);
- array_push($t,'i');
- }
- $sql .= ")";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
-
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
-
-
-#$show = $row["name"]." ".$row["hausnummer"];
- if($row["zusatz"] != 'null'){
- # $show .= $row["zusatz"];
-
-$show = $row["name"]." ".$row["hausnummer"].$row["zusatz"];
-//$show = $row["name"]." ".$row["hausnummer"].$row["zusatz"]; TODO: exchange this, when the hauskoordinaten table is delivered in a homogenous encoding!
+if (isset($callback) && $callback != '') {
+ $returnJson = $callback."(".json_encode($returnObject).")";
+} else {
+ $returnJson = json_encode($returnObject);
}
- else
-{$show = $row["name"]." ".$row["hausnummer"];}
- $show .= ", " . $row["plz"]. " " . $row["post_ortsname"];
-
-
- stack_it($arraySH,"haus",$show,"sh",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
- }
- }
-
- }
- else {
- //is this 'else' obsolete?
- $sql = "SELECT DISTINCT name, hausnummer, zusatz, plz, post_ortsname, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(the_geom) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferSH.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferSH.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferSH.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferSH.") as maxy ";
- $sql .= "FROM hauskoordinaten ";
- $sql .= "WHERE name ILIKE $1 AND hausnummer = $2 ";
- $v = array("%".$s."%",$h);
- //$v = array($s."%",$h);
- $t = array('s','i');
- if($z){
- $sql .= "AND zusatz = $" . (count($v)+1);
- array_push($v,$z);
- array_push($t,'s');
- }
- if($p){
- $sql .= "AND plz = $" . (count($v)+1);
- array_push($v,$p);
- array_push($t,'i');
- }
- if($o){
- $sql .= "AND post_ortsname ILIKE $" . (count($v)+1);
- array_push($v,"%".$o."%");
- array_push($t,'s');
- }
- #$sql .= " GROUP BY the_geom, name, hausnummer, zusatz, plz, post_ortsname";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
-
- $show = $row["name"]." ".$row["hausnummer"];
- $e = new mb_notice('gaz_geom_mobile.php: streetname2: '.$row["name"]);
- //$show = $row["name"]." ".$row["hausnummer"]; TODO: see above
- if($row["zusatz"] != null){
- $show .= $row["zusatz"];
- }
- $show .= ", " . $row["plz"]. " " . $row["post_ortsname"];
- stack_it($arraySH,"haus",$show,"sh",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
- }
- return true;
-}
-//Wohnplatz
-function checkWP($plz,$name){
- global $bufferWP, $arrayWP, $arrayWPKey, $epsg;
- $v = array();
- $t = array();
- checkMinLength($name);
- $sql = "SELECT DISTINCT gemeinde_gem_teile, gem_schl_neu, postleitzahl,";
- $sql .= "SRID(the_geom) AS srid, AsGML(the_geom) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferWP.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferWP.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferWP.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferWP.") as maxy ";
- $sql .= "FROM wohnplatz WHERE ";
- if($plz == false){
- $sql .= "gemeinde_gem_teile_upper ILIKE $1 ";
- array_push($v,"%".$name."%");
- array_push($t,'s');
- }
- else if($name == false){
- $sql .= "postleitzahl = $1 ";
- array_push($v,$plz);
- array_push($t,'i');
- }
- else{
- $sql .= "postleitzahl = $1 AND gemeinde_gem_teile_upper ILIKE $2 ";
- array_push($v,$plz);
- array_push($t,'i');
- array_push($v,"%".$name."%");
- array_push($t,'s');
- }
- $sql .= "GROUP BY the_geom, gemeinde_gem_teile, gem_schl_neu, postleitzahl";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- $show = encode($row["gemeinde_gem_teile"]);
- $show.= " (Wohnplatz)";
- if(intval($row['postleitzahl'])> 1){ $show .= " (".$row['postleitzahl'].")"; }
- stack_it($arrayWP,"wohnplatz",$show,"wp",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- if(!in_array($row["gem_schl_neu"],$arrayWPKey)){
- array_push($arrayWPKey,$row["gem_schl_neu"]);
- }
- }
- return true;
-}
-function checkGfromWP(){
- global $arrayWPKey, $bufferG, $arrayG, $toleranceG, $epsg;
- if(count($arrayWPKey) == 0){
- return false;
- }
- $v = array();
- $t = array();
- $sql = "SELECT DISTINCT gemeinde_neu, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(Simplify(the_geom,$toleranceG)) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferG.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferG.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferG.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferG.") as maxy ";
- $sql .= "FROM gemeinden WHERE gem_schl_neu IN(";
- for($i=0; $i<count($arrayWPKey); $i++){
- if($i > 0){$sql .= ",";}
- $sql .= "$".($i+1);
- array_push($v,$arrayWPKey[$i]);
- array_push($t,'i');
- }
- $sql .= ") GROUP BY the_geom, gemeinde_neu";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- stack_it($arrayG,"gemeinde_neu",encode($row["gemeinde_neu"]." (Wohnplatz)"),"g",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
-}
-function checkG($str){
- global $bufferG, $arrayG, $toleranceG, $arrayWPKey, $epsg;
- checkMinLength($str);
- $tmp = array();
- $sql = "SELECT DISTINCT gemeinde_neu, gem_schl_neu, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(Simplify(the_geom,$toleranceG)) AS gml ,";
- $sql .= "(xmin(the_geom) - ".$bufferG.") as minx, ";
- $sql .= "(ymin(the_geom) - ".$bufferG.") as miny, ";
- $sql .= "(xmax(the_geom) + ".$bufferG.") as maxx, ";
- $sql .= "(ymax(the_geom) + ".$bufferG.") as maxy ";
- $sql .= "FROM gemeinden WHERE gemeinde_upper ILIKE $1 ";
- #$sql .= "GROUP BY the_geom, gemeinde, gem_schl_neu";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $v = array("%".$str."%");
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- stack_it($arrayG,"gemeinde_neu",encode($row["gemeinde_neu"]." (Gemeinde)"),"g",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- $tmp[count($tmp)] = $row["gem_schl_neu"];
- }
- $arrayWPKey = array_diff($arrayWPKey,$tmp);
-}
-
-function checkK($str){
- global $bufferK, $arrayK, $toleranceK, $epsg;
- checkMinLength($str);
- $sql = "SELECT DISTINCT kreis, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(Simplify(the_geom,".$toleranceK.")) AS gml ,";
- $sql .= "(xmin(the_geom)-".$bufferK.") as minx, ";
- $sql .= "(ymin(the_geom)-".$bufferK.") as miny, ";
- $sql .= "(xmax(the_geom)+".$bufferK.") as maxx, ";
- $sql .= "(ymax(the_geom)+".$bufferK.") as maxy ";
- $sql .= "FROM kreis_fl WHERE kreis_upper ILIKE $1 ";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $v = array("%".$str."%");
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- stack_it($arrayK,"kreis",encode($row["kreis"]." (Landkreis)"),"k",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
-}
-function checkVg($str){
- global $bufferV, $arrayV, $toleranceV, $epsg;
- checkMinLength($str);
- $sql = "SELECT DISTINCT vg, ";
- $sql .= "SRID(the_geom) AS srid, AsGML(Simplify(the_geom,".$toleranceV.")) AS gml ,";
- $sql .= "(xmin(the_geom)-".$bufferV.") as minx, ";
- $sql .= "(ymin(the_geom)-".$bufferV.") as miny, ";
- $sql .= "(xmax(the_geom)+".$bufferV.") as maxx, ";
- $sql .= "(ymax(the_geom)+".$bufferV.") as maxy ";
- $sql .= "FROM vg_fl WHERE vg ILIKE $1 ";
- if (isset($epsg) && is_numeric($epsg) && intval($epsg) != 25832) {
- $sql = str_replace("the_geom", "transform(the_geom,".$epsg.")", $sql);
- }
- $v = array("%".$str."%");
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- stack_it($arrayV,"verbandsgemeinde",encode($row["vg"]." (Verbandsgemeinde)"),"vg",$row["srid"],$row["minx"],$row["miny"],$row["maxx"],$row["maxy"],$row["gml"]);
- }
-}
-function stack_it(&$stack,$category,$showtitle,$prefix,$srid,$minx,$miny,$maxx,$maxy,$gml){
- global $searchThruWeb;
- if (!$searchThruWeb) {
- $doc = new DOMDocument();
- $member = $doc->createElement("member");
- $doc->appendChild($member);
- $member->setAttribute('id',$prefix.count($stack));
- $fc = $doc->createElement("FeatureCollection");
- $member->appendChild($fc);
- $fc->setAttribute("xmlns:gml","http://www.opengis.net/gml");
- $bb = $doc->createElement("boundedBy");
- $fc->appendChild($bb);
- $box = $doc->createElement("Box");
- $bb->appendChild($box);
- $box->setAttribute('srsName',"EPSG:".$srid);
- $c = $doc->createElement("coordinates");
- $box->appendChild($c);
- $coords = $doc->createTextNode($minx.",".$miny." ".$maxx.",".$maxy);
- $c->appendChild($coords);
- $fm = $doc->createElement("featureMember");
- $fc->appendChild($fm);
- $wp = $doc->createElement($category);
- $fm->appendChild($wp);
- $title = $doc->createElement("title");
- $wp->appendChild($title);
- $ttitle = $doc->createTextNode($showtitle);
- $title->appendChild($ttitle);
- $geom = $doc->createElement("the_geom");
- $wp->appendChild($geom);
- $myNode = @simplexml_load_string($gml);
- $mySNode = dom_import_simplexml($myNode);
- $domNode = $doc->importNode($mySNode, true);
- $geom->appendChild($domNode);
- array_push($stack,$member);
- } else {
- //generate simple json objects as array elements
- $classJSON = new Mapbender_JSON;
- $returnJSON = new stdClass;
- $returnJSON->title = $showtitle;
- $returnJSON->category = $category;
- $returnJSON->minx = $minx;
- $returnJSON->miny = $miny;
- $returnJSON->maxx = $maxx;
- $returnJSON->maxy = $maxy;
- $returnJSON = $classJSON->encode($returnJSON);
- array_push($stack,$returnJSON);
- }
-}
-
-function null_output(){
- global $sstr, $arrayWP, $arrayG, $arrayK, $arraySH, $arraySTR, $arrayV;
- $doc = new DOMDocument('1.0');
- $doc->encoding = CHARSET;
- $result = $doc->createElement("result");
- $doc->appendChild($result);
- $ready = $doc->createElement('ready');
- $result->appendChild($ready);
- $tready = $doc->createTextNode("true");
- $ready->appendChild($tready);
- echo $doc->saveXML();
-}
-
-function null_json_output(){
- global $sstr, $arrayWP, $arrayG, $arrayK, $arraySH, $arraySTR, $arrayV;
- echo "{\"totalResultsCount\":0,\"geonames\":[]}";
-}
-
-
-
-
-
-function xml_output(){
- global $sstr, $arrayWP, $arrayG, $arrayK, $arraySH, $arraySTR, $arrayV, $searchThruWeb, $callback, $maxResults;
- if (!$searchThruWeb) {
- $doc = new DOMDocument('1.0');
- $doc->encoding = CHARSET;
- $result = $doc->createElement("result");
- $doc->appendChild($result);
-
- for($i=0; $i<count($arrayWP); $i++){
- $domNode = $doc->importNode($arrayWP[$i], true);
- $result->appendChild($domNode);
- }
- for($i=0; $i<count($arrayG); $i++){
- $domNode = $doc->importNode($arrayG[$i], true);
- $result->appendChild($domNode);
- }
- for($i=0; $i<count($arrayK); $i++){
- $domNode = $doc->importNode($arrayK[$i], true);
- $result->appendChild($domNode);
- }
- for($i=0; $i<count($arraySH); $i++){
- $domNode = $doc->importNode($arraySH[$i], true);
- $result->appendChild($domNode);
- }
- for($i=0; $i<count($arraySTR); $i++){
- $domNode = $doc->importNode($arraySTR[$i], true);
- $result->appendChild($domNode);
- }
- for($i=0; $i<count($arrayV); $i++){
- $domNode = $doc->importNode($arrayV[$i], true);
- $result->appendChild($domNode);
- }
- $ready = $doc->createElement('ready');
- $result->appendChild($ready);
- $tready = $doc->createTextNode("true");
- $ready->appendChild($tready);
- //if ($searchThruWeb) {
- // header("Content-type: application/xhtml+xml; charset=UTF-8");
- //}
- echo $doc->saveXML();
- } else {
- //generate json object with gml content
- $classJSON = new Mapbender_JSON;
- $returnJSON = new stdClass;
-
- $countGeonames = 0;
- $returnJSON->totalResultsCount = 0;
-
- for($i=0; $i<count($arrayK); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arrayK[$i]);
- $countGeonames++;
- if (countGeonames >= $maxResults) {
- }
- }
-
- for($i=0; $i<count($arrayV); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arrayV[$i]);
- $countGeonames++;
- }
-
- for($i=0; $i<count($arrayG); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arrayG[$i]);
- $countGeonames++;
- }
-
- for($i=0; $i<count($arraySTR); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arraySTR[$i]);
- $countGeonames++;
- }
-
- for($i=0; $i<count($arrayWP); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arrayWP[$i]);
- $countGeonames++;
- }
-
- for($i=0; $i<count($arraySH); $i++){
- if ($countGeonames >= $maxResults) {
- break;
- }
- $returnJSON->geonames[$countGeonames] = $classJSON->decode($arraySH[$i]);
- $countGeonames++;
- }
- $returnJSON->totalResultsCount = $countGeonames;
- if ($returnJSON->totalResultsCount == 0) {
- $returnJSON->geonames = array();
- }
- if (isset($callback) && $callback != '') {
- $returnJSON = $callback."(".$classJSON->encode($returnJSON).")";
- } else {
- $returnJSON = $classJSON->encode($returnJSON);
- }
-
- echo $returnJSON;
- }
-
-}
-function encode($s){
-# if(CHARSET == 'UTF-8'){
-# $s = utf8_encode($s);
-# }
- return $s;
-}
-function getPlz($str){
- $p = "/.*(\d{5}).*/";
- $am = array();
- if(preg_match($p, $str, $am)){
- return $am[1];
- }
- else{
- return false;
- }
-}
-function getCity($str){
- $p = "/(^\d{5}){0,1}(.*)/";
- $am = array();
- if(preg_match($p, $str, $am)){
- return trim($am[2]);
- }
- else{
- return false;
- }
-}
-function getNr($str){
- $p = "/.*[^0-9](\d{1,4})[^0-9]*/";
- $am = array();
- if(preg_match($p, $str, $am)){
- return $am[(count($am)-1)];
- }
- else{
- return false;
- }
-}
-function getStrn($str){
- $p = "/^(\D+)\d/";
- $am = array();
- if(preg_match($p, $str, $am)){
- return trim($am[1]);
- }
- else{
- return false;
- }
-}
-function getAppendix($str){
- $p = "/.*\d+.*(\D{1})/";
- $am = array();
- if(preg_match($p, $str, $am)){
- return $am[1];
- }
- else{
- return false;
- }
-}
-function getCKeysByName($city){
- global $ckeys;
- $city = "%".strtoupper(trim($city))."%";
- $sql = "SELECT gem_schl_neu FROM gis.wohnplatz ";
- $sql .= "WHERE gemeinde_gem_teile_upper ILIKE $1 ";
- $v = array($city);
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- while($row = db_fetch_array($res)){
- array_push($ckeys, $row['gem_schl_neu']);
- }
-}
+header('Content-Type: application/json');
+echo $returnJson;
?>
More information about the Mapbender_commits
mailing list