]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/Geocode.php
Merge pull request #420 from lonvia/remove-explicit-software-versions
[nominatim.git] / lib / Geocode.php
index 8eaa540263c0fc825bc368a077325c4264305520..f2ca5e5008f36d440cc67f8dc81eb5c497f94b61 100644 (file)
                function loadParamArray($aParams)
                {
                        if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
                function loadParamArray($aParams)
                {
                        if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
-                       if ((float) CONST_Postgresql_Version > 9.2)
-                       {
-                               if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
-                               if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
-                       }
+                       if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
+                       if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
+
                        if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
                        if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
 
                        if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
                        if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
 
                        $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
 
                        // Get the details for display (is this a redundant extra step?)
                        $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
 
                        // Get the details for display (is this a redundant extra step?)
-                       $sPlaceIDs = join(',',array_keys($aPlaceIDs));
+                       $sPlaceIDs = join(',', array_keys($aPlaceIDs));
 
                        $sImportanceSQL = '';
                        if ($this->sViewboxSmallSQL) $sImportanceSQL .= " case when ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
 
                        $sImportanceSQL = '';
                        if ($this->sViewboxSmallSQL) $sImportanceSQL .= " case when ST_Contains($this->sViewboxSmallSQL, ST_Collect(centroid)) THEN 1 ELSE 0.75 END * ";
                                //Tiger search only if a housenumber was searched and if it was found (i.e. aPlaceIDs[placeID] = housenumber != -1) (realized through a join)
                                //only Tiger housenumbers need to be interpolated, because they are saved as lines with start- and endnumber, the common osm housenumbers are usually saved as points
                                $sHousenumbers = "";
                                //Tiger search only if a housenumber was searched and if it was found (i.e. aPlaceIDs[placeID] = housenumber != -1) (realized through a join)
                                //only Tiger housenumbers need to be interpolated, because they are saved as lines with start- and endnumber, the common osm housenumbers are usually saved as points
                                $sHousenumbers = "";
-                               $i=0;
-                               $length=count($aPlaceIDs);
-                               foreach($aPlaceIDs as $placeID => $housenumber){
+                               $i = 0;
+                               $length = count($aPlaceIDs);
+                               foreach($aPlaceIDs as $placeID => $housenumber)
+                {
                                        $i++;
                                        $sHousenumbers .= "(".$placeID.", ".$housenumber.")";
                                        if($i<$length)
                                        $i++;
                                        $sHousenumbers .= "(".$placeID.", ".$housenumber.")";
                                        if($i<$length)
                                $sSQL .= ", null as ref";
                                if ($this->bIncludeExtraTags) $sSQL .= ", null as extra";
                                if ($this->bIncludeNameDetails) $sSQL .= ", null as names";
                                $sSQL .= ", null as ref";
                                if ($this->bIncludeExtraTags) $sSQL .= ", null as extra";
                                if ($this->bIncludeNameDetails) $sSQL .= ", null as names";
-                               $sSQL .= ", avg(st_x(point)) as lon, avg(st_y(point)) as lat";
-                               $sSQL .= $sImportanceSQL."-1.15 as importance ";
+                               $sSQL .= ", avg(st_x(centroid)) as lon, avg(st_y(centroid)) as lat,";
+                               $sSQL .= $sImportanceSQL."-1.15 as importance ";
                                $sSQL .= ", (select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(blub.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance ";
                                $sSQL .= ", null as extra_place ";
                                $sSQL .= " from (select place_id";
                                //interpolate the Tiger housenumbers here
                                $sSQL .= ", (select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(blub.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance ";
                                $sSQL .= ", null as extra_place ";
                                $sSQL .= " from (select place_id";
                                //interpolate the Tiger housenumbers here
-                               $sSQL .= ", ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) as point, parent_place_id, housenumber_for_place ";
+                               $sSQL .= ", ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) as centroid, parent_place_id, housenumber_for_place ";
                                $sSQL .= "from (location_property_tiger ";
                                $sSQL .= " join (values ".$sHousenumbers.") as housenumbers(place_id, housenumber_for_place) using(place_id)) ";
                                $sSQL .= " where housenumber_for_place>=0 and 30 between $this->iMinAddressRank and $this->iMaxAddressRank) as blub"; //postgres wants an alias here
                                $sSQL .= "from (location_property_tiger ";
                                $sSQL .= " join (values ".$sHousenumbers.") as housenumbers(place_id, housenumber_for_place) using(place_id)) ";
                                $sSQL .= " where housenumber_for_place>=0 and 30 between $this->iMinAddressRank and $this->iMaxAddressRank) as blub"; //postgres wants an alias here
                        }
 
                        // Do we have anything that looks like a lat/lon pair?
                        }
 
                        // Do we have anything that looks like a lat/lon pair?
-                       if ( $aLooksLike = looksLikeLatLonPair($sQuery) ){
+                       if ( $aLooksLike = looksLikeLatLonPair($sQuery) )
+            {
                                $this->setNearPoint(array($aLooksLike['lat'], $aLooksLike['lon']));
                                $sQuery = $aLooksLike['query'];
                        }
                                $this->setNearPoint(array($aLooksLike['lat'], $aLooksLike['lon']));
                                $sQuery = $aLooksLike['query'];
                        }
                                        foreach($aSearches as $aSearch)
                                        {
                                                $iQueryLoop++;
                                        foreach($aSearches as $aSearch)
                                        {
                                                $iQueryLoop++;
-                                               $searchedHousenumber=-1;
+                                               $searchedHousenumber = -1;
 
                                                if (CONST_Debug) { echo "<hr><b>Search Loop, group $iGroupLoop, loop $iQueryLoop</b>"; }
                                                if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
 
                                                if (CONST_Debug) { echo "<hr><b>Search Loop, group $iGroupLoop, loop $iQueryLoop</b>"; }
                                                if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
                                                                if (!sizeof($aPlaceIDs))
                                                                {
                                                                        //new query for lines, not housenumbers anymore
                                                                if (!sizeof($aPlaceIDs))
                                                                {
                                                                        //new query for lines, not housenumbers anymore
-                                                                       if($searchedHousenumber%2==0){
+                                                                       if($searchedHousenumber%2 == 0){
                                                                                //if housenumber is even, look for housenumber in streets with interpolationtype even or all
                                                                                $sSQL = "select distinct place_id from location_property_tiger where parent_place_id in (".$sPlaceIDs.") and (interpolationtype='even' or interpolationtype='all') and ".$searchedHousenumber.">=startnumber and ".$searchedHousenumber."<=endnumber";
                                                                        }else{
                                                                                //if housenumber is even, look for housenumber in streets with interpolationtype even or all
                                                                                $sSQL = "select distinct place_id from location_property_tiger where parent_place_id in (".$sPlaceIDs.") and (interpolationtype='even' or interpolationtype='all') and ".$searchedHousenumber.">=startnumber and ".$searchedHousenumber."<=endnumber";
                                                                        }else{
                                                                {
                                                                        $aPlaceIDs = $aRoadPlaceIDs;
                                                                        //set to -1, if no housenumbers were found
                                                                {
                                                                        $aPlaceIDs = $aRoadPlaceIDs;
                                                                        //set to -1, if no housenumbers were found
-                                                                       $searchedHousenumber=-1;
-                                                               }else{
-                                                                       //housenumber was found, remains saved in searchedHousenumber
+                                                                       $searchedHousenumber = -1;
                                                                }
                                                                }
+                                //else: housenumber was found, remains saved in searchedHousenumber
                                                        }
 
 
                                                        if ($aSearch['sClass'] && sizeof($aPlaceIDs))
                                                        {
                                                        }
 
 
                                                        if ($aSearch['sClass'] && sizeof($aPlaceIDs))
                                                        {
-                                                               $sPlaceIDs = join(',', aPlaceIDs);
+                                                               $sPlaceIDs = join(',', $aPlaceIDs);
                                                                $aClassPlaceIDs = array();
 
                                                                if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
                                                                $aClassPlaceIDs = array();
 
                                                                if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
                                                if (CONST_Debug) var_dump($sSQL);
                                                $aFilteredPlaceIDs = $this->oDB->getCol($sSQL);
                                                $tempIDs = array();
                                                if (CONST_Debug) var_dump($sSQL);
                                                $aFilteredPlaceIDs = $this->oDB->getCol($sSQL);
                                                $tempIDs = array();
-                                               foreach($aFilteredPlaceIDs as $placeID){
-                                                       $tempIDs[$placeID]= $aResultPlaceIDs[$placeID];  //assign housenumber to placeID
+                                               foreach($aFilteredPlaceIDs as $placeID)
+                        {
+                                                       $tempIDs[$placeID] = $aResultPlaceIDs[$placeID];  //assign housenumber to placeID
                                                }
                                                }
-                                               $aResultPlaceIDs=$tempIDs;
+                                               $aResultPlaceIDs = $tempIDs;
                                        }
 
                                        //exit;
                                        }
 
                                        //exit;