From: Sarah Hoffmann Date: Sun, 13 Mar 2016 20:40:38 +0000 (+0100) Subject: Merge pull request #381 from lonvia/cmake-port X-Git-Tag: v3.0.0~198 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/279ea25e7debfeef06a0247d55499ee02b6b4de6?hp=30d56b7064293d7e4ffc2d030a9b7da53210a08e Merge pull request #381 from lonvia/cmake-port Replace autotools with cmake and update osm2pgsql --- diff --git a/Vagrantfile b/Vagrantfile index 30bc9375..f32640f1 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -14,6 +14,10 @@ Vagrant.configure("2") do |config| sub.vm.box = "ubuntu/trusty64" sub.vm.provision :shell, :path => "vagrant/ubuntu-trusty-provision.sh" end + config.vm.define "ubuntu-php7" do |sub| + sub.vm.box = "ubuntu/trusty64" + sub.vm.provision :shell, :path => "vagrant/ubuntu-trusty-php7-provision.sh" + end config.vm.define "centos" do |sub| sub.vm.box = "bento/centos-7.2" sub.vm.provision :shell, :path => "vagrant/centos-7-provision.sh" diff --git a/lib/Geocode.php b/lib/Geocode.php index a6ff279c..19ed354f 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -1,4 +1,6 @@ $aResult) { // Default - $fDiameter = 0.0001; - - if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) - && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) - { - $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']; - } - elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) - && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) + $fDiameter = getResultDiameter($aResult); + + $oPlaceLookup = new PlaceLookup($this->oDB); + $oPlaceLookup->setIncludePolygonAsPoints($this->bIncludePolygonAsPoints); + $oPlaceLookup->setIncludePolygonAsText($this->bIncludePolygonAsText); + $oPlaceLookup->setIncludePolygonAsGeoJSON($this->bIncludePolygonAsGeoJSON); + $oPlaceLookup->setIncludePolygonAsKML($this->bIncludePolygonAsKML); + $oPlaceLookup->setIncludePolygonAsSVG($this->bIncludePolygonAsSVG); + $oPlaceLookup->setPolygonSimplificationThreshold($this->fPolygonSimplificationThreshold); + + $aOutlineResult = $oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2); + if ($aOutlineResult) { - $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']; - } - $fRadius = $fDiameter / 2; - - if (CONST_Search_AreaPolygons) - { - // Get the bounding box and outline polygon - $sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,"; - $sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,"; - $sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,"; - $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon"; - if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson"; - if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml"; - if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; - if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext"; - $sFrom = " from placex where place_id = ".$aResult['place_id']; - if ($this->fPolygonSimplificationThreshold > 0) - { - $sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx"; - } - else - { - $sSQL .= $sFrom; - } - - $aPointPolygon = $this->oDB->getRow($sSQL); - if (PEAR::IsError($aPointPolygon)) - { - failInternalError("Could not get outline.", $sSQL, $aPointPolygon); - } - - if ($aPointPolygon['place_id']) - { - if ($this->bIncludePolygonAsGeoJSON) $aResult['asgeojson'] = $aPointPolygon['asgeojson']; - if ($this->bIncludePolygonAsKML) $aResult['askml'] = $aPointPolygon['askml']; - if ($this->bIncludePolygonAsSVG) $aResult['assvg'] = $aPointPolygon['assvg']; - if ($this->bIncludePolygonAsText) $aResult['astext'] = $aPointPolygon['astext']; - - if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null ) - { - $aResult['lat'] = $aPointPolygon['centrelat']; - $aResult['lon'] = $aPointPolygon['centrelon']; - } - - if ($this->bIncludePolygonAsPoints) - { - $aPolyPoints[] = geometryText2Points($aPointPolygon['astext'],$fRadius); - - // Output data suitable for display (points and a bounding box) - if (isset($aPolyPoints)) - { - $aResult['aPolyPoints'] = array(); - foreach($aPolyPoints as $aPoint) - { - $aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]); - } - } - } - - if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) - { - $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; - $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; - } - if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) - { - $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; - $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; - } - $aResult['aBoundingBox'] = array((string)$aPointPolygon['minlat'],(string)$aPointPolygon['maxlat'],(string)$aPointPolygon['minlon'],(string)$aPointPolygon['maxlon']); - } + $aResult = array_merge($aResult, $aOutlineResult); } - + if ($aResult['extra_place'] == 'city') { $aResult['class'] = 'place'; @@ -1724,32 +1659,6 @@ $aResult['rank_search'] = 16; } - if (!isset($aResult['aBoundingBox'])) - { - $iSteps = max(8,min(100,$fRadius * 3.14 * 100000)); - $fStepSize = (2*pi())/$iSteps; - $aPointPolygon['minlat'] = $aResult['lat'] - $fRadius; - $aPointPolygon['maxlat'] = $aResult['lat'] + $fRadius; - $aPointPolygon['minlon'] = $aResult['lon'] - $fRadius; - $aPointPolygon['maxlon'] = $aResult['lon'] + $fRadius; - - // Output data suitable for display (points and a bounding box) - if ($this->bIncludePolygonAsPoints) - { - $aPolyPoints = array(); - for($f = 0; $f < 2*pi(); $f += $fStepSize) - { - $aPolyPoints[] = array('',$aResult['lon']+($fRadius*sin($f)),$aResult['lat']+($fRadius*cos($f))); - } - $aResult['aPolyPoints'] = array(); - foreach($aPolyPoints as $aPoint) - { - $aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]); - } - } - $aResult['aBoundingBox'] = array((string)$aPointPolygon['minlat'],(string)$aPointPolygon['maxlat'],(string)$aPointPolygon['minlon'],(string)$aPointPolygon['maxlon']); - } - // Is there an icon set for this type of result? if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['icon']) && $aClassType[$aResult['class'].':'.$aResult['type']]['icon']) diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php index c5129fee..04e45d5a 100644 --- a/lib/PlaceLookup.php +++ b/lib/PlaceLookup.php @@ -15,6 +15,14 @@ protected $bNameDetails = false; + protected $bIncludePolygonAsPoints = false; + protected $bIncludePolygonAsText = false; + protected $bIncludePolygonAsGeoJSON = false; + protected $bIncludePolygonAsKML = false; + protected $bIncludePolygonAsSVG = false; + protected $fPolygonSimplificationThreshold = 0.0; + + function PlaceLookup(&$oDB) { $this->oDB =& $oDB; @@ -46,6 +54,48 @@ } } + + function setIncludePolygonAsPoints($b = true) + { + $this->bIncludePolygonAsPoints = $b; + } + + function getIncludePolygonAsPoints() + { + return $this->bIncludePolygonAsPoints; + } + + function setIncludePolygonAsText($b = true) + { + $this->bIncludePolygonAsText = $b; + } + + function getIncludePolygonAsText() + { + return $this->bIncludePolygonAsText; + } + + function setIncludePolygonAsGeoJSON($b = true) + { + $this->bIncludePolygonAsGeoJSON = $b; + } + + function setIncludePolygonAsKML($b = true) + { + $this->bIncludePolygonAsKML = $b; + } + + function setIncludePolygonAsSVG($b = true) + { + $this->bIncludePolygonAsSVG = $b; + } + + function setPolygonSimplificationThreshold($f) + { + $this->fPolygonSimplificationThreshold = $f; + } + + function setPlaceID($iPlaceID) { $this->iPlaceID = $iPlaceID; @@ -219,5 +269,110 @@ return $aAddress; } + + + // returns an array which will contain the keys + // aBoundingBox + // and may also contain one or more of the keys + // asgeojson + // askml + // assvg + // astext + // lat + // lon + function getOutlines($iPlaceID, $fLon=null, $fLat=null, $fRadius=null) + { + + $aOutlineResult = array(); + if (!$iPlaceID) return $aOutlineResult; + + if (CONST_Search_AreaPolygons) + { + // Get the bounding box and outline polygon + $sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,"; + $sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,"; + $sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,"; + $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon"; + if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson"; + if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml"; + if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; + if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext"; + $sFrom = " from placex where place_id = ".$iPlaceID; + if ($this->fPolygonSimplificationThreshold > 0) + { + $sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx"; + } + else + { + $sSQL .= $sFrom; + } + + $aPointPolygon = $this->oDB->getRow($sSQL); + if (PEAR::IsError($aPointPolygon)) + { + echo var_dump($aPointPolygon); + failInternalError("Could not get outline.", $sSQL, $aPointPolygon); + } + + if ($aPointPolygon['place_id']) + { + if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null ) + { + $aOutlineResult['lat'] = $aPointPolygon['centrelat']; + $aOutlineResult['lon'] = $aPointPolygon['centrelon']; + } + + if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson']; + if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml']; + if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg']; + if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext']; + if ($this->bIncludePolygonAsPoints) $aOutlineResult['aPolyPoints'] = geometryText2Points($aPointPolygon['astext'], $fRadius); + + + if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) + { + $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; + $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; + } + if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) + { + $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; + $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; + } + + $aOutlineResult['aBoundingBox'] = array( + (string)$aPointPolygon['minlat'], + (string)$aPointPolygon['maxlat'], + (string)$aPointPolygon['minlon'], + (string)$aPointPolygon['maxlon'] + ); + } + } // CONST_Search_AreaPolygons + + // as a fallback we generate a bounding box without knowing the size of the geometry + if ( (!isset($aOutlineResult['aBoundingBox'])) && isset($fLon) ) + { + + if ($this->bIncludePolygonAsPoints) + { + $sGeometryText = 'POINT('.$fLon.','.$fLat.')'; + $aOutlineResult['aPolyPoints'] = geometryText2Points($sGeometryText, $fRadius); + } + + $aBounds = array(); + $aBounds['minlat'] = $fLat - $fRadius; + $aBounds['maxlat'] = $fLat + $fRadius; + $aBounds['minlon'] = $fLon - $fRadius; + $aBounds['maxlon'] = $fLon + $fRadius; + + $aOutlineResult['aBoundingBox'] = array( + (string)$aBounds['minlat'], + (string)$aBounds['maxlat'], + (string)$aBounds['minlon'], + (string)$aBounds['maxlon'] + ); + } + return $aOutlineResult; + } } ?> diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index e40ce6cc..d9652764 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -9,6 +9,14 @@ protected $aLangPrefOrder = array(); + protected $bIncludePolygonAsPoints = false; + protected $bIncludePolygonAsText = false; + protected $bIncludePolygonAsGeoJSON = false; + protected $bIncludePolygonAsKML = false; + protected $bIncludePolygonAsSVG = false; + protected $fPolygonSimplificationThreshold = 0.0; + + function ReverseGeocode(&$oDB) { $this->oDB =& $oDB; @@ -58,6 +66,48 @@ $this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28; } + function setIncludePolygonAsPoints($b = true) + { + $this->bIncludePolygonAsPoints = $b; + } + + function getIncludePolygonAsPoints() + { + return $this->bIncludePolygonAsPoints; + } + + function setIncludePolygonAsText($b = true) + { + $this->bIncludePolygonAsText = $b; + } + + function getIncludePolygonAsText() + { + return $this->bIncludePolygonAsText; + } + + function setIncludePolygonAsGeoJSON($b = true) + { + $this->bIncludePolygonAsGeoJSON = $b; + } + + function setIncludePolygonAsKML($b = true) + { + $this->bIncludePolygonAsKML = $b; + } + + function setIncludePolygonAsSVG($b = true) + { + $this->bIncludePolygonAsSVG = $b; + } + + function setPolygonSimplificationThreshold($f) + { + $this->fPolygonSimplificationThreshold = $f; + } + + // returns { place_id =>, type => '(osm|tiger)' } + // fails if no place was found function lookup() { $sPointSQL = 'ST_SetSRID(ST_Point('.$this->fLon.','.$this->fLat.'),4326)'; @@ -86,7 +136,8 @@ if ($fSearchDiam > 0.008 && $iMaxRank > 22) $iMaxRank = 22; if ($fSearchDiam > 0.001 && $iMaxRank > 26) $iMaxRank = 26; - $sSQL = 'select place_id,parent_place_id,rank_search,calculated_country_code from placex'; + $sSQL = 'select place_id,parent_place_id,rank_search,calculated_country_code'; + $sSQL .= ' FROM placex'; $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; $sSQL .= ' and rank_search != 28 and rank_search >= '.$iMaxRank; $sSQL .= ' and (name is not null or housenumber is not null)'; @@ -152,7 +203,11 @@ { $iPlaceID = $iParentPlaceID; } - $sSQL = "select address_place_id from place_addressline where place_id = $iPlaceID order by abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc limit 1"; + $sSQL = 'select address_place_id'; + $sSQL .= ' FROM place_addressline'; + $sSQL .= " WHERE place_id = $iPlaceID"; + $sSQL .= " ORDER BY abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc"; + $sSQL .= ' LIMIT 1'; $iPlaceID = $this->oDB->getOne($sSQL); if (PEAR::IsError($iPlaceID)) { @@ -165,7 +220,8 @@ } return array('place_id' => $iPlaceID, - 'type' => $bPlaceIsTiger ? 'tiger' : 'osm'); + 'type' => $bPlaceIsTiger ? 'tiger' : 'osm'); } + } ?> diff --git a/lib/lib.php b/lib/lib.php index e81d85be..51bf7ebb 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -673,6 +673,31 @@ return $aOrders; } + function getResultDiameter($aResult) + { + $aClassType = getClassTypes(); + + $fDiameter = 0.0001; + + if (isset($aResult['class']) + && isset($aResult['type']) + && isset($aResult['admin_level']) + && isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) + && $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']) + { + $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter']; + } + elseif (isset($aResult['class']) + && isset($aResult['type']) + && isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) + && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']) + { + $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter']; + } + + return $fDiameter; + } + function javascript_renderData($xVal, $iOptions = 0) { @@ -1024,27 +1049,47 @@ } - - function geometryText2Points($geometry_as_text,$fRadius) + function geometryText2Points($geometry_as_text, $fRadius) { $aPolyPoints = NULL; - if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch)) + if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) { - preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER); + preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); } - elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch)) + elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) { - preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER); + preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); } - elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$geometry_as_text,$aMatch)) + elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) { + preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER); + } + elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#', $geometry_as_text, $aMatch)) + { + $aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius); + } + + if (isset($aPolyPoints)) + { + $aResultPoints = array(); + foreach($aPolyPoints as $aPoint) + { + $aResultPoints[] = array($aPoint[1], $aPoint[2]); + } + return $aResultPoints; + } + + return; + } + + function createPointsAroundCenter($fLon, $fLat, $fRadius) + { $iSteps = max(8, min(100, ($fRadius * 40000)^2)); $fStepSize = (2*pi())/$iSteps; $aPolyPoints = array(); for($f = 0; $f < 2*pi(); $f += $fStepSize) { - $aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f))); + $aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) ); } - } - return $aPolyPoints; + return $aPolyPoints; } diff --git a/lib/template/address-json.php b/lib/template/address-json.php index d1edaf0d..6fd101bb 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -24,6 +24,38 @@ if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress']; if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; + + if (isset($aPlace['aBoundingBox'])) + { + $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox']; + + if (isset($aPlace['aPolyPoints']) && $bAsPoints) + { + $aFilteredPlaces['polygonpoints'] = $aPlace['aPolyPoints']; + } + } + + if (isset($aPlace['asgeojson'])) + { + $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']); + } + + if (isset($aPlace['assvg'])) + { + $aFilteredPlaces['svg'] = $aPlace['assvg']; + } + + if (isset($aPlace['astext'])) + { + $aFilteredPlaces['geotext'] = $aPlace['astext']; + } + + if (isset($aPlace['askml'])) + { + $aFilteredPlaces['geokml'] = $aPlace['askml']; + } + + } javascript_renderData($aFilteredPlaces); diff --git a/lib/template/address-jsonv2.php b/lib/template/address-jsonv2.php index 40c5c56d..89403875 100644 --- a/lib/template/address-jsonv2.php +++ b/lib/template/address-jsonv2.php @@ -36,6 +36,37 @@ if (isset($aPlace['aAddress'])) $aFilteredPlaces['address'] = $aPlace['aAddress']; if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; + + if (isset($aPlace['aBoundingBox'])) + { + $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox']; + + if (isset($aPlace['aPolyPoints']) && $bAsPoints) + { + $aFilteredPlaces['polygonpoints'] = $aPlace['aPolyPoints']; + } + } + + if (isset($aPlace['asgeojson'])) + { + $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']); + } + + if (isset($aPlace['assvg'])) + { + $aFilteredPlaces['svg'] = $aPlace['assvg']; + } + + if (isset($aPlace['astext'])) + { + $aFilteredPlaces['geotext'] = $aPlace['astext']; + } + + if (isset($aPlace['askml'])) + { + $aFilteredPlaces['geokml'] = $aPlace['askml']; + } + } javascript_renderData($aFilteredPlaces); diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index 39d9a147..109e66a1 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -27,6 +27,40 @@ if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"'; if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"'; if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"'; + if (isset($aPlace['aBoundingBox'])) + { + echo ' boundingbox="'; + echo join(',', $aPlace['aBoundingBox']); + echo '"'; + + if ($bAsPoints && isset($aPlace['aPolyPoints'])) + { + echo ' polygonpoints=\''; + echo json_encode($aPlace['aPolyPoints']); + echo '\''; + } + } + + if (isset($aPlace['asgeojson'])) + { + echo ' geojson=\''; + echo $aPlace['asgeojson']; + echo '\''; + } + + if (isset($aPlace['assvg'])) + { + echo ' geosvg=\''; + echo $aPlace['assvg']; + echo '\''; + } + + if (isset($aPlace['astext'])) + { + echo ' geotext=\''; + echo $aPlace['astext']; + echo '\''; + } echo ">".htmlspecialchars($aPlace['langaddress']).""; if (isset($aPlace['aAddress'])) @@ -63,6 +97,14 @@ } echo ""; } + + if (isset($aPlace['askml'])) + { + echo "\n"; + echo $aPlace['askml']; + echo ""; + } + } echo ""; diff --git a/lib/template/details-html.php b/lib/template/details-html.php index 404450c0..3e9e39d7 100644 --- a/lib/template/details-html.php +++ b/lib/template/details-html.php @@ -121,7 +121,7 @@ echo $keyword_token; if (isset($word_id)) { - echo '('.$word_id.')'; + echo 'word id: '.$word_id; } echo "\n"; } @@ -222,7 +222,7 @@ headline('Name Keywords'); foreach($aPlaceSearchNameKeywords as $aRow) { - _one_keyword_row($aRow['word_token']); + _one_keyword_row($aRow['word_token'], $aRow['word_id']); } } diff --git a/lib/template/includes/html-top-navigation.php b/lib/template/includes/html-top-navigation.php index 61bec19a..d72fcb7c 100644 --- a/lib/template/includes/html-top-navigation.php +++ b/lib/template/includes/html-top-navigation.php @@ -9,7 +9,7 @@
- + Data last updated:
diff --git a/lib/template/search-json.php b/lib/template/search-json.php index 5f29fdfb..fc50ee0e 100644 --- a/lib/template/search-json.php +++ b/lib/template/search-json.php @@ -18,11 +18,7 @@ if (isset($aPointDetails['aBoundingBox'])) { - $aPlace['boundingbox'] = array( - $aPointDetails['aBoundingBox'][0], - $aPointDetails['aBoundingBox'][1], - $aPointDetails['aBoundingBox'][2], - $aPointDetails['aBoundingBox'][3]); + $aPlace['boundingbox'] = $aPointDetails['aBoundingBox']; if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) { diff --git a/lib/template/search-jsonv2.php b/lib/template/search-jsonv2.php index 66098d30..773cfd96 100644 --- a/lib/template/search-jsonv2.php +++ b/lib/template/search-jsonv2.php @@ -16,11 +16,7 @@ if (isset($aPointDetails['aBoundingBox'])) { - $aPlace['boundingbox'] = array( - $aPointDetails['aBoundingBox'][0], - $aPointDetails['aBoundingBox'][1], - $aPointDetails['aBoundingBox'][2], - $aPointDetails['aBoundingBox'][3]); + $aPlace['boundingbox'] = $aPointDetails['aBoundingBox']; if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) { diff --git a/lib/template/search-xml.php b/lib/template/search-xml.php index b61ff22f..6a382ebf 100644 --- a/lib/template/search-xml.php +++ b/lib/template/search-xml.php @@ -36,10 +36,7 @@ if (isset($aResult['aBoundingBox'])) { echo ' boundingbox="'; - echo $aResult['aBoundingBox'][0]; - echo ','.$aResult['aBoundingBox'][1]; - echo ','.$aResult['aBoundingBox'][2]; - echo ','.$aResult['aBoundingBox'][3]; + echo join(',',$aResult['aBoundingBox']); echo '"'; if ($bShowPolygons && isset($aResult['aPolyPoints'])) diff --git a/tests-php/Nominatim/NominatimTest.php b/tests-php/Nominatim/NominatimTest.php index 129fa012..d50a8da4 100644 --- a/tests-php/Nominatim/NominatimTest.php +++ b/tests-php/Nominatim/NominatimTest.php @@ -12,6 +12,51 @@ class NominatimTest extends \PHPUnit_Framework_TestCase } + public function test_getClassTypesWithImportance() + { + $aClasses = getClassTypesWithImportance(); + + $this->assertGreaterThan( + 200, + count($aClasses) + ); + + $this->assertEquals( + array( + 'label' => "Country", + 'frequency' => 0, + 'icon' => "poi_boundary_administrative", + 'defzoom' => 6, + 'defdiameter' => 15, + 'importance' => 3 + ), + $aClasses['place:country'] + ); + } + + + public function test_getResultDiameter() + { + $aResult = array(); + $this->assertEquals( + 0.0001, + getResultDiameter($aResult) + ); + + $aResult = array('class' => 'place', 'type' => 'country'); + $this->assertEquals( + 15, + getResultDiameter($aResult) + ); + + $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6); + $this->assertEquals( + 0.32, + getResultDiameter($aResult) + ); + } + + public function test_addQuotes() { // FIXME: not quoting existing quote signs is probably a bug @@ -142,36 +187,48 @@ class NominatimTest extends \PHPUnit_Framework_TestCase 65536, count( getWordSets(array_fill( 0, 18, 'a'),0) ) ); - } + // you might say we're creating a circle + public function test_createPointsAroundCenter() + { + $aPoints = createPointsAroundCenter(0, 0, 2); + $this->assertEquals( + 101, + count($aPoints) + ); + $this->assertEquals( + array( + ['', 0, 2], + ['', 0.12558103905863, 1.9960534568565], + ['', 0.25066646712861, 1.984229402629] + ), + array_splice($aPoints, 0, 3) + ); + } public function test_geometryText2Points() { $fRadius = 1; - // invalid value $this->assertEquals( NULL, geometryText2Points('', $fRadius) ); - // POINT $aPoints = geometryText2Points('POINT(10 20)', $fRadius); $this->assertEquals( 101, count($aPoints) ); - $this->assertEquals( - - array( - ['', 10, 21], - ['', 10.062790519529, 20.998026728428], - ['', 10.125333233564, 20.992114701314] + array( + [10, 21], + [10.062790519529, 20.998026728428], + [10.125333233564, 20.992114701314] ), array_splice($aPoints, 0,3) ); @@ -179,35 +236,25 @@ class NominatimTest extends \PHPUnit_Framework_TestCase // POLYGON $this->assertEquals( array( - ['30 10', '30', '10'], - ['40 40', '40', '40'], - ['20 40', '20', '40'], - ['10 20', '10', '20'], - ['30 10', '30', '10'] + ['30', '10'], + ['40', '40'], + ['20', '40'], + ['10', '20'], + ['30', '10'] ), geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius) ); // MULTIPOLYGON - // only the first polygon is used $this->assertEquals( array( - ['30 20', '30', '20'], - ['45 40', '45', '40'], - ['10 40', '10', '40'], - ['30 20', '30', '20'], - - // ['15 5' , '15', '5' ], - // ['45 10', '45', '10'], - // ['10 20', '10', '20'], - // ['5 10' , '5' , '10'], - // ['15 5' , '15', '5' ] + ['30', '20'], // first polygon only + ['45', '40'], + ['10', '40'], + ['30', '20'], ), geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius) ); - - } - } diff --git a/tests/features/api/reverse.feature b/tests/features/api/reverse.feature index fa636acf..39519177 100644 --- a/tests/features/api/reverse.feature +++ b/tests/features/api/reverse.feature @@ -11,6 +11,15 @@ Feature: Reverse geocoding | ID | country | 0 | Deutschland + + Scenario: Boundingbox is returned + Given the request parameters + | format | zoom + | xml | 4 + When looking up coordinates 53.9788769,13.0830313 + And results contain valid boundingboxes + + @Tiger Scenario: TIGER house number Given the request parameters @@ -61,3 +70,75 @@ Feature: Reverse geocoding | xml | json | jsonv2 + + + Scenario Outline: Reverse Geocoding contains TEXT geometry + Given the request parameters + | polygon_text + | 1 + When looking up coordinates 48.86093,2.2978 + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geotext + | json | geotext + | jsonv2 | geotext + + Scenario Outline: Reverse Geocoding contains polygon-as-points geometry + Given the request parameters + | polygon + | 1 + When looking up coordinates 48.86093,2.2978 + Then result 0 has not attributes + + Examples: + | format | response_attribute + | xml | polygonpoints + | json | polygonpoints + | jsonv2 | polygonpoints + + + + Scenario Outline: Reverse Geocoding contains SVG geometry + Given the request parameters + | polygon_svg + | 1 + When looking up coordinates 48.86093,2.2978 + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geosvg + | json | svg + | jsonv2 | svg + + + Scenario Outline: Reverse Geocoding contains KML geometry + Given the request parameters + | polygon_kml + | 1 + When looking up coordinates 48.86093,2.2978 + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geokml + | json | geokml + | jsonv2 | geokml + + + Scenario Outline: Reverse Geocoding contains GEOJSON geometry + Given the request parameters + | polygon_geojson + | 1 + When looking up coordinates 48.86093,2.2978 + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geojson + | json | geojson + | jsonv2 | geojson + + diff --git a/tests/features/api/reverse_simple.feature b/tests/features/api/reverse_simple.feature index 8621ec65..5d79fd4b 100644 --- a/tests/features/api/reverse_simple.feature +++ b/tests/features/api/reverse_simple.feature @@ -17,6 +17,49 @@ Feature: Simple Reverse Tests | -79.34 | 23.5 | 0.23 | -178.555 + Scenario Outline: Testing different parameters + Given the request parameters + | + | + When sending search query "Manchester" + Then the result is valid html + Given the request parameters + | + | + When sending html search query "Manchester" + Then the result is valid html + Given the request parameters + | + | + When sending xml search query "Manchester" + Then the result is valid xml + Given the request parameters + | + | + When sending json search query "Manchester" + Then the result is valid json + Given the request parameters + | + | + When sending jsonv2 search query "Manchester" + Then the result is valid json + + Examples: + | parameter | value + | polygon | 1 + | polygon | 0 + | polygon_text | 1 + | polygon_text | 0 + | polygon_kml | 1 + | polygon_kml | 0 + | polygon_geojson | 1 + | polygon_geojson | 0 + | polygon_svg | 1 + | polygon_svg | 0 + + + + Scenario Outline: Wrapping of legal jsonp requests Given the request parameters | json_callback diff --git a/tests/features/api/search_params.feature b/tests/features/api/search_params.feature index 7099c72f..150d6bdc 100644 --- a/tests/features/api/search_params.feature +++ b/tests/features/api/search_params.feature @@ -8,6 +8,7 @@ Feature: Search queries And result 0 has attributes lat,lon,display_name And result 0 has attributes class,type,importance,icon And result 0 has not attributes address + And results contain valid boundingboxes Scenario: Simple JSON search When sending json search query "Vaduz" @@ -15,6 +16,7 @@ Feature: Search queries And result 0 has attributes osm_type,osm_id,boundingbox And result 0 has attributes lat,lon,display_name,importance And result 0 has not attributes address + And results contain valid boundingboxes Scenario: JSON search with addressdetails When sending json search query "Montevideo" with address @@ -230,3 +232,73 @@ Feature: Search queries | xml | json | jsonv2 + + + Scenario Outline: Search result with contains TEXT geometry + Given the request parameters + | polygon_text + | 1 + When sending search query "switzerland" + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geotext + | json | geotext + | jsonv2 | geotext + + Scenario Outline: Search result contains polygon-as-points geometry + Given the request parameters + | polygon + | 1 + When sending search query "switzerland" + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | polygonpoints + | json | polygonpoints + | jsonv2 | polygonpoints + + + + Scenario Outline: Search result contains SVG geometry + Given the request parameters + | polygon_svg + | 1 + When sending search query "switzerland" + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geosvg + | json | svg + | jsonv2 | svg + + + Scenario Outline: Search result contains KML geometry + Given the request parameters + | polygon_kml + | 1 + When sending search query "switzerland" + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geokml + | json | geokml + | jsonv2 | geokml + + + Scenario Outline: Search result contains GEOJSON geometry + Given the request parameters + | polygon_geojson + | 1 + When sending search query "switzerland" + Then result 0 has attributes + + Examples: + | format | response_attribute + | xml | geojson + | json | geojson + | jsonv2 | geojson diff --git a/tests/steps/api_result.py b/tests/steps/api_result.py index 4910c157..2644d4a2 100644 --- a/tests/steps/api_result.py +++ b/tests/steps/api_result.py @@ -98,6 +98,8 @@ def _parse_xml(): attrs = dict(tag.attributes.items()) assert_in('desc', attrs) world.results[0]['namedetails'][attrs['desc']] = tag.firstChild.nodeValue.strip() + elif node.nodeName == "geokml": + world.results[0]['geokml'] = node elif node.nodeName == "#text": pass else: @@ -209,6 +211,15 @@ def api_result_contains(step): m = re.match("%s$" % (v,), curres[k]) assert_is_not_none(m, msg="field %s does not match: %s$ != %s." % (k, v, curres[k])) +@step(u'results contain valid boundingboxes$') +def api_result_address_contains(step): + step.given('the result is valid') + for curres in world.results: + bb = curres['boundingbox'] + if world.response_format == 'json': + bb = ','.join(bb) + m = re.match('^(-?\d+\.\d+),(-?\d+\.\d+),(-?\d+\.\d+),(-?\d+\.\d+)$', bb) + assert_is_not_none(m, msg="invalid boundingbox: %s." % (curres['boundingbox'])) @step(u'result addresses contain$') def api_result_address_contains(step): diff --git a/vagrant/ubuntu-trusty-php7-provision.sh b/vagrant/ubuntu-trusty-php7-provision.sh new file mode 100755 index 00000000..6ea19a37 --- /dev/null +++ b/vagrant/ubuntu-trusty-php7-provision.sh @@ -0,0 +1,180 @@ +#!/bin/bash + +# This script sets up a Nominatim installation on a Ubuntu box. +# +# For more detailed installation instructions see also +# http://wiki.openstreetmap.org/wiki/Nominatim/Installation + +## Part 1: System preparation + +## During 'vagrant provision' this script runs as root and the current +## directory is '/root' +USERNAME=vagrant + +### +### maybe create ubuntu user +### + +# if [[ ! `id -u $USERNAME` ]]; then +# useradd $USERNAME --create-home --shell /bin/bash +# +# # give sudo power +# echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-$USERNAME-user +# chmod 0440 /etc/sudoers.d/99-$USERNAME-user +# service sudo restart +# +# # add basic .profile +# cp -r .ssh .profile .bashrc /home/$USERNAME/ +# chown -R $USERNAME /home/$USERNAME/.* +# chgrp -R $USERNAME /home/$USERNAME/.* +# +# # now ideally login as $USERNAME and continue +# su $USERNAME -l +# fi + + +sudo apt-get update -qq +sudo apt-get upgrade -y +sudo apt-get install -y build-essential libgeos-dev libpq-dev libbz2-dev \ + libtool automake libproj-dev libboost-dev libboost-system-dev \ + libboost-filesystem-dev libboost-thread-dev libexpat-dev +sudo apt-get autoremove -y + +# get arrow-keys working in terminal (e.g. editing in vi) +echo 'stty sane' >> ~/.bash_profile +echo 'export TERM=linux' >> ~/.bash_profile +source ~/.bash_profile + + +### +### PostgreSQL 9.3 + PostGIS 2.1 +### + +sudo apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib-9.3 postgresql-server-dev-9.3 +# already included: proj-bin libgeos-dev + +# make sure OS-authenticated users (e.g. $USERNAME) can access +sudo sed -i "s/ident/trust/" /etc/postgresql/9.3/main/pg_hba.conf +sudo sed -i "s/md5/trust/" /etc/postgresql/9.3/main/pg_hba.conf +sudo sed -i "s/peer/trust/" /etc/postgresql/9.3/main/pg_hba.conf +sudo /etc/init.d/postgresql restart + +# creates the role +sudo -u postgres createuser -s $USERNAME + + + +### +### PHP for frontend +### +sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php +sudo apt-get update -qq +sudo apt-get install -y apache2 +sudo apt-get install -y php7.0 php7.0-pgsql php7.0-fpm libapache2-mod-php7.0 php-pear php-db + + +# get rid of some warning +# where is the ini file? 'php --ini' +echo "date.timezone = 'Etc/UTC'" | sudo tee /etc/php/7.0/cli/conf.d/99-timezone.ini > /dev/null + + + +### +### Nominatim +### +sudo apt-get install -y libgeos-c1 libgeos++-dev libxml2-dev + +## Part 2: Nominatim installaion + +# now ideally login as $USERNAME and continue +cd /home/$USERNAME + +# If the Nominatim source is not being shared with the host, check out source. +if [ ! -d "Nominatim" ]; then + sudo apt-get install -y git + sudo -u $USERNAME git clone --recursive https://github.com/twain47/Nominatim.git +fi + +cd Nominatim + +sudo -u $USERNAME ./autogen.sh +sudo -u $USERNAME ./configure +sudo -u $USERNAME make +chmod +x ./ +chmod +x ./module + + +LOCALSETTINGS_FILE='settings/local.php' +if [[ -e "$LOCALSETTINGS_FILE" ]]; then + echo "$LOCALSETTINGS_FILE already exist, writing to settings/local-vagrant.php instead." + LOCALSETTINGS_FILE='settings/local-vagrant.php' +fi + +# IP=`curl -s http://bot.whatismyipaddress.com` +IP=localhost +echo " $LOCALSETTINGS_FILE + + + + + + + +### +### Setup Apache/website +### + +sudo -u postgres createuser -SDR www-data + +echo ' +Listen 8089 + + # DirectoryIndex index.html + # ErrorDocument 403 /index.html + + DocumentRoot "/var/www/" + + + Options FollowSymLinks MultiViews + AddType text/html .php + + +' | sudo tee /etc/apache2/sites-enabled/nominatim.conf > /dev/null + + +service apache2 graceful + + +mkdir -m 755 /var/www/nominatim +chown $USERNAME /var/www/nominatim +sudo -u $USERNAME ./utils/setup.php --create-website /var/www/nominatim + + +# if you get 'permission denied for relation word', then try +# GRANT usage ON SCHEMA public TO "www-data"; +# GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data"; + +## +## Test suite (Python) +## https://github.com/twain47/Nominatim/tree/master/tests +## +apt-get install -y python-dev python-pip python-Levenshtein python-shapely \ + python-psycopg2 tidy python-nose python-tidylib +pip install certifi # deals with "SNI extension to TLS is not available" warning +pip install lettuce==0.2.18 six==1.7 haversine +pip install --upgrade pip setuptools + +## Test suite (PHP) +## https://github.com/twain47/Nominatim/tree/master/tests-php +wget --quiet https://phar.phpunit.de/phpunit.phar +chmod +x phpunit.phar +mv phpunit.phar /usr/local/bin/phpunit + diff --git a/vagrant/ubuntu-trusty-provision.sh b/vagrant/ubuntu-trusty-provision.sh index ed58d2e0..8e35bf7d 100755 --- a/vagrant/ubuntu-trusty-provision.sh +++ b/vagrant/ubuntu-trusty-provision.sh @@ -147,7 +147,7 @@ Listen 8089 ' | sudo tee /etc/apache2/sites-enabled/nominatim.conf > /dev/null -apache2ctl graceful +service apache2 graceful mkdir -m 755 /var/www/nominatim diff --git a/website/details.php b/website/details.php index ad753a82..3a0fee82 100755 --- a/website/details.php +++ b/website/details.php @@ -159,7 +159,12 @@ logEnd($oDB, $hLog, 1); - $sTileURL = CONST_Map_Tile_URL; - $sTileAttribution = CONST_Map_Tile_Attribution; + if ($sOutputFormat=='html') + { + $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"); + $sTileURL = CONST_Map_Tile_URL; + $sTileAttribution = CONST_Map_Tile_Attribution; + } + include(CONST_BasePath.'/lib/template/details-'.$sOutputFormat.'.php'); diff --git a/website/reverse.php b/website/reverse.php index e2dfaef8..3254e710 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -18,6 +18,36 @@ } } + + $bAsPoints = false; + $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson']; + $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml']; + $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg']; + $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text']; + if ( ( ($bAsGeoJSON?1:0) + + ($bAsKML?1:0) + + ($bAsSVG?1:0) + + ($bAsText?1:0) + + ($bAsPoints?1:0) + ) > CONST_PolygonOutput_MaximumTypes) + { + if (CONST_PolygonOutput_MaximumTypes) + { + userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option"); + } + else + { + userError("Polygon output is disabled"); + } + exit; + } + + + // Polygon simplification threshold (optional) + $fThreshold = 0.0; + if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold']; + + $oDB =& getDB(); ini_set('memory_limit', '200M'); @@ -63,6 +93,21 @@ $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false)); $aPlace = $oPlaceLookup->lookupPlace($aLookup); + + $oPlaceLookup->setIncludePolygonAsPoints($bAsPoints); + $oPlaceLookup->setIncludePolygonAsText($bAsText); + $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON); + $oPlaceLookup->setIncludePolygonAsKML($bAsKML); + $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG); + $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold); + + $fRadius = $fDiameter = getResultDiameter($aPlace); + $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius); + + if ($aOutlineResult) + { + $aPlace = array_merge($aPlace, $aOutlineResult); + } } else { @@ -76,6 +121,10 @@ exit; } - $sTileURL = CONST_Map_Tile_URL; - $sTileAttribution = CONST_Map_Tile_Attribution; + if ($sOutputFormat=='html') + { + $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"); + $sTileURL = CONST_Map_Tile_URL; + $sTileAttribution = CONST_Map_Tile_Attribution; + } include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php'); diff --git a/website/search.php b/website/search.php index f2c327c0..ac0b4bdd 100755 --- a/website/search.php +++ b/website/search.php @@ -13,10 +13,8 @@ $fLat = CONST_Default_Lat; $fLon = CONST_Default_Lon; $iZoom = CONST_Default_Zoom; - $sTileURL = CONST_Map_Tile_URL; - $sTileAttribution = CONST_Map_Tile_Attribution; - $oGeocode =& new Geocode($oDB); + $oGeocode = new Geocode($oDB); $aLangPrefOrder = getPreferredLanguages(); $oGeocode->setLanguagePreference($aLangPrefOrder); @@ -99,17 +97,17 @@ { if (!(isset($_GET['q']) && $_GET['q']) && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') { - $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1); + $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1); - // reverse order of '/' separated string - $aPhrases = explode('/', $sQuery); - $aPhrases = array_reverse($aPhrases); - $sQuery = join(', ',$aPhrases); - $oGeocode->setQuery($sQuery); + // reverse order of '/' separated string + $aPhrases = explode('/', $sQuery); + $aPhrases = array_reverse($aPhrases); + $sQuery = join(', ',$aPhrases); + $oGeocode->setQuery($sQuery); } else { - $oGeocode->setQueryFromParams($_GET); + $oGeocode->setQueryFromParams($_GET); } } @@ -118,8 +116,12 @@ $aSearchResults = $oGeocode->lookup(); if ($aSearchResults === false) $aSearchResults = array(); - $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"); - + if ($sOutputFormat=='html') + { + $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"); + $sTileURL = CONST_Map_Tile_URL; + $sTileAttribution = CONST_Map_Tile_Attribution; + } logEnd($oDB, $hLog, sizeof($aSearchResults)); $bAsText = $oGeocode->getIncludePolygonAsText();