From: Regina Obe Date: Wed, 6 Jul 2011 23:00:02 +0000 (+0000) Subject: fix for #1109 when a street name is same as a defined street type X-Git-Tag: 2.0.0alpha1~1229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88fecac44a661dad84eb83cc01f152e27f7b2d54;p=postgis fix for #1109 when a street name is same as a defined street type git-svn-id: http://svn.osgeo.org/postgis/trunk@7613 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql b/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql index 6465d1d1b..eaa5cbb98 100644 --- a/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql +++ b/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql @@ -300,23 +300,28 @@ BEGIN WHERE fullStreet ILIKE '%' || name || '%' AND trim(upper(fullStreet)) != name AND texticregexeq(fullStreet, '(?i)' || ws || '(' || name - || ')(?:' || ws || '|$)') ; + || ')(?:' || ws || '|$)') ; streetType := rec.given; result.streetTypeAbbrev := rec.abbrev; isHighway := rec.is_hw; IF debug_flag THEN - RAISE NOTICE 'street Type: %, street Type abbrev: %', rec.given, rec.abbrev; + RAISE NOTICE 'street Type: %, street Type abbrev: %', rec.given, rec.abbrev; END IF; ELSIF tempInt > 1 THEN tempInt := 0; + -- the last matching abbrev in the string is the most likely one FOR rec IN SELECT abbrev, substring(fullStreet, '(?i)' || ws || '?(' || name || ')(?:' || ws || '|$)') AS given, is_hw FROM street_type_lookup WHERE fullStreet ILIKE '%' || name || '%' AND trim(upper(fullStreet)) != name AND texticregexeq(fullStreet, '(?i)' || ws || '(' || name - || ')(?:' || ws || '|$)') ORDER BY length(name) DESC LIMIT 1 LOOP + -- we only consider street types that are regular and not at beginning of name or are highways (since those can be at beg or end) + -- we take the one that is the longest e.g Country Road would be more correct than Road + || ')(?:' || ws || '|$)') AND ((NOT is_hw AND position(name IN trim(fullStreet)) > 2) OR is_hw) ORDER BY length(name) DESC LIMIT 1 LOOP -- If we have found an internal address, make sure the type -- precedes it. + /** TODO: I don't think we need a loop anymore since we are just returning one and the one in the last position + * I'll leave for now though **/ IF result.internal IS NOT NULL THEN IF position(rec.given IN fullStreet) < position(result.internal IN fullStreet) THEN IF tempInt < position(rec.given IN fullStreet) THEN @@ -397,6 +402,11 @@ BEGIN END IF; reducedStreet := substring(fullStreet, '^(.*)' || ws || '+' || streetType); + IF COALESCE(reducedStreet,'') = '' THEN --reduced street can't be blank + reducedStreet := fullStreet; + streetType := NULL; + result.streetTypeAbbrev := NULL; + END IF; END IF; -- the post direction might be portion of fullStreet after reducedStreet -- reducedStreet: Main fullStreet: Main St, N or fullStreet: Main St N