+ $aAllHouses = $this->oDB->getAll($sSQL);
+ foreach($aAllHouses as $i)
+ {
+ echo $i['housenumber'] . ' | ' . $i['distance'] * 1000 . ' | ' . $i['lat'] . ' | ' . $i['lon']. ' | '. "<br>\n";
+ }
+ }
+ $aPlaceLine = $this->oDB->getRow($sSQL);
+ if (PEAR::IsError($aPlaceLine))
+ {
+ failInternalError("Could not determine closest housenumber on an osm interpolation line.", $sSQL, $aPlaceLine);
+ }
+ $iInterpolationLinePlaceID = $aPlaceLine['place_id'];
+ if ($aPlaceLine)
+ {
+ if (CONST_Debug) var_dump('found housenumber in interpolation lines table', $aPlaceLine);
+ if ($aPlace['rank_search'] == 30)
+ {
+ // if a house was already found in placex, we have to find out,
+ // if the placex house or the interpolated house are closer to the searched point
+ // distance between point and placex house
+ $sSQL = 'SELECT ST_distance('.$sPointSQL.', house.geometry) as distance FROM placex as house WHERE house.place_id='.$iPlaceID;
+ $aDistancePlacex = $this->oDB->getRow($sSQL);
+ if (PEAR::IsError($aDistancePlacex))
+ {
+ failInternalError("Could not determine distance between searched point and placex house.", $sSQL, $aDistancePlacex);
+ }
+ $fDistancePlacex = $aDistancePlacex['distance'];
+ // distance between point and interpolated house (fraction on interpolation line)
+ $sSQL = 'SELECT ST_distance('.$sPointSQL.', ST_LineInterpolatePoint(linegeo, '.$aPlaceLine['fraction'].')) as distance';
+ $sSQL .= ' FROM location_property_osmline WHERE place_id = '.$iInterpolationLinePlaceID;
+ $aDistanceInterpolation = $this->oDB->getRow($sSQL);
+ if (PEAR::IsError($aDistanceInterpolation))
+ {
+ failInternalError("Could not determine distance between searched point and interpolated house.", $sSQL, $aDistanceInterpolation);
+ }
+ $fDistanceInterpolation = $aDistanceInterpolation['distance'];
+ if ($fDistanceInterpolation < $fDistancePlacex)
+ {
+ // interpolation is closer to point than placex house
+ $bPlaceIsLine = true;
+ $aPlace = $aPlaceLine;
+ $iPlaceID = $iInterpolationLinePlaceID;
+ $iParentPlaceID = $aPlaceLine['parent_place_id']; // the street
+ $fFraction = $aPlaceLine['fraction'];
+ }
+ // else: nothing to do, take placex house from above
+ }
+ else
+ {
+ $bPlaceIsLine = true;
+ $aPlace = $aPlaceLine;
+ $iPlaceID = $aPlaceLine['place_id'];
+ $iParentPlaceID = $aPlaceLine['parent_place_id']; // the street
+ $fFraction = $aPlaceLine['fraction'];
+ }
+ }
+ }
+