diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php index 8a1a366678..79ce4b658d 100644 --- a/lib/PlaceLookup.php +++ b/lib/PlaceLookup.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/AddressDetails.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once CONST_BasePath.'/lib/AddressDetails.php'; +require_once CONST_BasePath.'/lib/Result.php'; class PlaceLookup { @@ -26,6 +26,9 @@ class PlaceLookup protected $sAllowedTypesSQLList = null; protected $bDeDupe = true; + protected $aLicence = 'Data © OpenStreetMap contributors, ODbL 1.0.'; + protected $aCopyright = 'https://osm.org/copyright'; + public function __construct(&$oDB) { @@ -89,9 +92,15 @@ public function getMoreUrlParams() { $aParams = array(); - if ($this->bAddressDetails) $aParams['addressdetails'] = '1'; - if ($this->bExtraTags) $aParams['extratags'] = '1'; - if ($this->bNameDetails) $aParams['namedetails'] = '1'; + if ($this->bAddressDetails) { + $aParams['addressdetails'] = '1'; + } + if ($this->bExtraTags) { + $aParams['extratags'] = '1'; + } + if ($this->bNameDetails) { + $aParams['namedetails'] = '1'; + } if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1'; if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1'; @@ -102,7 +111,9 @@ public function getMoreUrlParams() $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold; } - if (!$this->bDeDupe) $aParams['dedupe'] = '0'; + if (!$this->bDeDupe) { + $aParams['dedupe'] = '0'; + } return $aParams; } @@ -147,8 +158,9 @@ private function addressImportanceSql($sGeometry, $sPlaceId) private function langAddressSql($sHousenumber) { - if ($this->bAddressDetails) + if ($this->bAddressDetails) { return ''; // langaddress will be computed from address details + } return 'get_address_by_language(place_id,'.$sHousenumber.','.$this->aLangPrefOrderSql.') AS langaddress,'; } @@ -234,10 +246,15 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $sSQL .= ' housenumber,'; $sSQL .= ' country_code, '; $sSQL .= ' importance, '; - if (!$this->bDeDupe) $sSQL .= 'place_id,'; - if (!$this->bAddressDetails) $sSQL .= 'langaddress, '; + if (!$this->bDeDupe) { + $sSQL .= 'place_id,'; + } + if (!$this->bAddressDetails) { + $sSQL .= 'langaddress, '; + } $sSQL .= ' placename, '; $sSQL .= ' ref, '; + if ($this->bExtraTags) $sSQL .= 'extratags, '; if ($this->bNameDetails) $sSQL .= 'name, '; $sSQL .= ' extra_place '; @@ -260,8 +277,12 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $sSQL .= $this->langAddressSql('-1'); $sSQL .= ' postcode as placename,'; $sSQL .= ' postcode as ref,'; - if ($this->bExtraTags) $sSQL .= 'null::text AS extra,'; - if ($this->bNameDetails) $sSQL .= 'null::text AS names,'; + if ($this->bExtraTags) { + $sSQL .= 'null::text AS extra,'; + } + if ($this->bNameDetails) { + $sSQL .= 'null::text AS names,'; + } $sSQL .= ' ST_x(geometry) AS lon, ST_y(geometry) AS lat,'; $sSQL .= ' (0.75-(rank_search::float/40)) AS importance, '; $sSQL .= $this->addressImportanceSql('geometry', 'lp.parent_place_id'); @@ -298,8 +319,12 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $sSQL .= $this->langAddressSql('housenumber_for_place'); $sSQL .= ' null::text AS placename, '; $sSQL .= ' null::text AS ref, '; - if ($this->bExtraTags) $sSQL .= 'null::text AS extra,'; - if ($this->bNameDetails) $sSQL .= 'null::text AS names,'; + if ($this->bExtraTags) { + $sSQL .= 'null::text AS extra,'; + } + if ($this->bNameDetails) { + $sSQL .= 'null::text AS names,'; + } $sSQL .= ' st_x(centroid) AS lon, '; $sSQL .= ' st_y(centroid) AS lat,'; $sSQL .= ' -1.15 AS importance, '; @@ -344,8 +369,12 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $sSQL .= $this->langAddressSql('housenumber_for_place'); $sSQL .= ' null::text AS placename, '; $sSQL .= ' null::text AS ref, '; - if ($this->bExtraTags) $sSQL .= 'null::text AS extra, '; - if ($this->bNameDetails) $sSQL .= 'null::text AS names, '; + if ($this->bExtraTags) { + $sSQL .= 'null::text AS extra, '; + } + if ($this->bNameDetails) { + $sSQL .= 'null::text AS names, '; + } $sSQL .= ' st_x(centroid) AS lon, '; $sSQL .= ' st_y(centroid) AS lat, '; // slightly smaller than the importance for normal houses @@ -393,8 +422,12 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $sSQL .= $this->langAddressSql('-1'); $sSQL .= ' null::text AS placename, '; $sSQL .= ' null::text AS ref, '; - if ($this->bExtraTags) $sSQL .= 'null::text AS extra, '; - if ($this->bNameDetails) $sSQL .= 'null::text AS names, '; + if ($this->bExtraTags) { + $sSQL .= 'null::text AS extra, '; + } + if ($this->bNameDetails) { + $sSQL .= 'null::text AS names, '; + } $sSQL .= ' ST_X(centroid) AS lon, '; $sSQL .= ' ST_Y(centroid) AS lat, '; $sSQL .= ' -1.10 AS importance, '; @@ -421,6 +454,7 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) foreach ($aPlaces as &$aPlace) { $aPlace['importance'] = (float) $aPlace['importance']; + if ($this->bAddressDetails) { // to get addressdetails for tiger data, the housenumber is needed $aPlace['address'] = new AddressDetails( @@ -432,9 +466,19 @@ public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30) $aPlace['langaddress'] = $aPlace['address']->getLocaleAddress(); } + $aPlace['licence'] = ($this->aLicence); + $aPlace['copyright'] = ($this->aCopyright); + if ($this->bExtraTags) { if ($aPlace['extra']) { $aPlace['sExtraTags'] = json_decode($aPlace['extra']); + + if ($aPlace['sExtraTags']->licence) { + $aPlace['licence'] = $aPlace['sExtraTags']->data_licence; + } + if ($aPlace['sExtraTags']->copyright) { + $aPlace['copyright'] = $aPlace['sExtraTags']->data_copyright; + } } else { $aPlace['sExtraTags'] = (object) array(); } @@ -476,7 +520,9 @@ public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = nu { $aOutlineResult = array(); - if (!$iPlaceID) return $aOutlineResult; + if (!$iPlaceID) { + return $aOutlineResult; + } if (CONST_Search_AreaPolygons) { // Get the bounding box and outline polygon @@ -489,10 +535,12 @@ public function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = nu } $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) $sSQL .= ',ST_AsText(geometry) as astext'; + if ($fLonReverse != null && $fLatReverse != null) { $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; diff --git a/lib/template/address-geocodejson.php b/lib/template/address-geocodejson.php index 0066e80e29..813886130f 100644 --- a/lib/template/address-geocodejson.php +++ b/lib/template/address-geocodejson.php @@ -5,9 +5,11 @@ $aFilteredPlaces = array(); if (empty($aPlace)) { - if (isset($sError)) + if (isset($sError)) { $aFilteredPlaces['error'] = $sError; - else $aFilteredPlaces['error'] = 'Unable to geocode'; + } else { + $aFilteredPlaces['error'] = 'Unable to geocode'; + } javascript_renderData($aFilteredPlaces); } else { $aFilteredPlaces = array( @@ -17,7 +19,14 @@ ) ); - if (isset($aPlace['place_id'])) $aFilteredPlaces['properties']['geocoding']['place_id'] = $aPlace['place_id']; + if (isset($aPlace['place_id'])) { + $aFilteredPlaces['properties']['geocoding']['place_id'] = $aPlace['place_id']; + } + + $aFilteredPlaces['properties']['geocoding']['licence'] = $aPlace['licence']; + + $aFilteredPlaces['properties']['geocoding']['copyright'] = $aPlace['copyright']; + $sOSMType = formatOSMType($aPlace['osm_type']); if ($sOSMType) { $aFilteredPlaces['properties']['geocoding']['osm_type'] = $sOSMType; @@ -55,14 +64,16 @@ ); } - javascript_renderData(array( - 'type' => 'FeatureCollection', - 'geocoding' => array( - 'version' => '0.1.0', - 'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', - 'licence' => 'ODbL', - 'query' => $sQuery + javascript_renderData( + array( + 'type' => 'FeatureCollection', + 'geocoding' => array( + 'version' => '0.1.0', + // 'attribution' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', + // 'licence' => 'ODbL', + 'query' => $sQuery ), - 'features' => array($aFilteredPlaces) - )); + 'features' => array($aFilteredPlaces) + ) + ); } diff --git a/lib/template/address-geojson.php b/lib/template/address-geojson.php index 089a86b683..a48302e472 100644 --- a/lib/template/address-geojson.php +++ b/lib/template/address-geojson.php @@ -3,9 +3,11 @@ $aFilteredPlaces = array(); if (empty($aPlace)) { - if (isset($sError)) + if (isset($sError)) { $aFilteredPlaces['error'] = $sError; - else $aFilteredPlaces['error'] = 'Unable to geocode'; + } else { + $aFilteredPlaces['error'] = 'Unable to geocode'; + } javascript_renderData($aFilteredPlaces); } else { $aFilteredPlaces = array( @@ -13,7 +15,14 @@ 'properties' => array() ); - if (isset($aPlace['place_id'])) $aFilteredPlaces['properties']['place_id'] = $aPlace['place_id']; + if (isset($aPlace['place_id'])) { + $aFilteredPlaces['properties']['place_id'] = $aPlace['place_id']; + } + + $aFilteredPlaces['properties']['licence'] = $aPlace['licence']; + + $aFilteredPlaces['properties']['copyright'] = $aPlace['copyright']; + $sOSMType = formatOSMType($aPlace['osm_type']); if ($sOSMType) { $aFilteredPlaces['properties']['osm_type'] = $sOSMType; @@ -36,8 +45,12 @@ if (isset($aPlace['address'])) { $aFilteredPlaces['properties']['address'] = $aPlace['address']->getAddressNames(); } - if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags']; - if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails']; + if (isset($aPlace['sExtraTags'])) { + $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags']; + } + if (isset($aPlace['sNameDetails'])) { + $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails']; + } if (isset($aPlace['aBoundingBox'])) { $aFilteredPlaces['bbox'] = array( @@ -61,9 +74,11 @@ } - javascript_renderData(array( - 'type' => 'FeatureCollection', - 'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', - 'features' => array($aFilteredPlaces) - )); + javascript_renderData( + array( + 'type' => 'FeatureCollection', + // 'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', + 'features' => array($aFilteredPlaces) + ) + ); } diff --git a/lib/template/address-json.php b/lib/template/address-json.php index 691d6a749f..f1f177d54d 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -3,19 +3,30 @@ $aFilteredPlaces = array(); if (empty($aPlace)) { - if (isset($sError)) + if (isset($sError)) { $aFilteredPlaces['error'] = $sError; - else $aFilteredPlaces['error'] = 'Unable to geocode'; + } else { + $aFilteredPlaces['error'] = 'Unable to geocode'; + } } else { - if (isset($aPlace['place_id'])) $aFilteredPlaces['place_id'] = $aPlace['place_id']; - $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright'; + if (isset($aPlace['place_id'])) { + $aFilteredPlaces['place_id'] = $aPlace['place_id']; + } + // $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright'; + $aFilteredPlaces['licence'] = $aPlace['licence']; + $aFilteredPlaces['copyright'] = $aPlace['copyright']; + $sOSMType = formatOSMType($aPlace['osm_type']); if ($sOSMType) { $aFilteredPlaces['osm_type'] = $sOSMType; $aFilteredPlaces['osm_id'] = $aPlace['osm_id']; } - if (isset($aPlace['lat'])) $aFilteredPlaces['lat'] = $aPlace['lat']; - if (isset($aPlace['lon'])) $aFilteredPlaces['lon'] = $aPlace['lon']; + if (isset($aPlace['lat'])) { + $aFilteredPlaces['lat'] = $aPlace['lat']; + } + if (isset($aPlace['lon'])) { + $aFilteredPlaces['lon'] = $aPlace['lon']; + } if ($sOutputFormat == 'jsonv2' || $sOutputFormat == 'geojson') { $aFilteredPlaces['place_rank'] = $aPlace['rank_search']; @@ -35,8 +46,12 @@ if (isset($aPlace['address'])) { $aFilteredPlaces['address'] = $aPlace['address']->getAddressNames(); } - if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; - if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; + if (isset($aPlace['sExtraTags'])) { + $aFilteredPlaces['extratags'] = $aPlace['sExtraTags']; + } + if (isset($aPlace['sNameDetails'])) { + $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails']; + } if (isset($aPlace['aBoundingBox'])) { $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox']; diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index a17da73821..509b984ce1 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -7,22 +7,36 @@ echo '\n"; if (empty($aPlace)) { - if (isset($sError)) + if (isset($sError)) { echo "$sError"; - else echo 'Unable to geocode'; + } else { + echo 'Unable to geocode'; + } } else { echo ' $aResult) { echo "