X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/25baaf530dea28b7cf3c72ba4e83f3ebed05629f..b00d16fd7d41b41eb41128fdc4866dd3d7a67a95:/lib/PlaceLookup.php
diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php
index 9e19db90..fce49701 100644
--- a/lib/PlaceLookup.php
+++ b/lib/PlaceLookup.php
@@ -52,7 +52,7 @@ class PlaceLookup
{
$aLangs = $oParams->getPreferredLanguages();
$this->aLangPrefOrderSql =
- 'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
+ 'ARRAY['.join(',', $this->oDB->getDBQuotedList($aLangs)).']';
$this->bExtraTags = $oParams->getBool('extratags', false);
$this->bNameDetails = $oParams->getBool('namedetails', false);
@@ -132,8 +132,9 @@ class PlaceLookup
public function setLanguagePreference($aLangPrefOrder)
{
- $this->aLangPrefOrderSql =
- 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
+ $this->aLangPrefOrderSql = $this->oDB->getArraySQL(
+ $this->oDB->getDBQuotedList($aLangPrefOrder)
+ );
}
private function addressImportanceSql($sGeometry, $sPlaceId)
@@ -162,8 +163,8 @@ class PlaceLookup
public function lookupOSMID($sType, $iID)
{
- $sSQL = "select place_id from placex where osm_type = '".$sType."' and osm_id = ".$iID;
- $iPlaceID = chksql($this->oDB->getOne($sSQL));
+ $sSQL = 'select place_id from placex where osm_type = :type and osm_id = :id';
+ $iPlaceID = $this->oDB->getOne($sSQL, array(':type' => $sType, ':id' => $iID));
if (!$iPlaceID) {
return null;
@@ -260,19 +261,19 @@ class PlaceLookup
$sSQL .= " 'P' as osm_type,";
$sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,';
$sSQL .= " 'place' as class, 'postcode' as type,";
- $sSQL .= ' null as admin_level, rank_search, rank_address,';
+ $sSQL .= ' null::smallint as admin_level, rank_search, rank_address,';
$sSQL .= ' place_id, parent_place_id,';
- $sSQL .= ' null as housenumber,';
+ $sSQL .= ' -1 as housenumber,';
$sSQL .= ' country_code,';
$sSQL .= $this->langAddressSql('-1');
$sSQL .= ' postcode as placename,';
$sSQL .= ' postcode as ref,';
- if ($this->bExtraTags) $sSQL .= 'null AS extra,';
- if ($this->bNameDetails) $sSQL .= 'null 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');
- $sSQL .= ' null AS extra_place ';
+ $sSQL .= ' null::text AS extra_place ';
$sSQL .= 'FROM location_postcode lp';
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
$sSQL .= " AND lp.rank_address between $iMinRank and $iMaxRank";
@@ -295,7 +296,7 @@ class PlaceLookup
$sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, ';
$sSQL .= " 'place' AS class, ";
$sSQL .= " 'house' AS type, ";
- $sSQL .= ' null AS admin_level, ';
+ $sSQL .= ' null::smallint AS admin_level, ';
$sSQL .= ' 30 AS rank_search, ';
$sSQL .= ' 30 AS rank_address, ';
$sSQL .= ' place_id, ';
@@ -303,15 +304,15 @@ class PlaceLookup
$sSQL .= ' housenumber_for_place as housenumber,';
$sSQL .= " 'us' AS country_code, ";
$sSQL .= $this->langAddressSql('housenumber_for_place');
- $sSQL .= ' null AS placename, ';
- $sSQL .= ' null AS ref, ';
- if ($this->bExtraTags) $sSQL .= 'null AS extra,';
- if ($this->bNameDetails) $sSQL .= 'null AS names,';
+ $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,';
$sSQL .= ' st_x(centroid) AS lon, ';
$sSQL .= ' st_y(centroid) AS lat,';
$sSQL .= ' -1.15 AS importance, ';
$sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
- $sSQL .= ' null AS extra_place ';
+ $sSQL .= ' null::text AS extra_place ';
$sSQL .= ' FROM (';
$sSQL .= ' SELECT place_id, '; // interpolate the Tiger housenumbers here
$sSQL .= ' ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) AS centroid, ';
@@ -341,7 +342,7 @@ class PlaceLookup
$sSQL .= ' osm_id, ';
$sSQL .= " 'place' AS class, ";
$sSQL .= " 'house' AS type, ";
- $sSQL .= ' 15 AS admin_level, ';
+ $sSQL .= ' null::smallint AS admin_level, ';
$sSQL .= ' 30 AS rank_search, ';
$sSQL .= ' 30 AS rank_address, ';
$sSQL .= ' place_id, ';
@@ -349,16 +350,16 @@ class PlaceLookup
$sSQL .= ' housenumber_for_place as housenumber,';
$sSQL .= ' country_code, ';
$sSQL .= $this->langAddressSql('housenumber_for_place');
- $sSQL .= ' null AS placename, ';
- $sSQL .= ' null AS ref, ';
- if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
- if ($this->bNameDetails) $sSQL .= 'null AS names, ';
+ $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, ';
$sSQL .= ' st_x(centroid) AS lon, ';
$sSQL .= ' st_y(centroid) AS lat, ';
// slightly smaller than the importance for normal houses
$sSQL .= ' -0.1 AS importance, ';
$sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id');
- $sSQL .= ' null AS extra_place ';
+ $sSQL .= ' null::text AS extra_place ';
$sSQL .= ' FROM (';
$sSQL .= ' SELECT ';
$sSQL .= ' osm_id, ';
@@ -390,7 +391,7 @@ class PlaceLookup
$sSQL .= ' place_id AS osm_id, ';
$sSQL .= " 'place' AS class,";
$sSQL .= " 'house' AS type, ";
- $sSQL .= ' null AS admin_level, ';
+ $sSQL .= ' null::smallint AS admin_level, ';
$sSQL .= ' 30 AS rank_search,';
$sSQL .= ' 30 AS rank_address, ';
$sSQL .= ' place_id,';
@@ -398,10 +399,10 @@ class PlaceLookup
$sSQL .= ' housenumber,';
$sSQL .= " 'us' AS country_code, ";
$sSQL .= $this->langAddressSql('-1');
- $sSQL .= ' null AS placename, ';
- $sSQL .= ' null AS ref, ';
- if ($this->bExtraTags) $sSQL .= 'null AS extra, ';
- if ($this->bNameDetails) $sSQL .= 'null AS names, ';
+ $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, ';
$sSQL .= ' ST_X(centroid) AS lon, ';
$sSQL .= ' ST_Y(centroid) AS lat, ';
$sSQL .= ' -1.10 AS importance, ';
@@ -409,7 +410,7 @@ class PlaceLookup
'centroid',
'location_property_aux.parent_place_id'
);
- $sSQL .= ' null AS extra_place ';
+ $sSQL .= ' null::text AS extra_place ';
$sSQL .= ' FROM location_property_aux ';
$sSQL .= " WHERE place_id in ($sPlaceIDs) ";
@@ -424,9 +425,10 @@ class PlaceLookup
$sSQL = join(' UNION ', $aSubSelects);
Debug::printSQL($sSQL);
- $aPlaces = chksql($this->oDB->getAll($sSQL), 'Could not lookup place');
+ $aPlaces = $this->oDB->getAll($sSQL, null, 'Could not lookup place');
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(
@@ -513,9 +515,9 @@ class PlaceLookup
$sSQL .= $sFrom;
}
- $aPointPolygon = chksql($this->oDB->getRow($sSQL), 'Could not get outline');
+ $aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline');
- if ($aPointPolygon['place_id']) {
+ if ($aPointPolygon && $aPointPolygon['place_id']) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
$aOutlineResult['lat'] = $aPointPolygon['centrelat'];
$aOutlineResult['lon'] = $aPointPolygon['centrelon'];