- if ($this->sViewboxSmallSQL) $sImportanceSQL .= " case when ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
- if ($this->sViewboxLargeSQL) $sImportanceSQL .= " case when ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
-
- $sSQL = "select osm_type,osm_id,class,type,admin_level,rank_search,rank_address,min(place_id) as place_id, min(parent_place_id) as parent_place_id, calculated_country_code as country_code,";
- $sSQL .= "get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) as langaddress,";
- $sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
- $sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
- if ($this->bIncludeExtraTags) $sSQL .= "hstore_to_json(extratags)::text as extra,";
- if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text as names,";
- $sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
- $sSQL .= $sImportanceSQL."coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
- $sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
- $sSQL .= "(extratags->'place') as extra_place ";
- $sSQL .= "from placex where place_id in ($sPlaceIDs) ";
- $sSQL .= "and (placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
- if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
- if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$this->aAddressRankList).")";
- $sSQL .= ") ";
- if ($this->sAllowedTypesSQLList) $sSQL .= "and placex.class in $this->sAllowedTypesSQLList ";
- $sSQL .= "and linked_place_id is null ";
- $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,calculated_country_code,importance";
- if (!$this->bDeDupe) $sSQL .= ",place_id";
- $sSQL .= ",langaddress ";
- $sSQL .= ",placename ";
- $sSQL .= ",ref ";
- if ($this->bIncludeExtraTags) $sSQL .= ",extratags";
- if ($this->bIncludeNameDetails) $sSQL .= ",name";
- $sSQL .= ",extratags->'place' ";
+ if ($this->sViewboxSmallSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+ if ($this->sViewboxLargeSQL) $sImportanceSQL .= " CASE WHEN ST_Contains($this->sViewboxLargeSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
+
+ $sSQL = "SELECT ";
+ $sSQL .= " osm_type,";
+ $sSQL .= " osm_id,";
+ $sSQL .= " class,";
+ $sSQL .= " type,";
+ $sSQL .= " admin_level,";
+ $sSQL .= " rank_search,";
+ $sSQL .= " rank_address,";
+ $sSQL .= " min(place_id) AS place_id, ";
+ $sSQL .= " min(parent_place_id) AS parent_place_id, ";
+ $sSQL .= " country_code, ";
+ $sSQL .= " get_address_by_language(place_id, -1, $sLanguagePrefArraySQL) AS langaddress,";
+ $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) AS placename,";
+ $sSQL .= " get_name_by_language(name, ARRAY['ref']) AS ref,";
+ if ($this->bIncludeExtraTags) $sSQL .= "hstore_to_json(extratags)::text AS extra,";
+ if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text AS names,";
+ $sSQL .= " avg(ST_X(centroid)) AS lon, ";
+ $sSQL .= " avg(ST_Y(centroid)) AS lat, ";
+ $sSQL .= " ".$sImportanceSQL."COALESCE(importance,0.75-(rank_search::float/40)) AS importance, ";
+ $sSQL .= " ( ";
+ $sSQL .= " SELECT max(p.importance*(p.rank_address+2))";
+ $sSQL .= " FROM ";
+ $sSQL .= " place_addressline s, ";
+ $sSQL .= " placex p";
+ $sSQL .= " WHERE s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)";
+ $sSQL .= " AND p.place_id = s.address_place_id ";
+ $sSQL .= " AND s.isaddress ";
+ $sSQL .= " AND p.importance is not null ";
+ $sSQL .= " ) AS addressimportance, ";
+ $sSQL .= " (extratags->'place') AS extra_place ";
+ $sSQL .= " FROM placex";
+ $sSQL .= " WHERE place_id in ($sPlaceIDs) ";
+ $sSQL .= " AND (";
+ $sSQL .= " placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
+ if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) {
+ $sSQL .= " OR (extratags->'place') = 'city'";
+ }
+ if ($this->aAddressRankList) {
+ $sSQL .= " OR placex.rank_address in (".join(',', $this->aAddressRankList).")";
+ }
+ $sSQL .= " ) ";
+ if ($this->sAllowedTypesSQLList) {
+ $sSQL .= "AND placex.class in $this->sAllowedTypesSQLList ";
+ }
+ $sSQL .= " AND linked_place_id is null ";
+ $sSQL .= " GROUP BY ";
+ $sSQL .= " osm_type, ";
+ $sSQL .= " osm_id, ";
+ $sSQL .= " class, ";
+ $sSQL .= " type, ";
+ $sSQL .= " admin_level, ";
+ $sSQL .= " rank_search, ";
+ $sSQL .= " rank_address, ";
+ $sSQL .= " country_code, ";
+ $sSQL .= " importance, ";
+ if (!$this->bDeDupe) $sSQL .= "place_id,";
+ $sSQL .= " langaddress, ";
+ $sSQL .= " placename, ";
+ $sSQL .= " ref, ";
+ if ($this->bIncludeExtraTags) $sSQL .= "extratags, ";
+ if ($this->bIncludeNameDetails) $sSQL .= "name, ";
+ $sSQL .= " extratags->'place' ";