]> git.openstreetmap.org Git - nominatim.git/commitdiff
cut interpolated housenumbers at range boundaries
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 9 Oct 2016 21:54:58 +0000 (23:54 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 9 Oct 2016 21:54:58 +0000 (23:54 +0200)
Quick fix for #545.

lib/PlaceLookup.php

index 3fd882a70c12719447fd662ad6f4611ea662e60c..37d8578770f4a77e991c2fc600ff3dddf3f7d3f5 100644 (file)
@@ -113,10 +113,10 @@ class PlaceLookup
             if ($this->bNameDetails) $sSQL .= " null as names,";
             $sSQL .= " ST_X(point) as lon, ST_Y(point) as lat from (select *, ST_LineInterpolatePoint(linegeo, (housenumber-startnumber::float)/(endnumber-startnumber)::float) as point from ";
             $sSQL .= " (select *, ";
-            $sSQL .= " CASE WHEN interpolationtype='odd' THEN floor((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2+1";
+            $sSQL .= " GREATEST(startnumber, LEAST(endnumber, CASE WHEN interpolationtype='odd' THEN floor((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2+1";
             $sSQL .= " WHEN interpolationtype='even' THEN ((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2";
             $sSQL .= " WHEN interpolationtype='all' THEN (".$fInterpolFraction."*(endnumber-startnumber)+startnumber)::int";
-            $sSQL .= " END as housenumber";
+            $sSQL .= " END)) as housenumber";
             $sSQL .= " from location_property_tiger where place_id = ".$iPlaceID.") as blub1) as blub2";
         } elseif ($bIsInterpolation) {
             $sSQL = "select place_id, partition, 'W' as osm_type, osm_id, 'place' as class, 'house' as type, null admin_level, housenumber, null as street, null as isin, postcode,";
@@ -129,10 +129,10 @@ class PlaceLookup
             if ($this->bNameDetails) $sSQL .= " null as names,";
             $sSQL .= " ST_X(point) as lon, ST_Y(point) as lat from (select *, ST_LineInterpolatePoint(linegeo, (housenumber-startnumber::float)/(endnumber-startnumber)::float) as point from ";
             $sSQL .= " (select *, ";
-            $sSQL .= " CASE WHEN interpolationtype='odd' THEN floor((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2+1";
+            $sSQL .= " GREATEST(startnumber, LEAST(endnumber, CASE WHEN interpolationtype='odd' THEN floor((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2+1";
             $sSQL .= " WHEN interpolationtype='even' THEN ((".$fInterpolFraction."*(endnumber-startnumber)+startnumber)/2)::int*2";
             $sSQL .= " WHEN interpolationtype='all' THEN (".$fInterpolFraction."*(endnumber-startnumber)+startnumber)::int";
-            $sSQL .= " END as housenumber";
+            $sSQL .= " END)) as housenumber";
             $sSQL .= " from location_property_osmline where place_id = ".$iPlaceID.") as blub1) as blub2";
             // testcase: interpolationtype=odd, startnumber=1000, endnumber=1006, fInterpolFraction=1 => housenumber=1007 => error in st_lineinterpolatepoint
             // but this will never happen, because if the searched point is that close to the endnumber, the endnumber house will be directly taken from placex (in ReverseGeocode.php line 220)