+ $sSQL = 'SELECT place_id, parent_place_id, 30 as rank_search,';
+ $sSQL .= ' ST_LineLocatePoint(linegeo,'.$sPointSQL.') as fraction,';
+ $sSQL .= ' startnumber, endnumber, interpolationtype,';
+ $sSQL .= ' ST_Distance(linegeo,'.$sPointSQL.') as distance';
+ $sSQL .= ' FROM location_property_osmline';
+ $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')';
+ $sSQL .= ' and indexed_status = 0 and startnumber is not NULL ';
+ $sSQL .= ' ORDER BY distance ASC limit 1';
+
+ return chksql(
+ $this->oDB->getRow($sSQL),
+ 'Could not determine closest housenumber on an osm interpolation line.'
+ );
+ }
+
+ protected function lookupPolygon($sPointSQL, $iMaxRank)
+ {
+ $sSQL = 'select place_id,parent_place_id,rank_search,country_code, geometry';
+ $sSQL .= ' FROM placex';
+ $sSQL .= ' WHERE ST_GeometryType(geometry) in (\'ST_Polygon\',\'ST_MultiPolygon\')';
+ $sSQL .= ' AND rank_search <= LEAST(25, '.$iMaxRank.')';
+ $sSQL .= ' AND ST_CONTAINS(geometry, '.$sPointSQL.' )';
+ $sSQL .= ' AND type != \'postcode\' ';
+ $sSQL .= ' AND name IS NOT NULL ';
+ $sSQL .= ' ORDER BY rank_search DESC LIMIT 1';
+
+ $aPoly = chksql(
+ $this->oDB->getRow($sSQL),
+ 'Could not determine polygon containing the point.'
+ );
+ if ($aPoly) {
+ $iParentPlaceID = $aPoly['parent_place_id'];
+ $iRankSearch = $aPoly['rank_search'];
+ $iPlaceID = $aPoly['place_id'];
+
+ $sSQL = 'select place_id,parent_place_id,rank_search,country_code, linked_place_id,';
+ $sSQL .=' ST_distance('.$sPointSQL.', geometry) as distance';
+ $sSQL .= ' FROM placex';
+ $sSQL .= ' WHERE osm_type = \'N\'';
+ $sSQL .= ' AND rank_search >= '.$iRankSearch;
+ $sSQL .= ' AND rank_search <= LEAST(25, '.$iMaxRank.')';
+ $sSQL .= ' AND ST_CONTAINS((SELECT geometry FROM placex WHERE place_id = '.$iPlaceID.'), geometry )';
+ $sSQL .= ' AND type != \'postcode\'';
+ $sSQL .= ' AND name IS NOT NULL ';
+ $sSQL .= ' AND class not in ( \'waterway\')';
+ $sSQL .= ' ORDER BY distance ASC,';
+ $sSQL .= ' rank_search DESC';
+ $sSQL .= ' limit 1';
+ if (CONST_Debug) var_dump($sSQL);
+ $aPlacNode = chksql(
+ $this->oDB->getRow($sSQL),
+ 'Could not determine place node.'
+ );
+ if ($aPlacNode) {
+ return $aPlacNode;
+ }
+ }
+ return $aPoly;
+ }
+
+ public function lookup($fLat, $fLon, $bDoInterpolation = true)
+ {
+ return $this->lookupPoint(
+ 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)',
+ $bDoInterpolation
+ );
+ }
+
+ public function lookupPoint($sPointSQL, $bDoInterpolation = true)
+ {
+