$sSQL .= ' CASE '; // interpolate the housenumbers here
$sSQL .= ' WHEN startnumber != endnumber ';
$sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ';
- $sSQL .= ' ELSE ST_LineInterpolatePoint(linegeo, 0.5) ';
+ $sSQL .= ' ELSE linegeo ';
$sSQL .= ' END as centroid, ';
$sSQL .= ' parent_place_id, ';
$sSQL .= ' housenumber_for_place ';
{
Debug::newFunction('lookupInterpolation');
$sSQL = 'SELECT place_id, parent_place_id, 30 as rank_search,';
- $sSQL .= ' ST_LineLocatePoint(linegeo,'.$sPointSQL.') as fraction,';
- $sSQL .= ' startnumber, endnumber, interpolationtype,';
+ $sSQL .= ' (endnumber - startnumber) * ST_LineLocatePoint(linegeo,'.$sPointSQL.') as fhnr,';
+ $sSQL .= ' startnumber, endnumber, step,';
$sSQL .= ' ST_Distance(linegeo,'.$sPointSQL.') as distance';
$sSQL .= ' FROM location_property_osmline';
$sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')';
if ($aHouse) {
$oResult = new Result($aHouse['place_id'], Result::TABLE_OSMLINE);
- $oResult->iHouseNumber = closestHouseNumber($aHouse);
+ $iRndNum = max(0, round($aHouse['fhnr'] / $aHouse['step']) * $aHouse['step']);
+ $oResult->iHouseNumber = $aHouse['startnumber'] + $iRndNum;
+ if ($oResult->iHouseNumber > $aHouse['endnumber']) {
+ $oResult->iHouseNumber = $aHouse['endnumber'];
+ }
$aPlace = $aHouse;
}
}
// if nothing found, search in the interpolation line table
$sSQL = 'SELECT distinct place_id FROM location_property_osmline';
$sSQL .= ' WHERE startnumber is not NULL';
- $sSQL .= ' AND parent_place_id in ('.$sRoadPlaceIDs.') AND (';
- if ($iHousenumber % 2 == 0) {
- // If housenumber is even, look for housenumber in streets
- // with interpolationtype even or all.
- $sSQL .= "interpolationtype='even'";
- } else {
- // Else look for housenumber with interpolationtype odd or all.
- $sSQL .= "interpolationtype='odd'";
- }
- $sSQL .= " or interpolationtype='all') and ";
- $sSQL .= $iHousenumber.'>=startnumber and ';
- $sSQL .= $iHousenumber.'<=endnumber';
+ $sSQL .= ' and parent_place_id in ('.$sRoadPlaceIDs.')';
+ $sSQL .= ' and ('.$iHousenumber.' - startnumber) % step = 0';
+ $sSQL .= ' and '.$iHousenumber.' between startnumber and endnumber';
$sSQL .= $this->oContext->excludeSQL(' AND place_id');
Debug::printSQL($sSQL);
Given the places
| osm | class | type | housenr | geometry |
| N1 | place | house | 0 | 1 1 |
- | N2 | place | house | 8 | 1 1.001 |
+ | N2 | place | house | 10 | 1 1.001 |
And the places
| osm | class | type | addr+interpolation | geometry |
| W1 | place | houses | even | 1 1, 1 1.001 |
When importing
Then W1 expands to interpolation
| start | end | geometry |
- | 2 | 6 | 1 0002, 1 1.0008 |
+ | 2 | 8 | 1 1.0002, 1 1.0008 |
When sending jsonv2 reverse coordinates 1,1
Then results contain
| ID | osm_type | osm_id | type | display_name |
- | 0 | way | 1 | house | 0 |
+ | 0 | node | 1 | house | 0 |