forked from openmaptiles/openmaptiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert semi-colon separated house numbers to a range (openmaptiles#1562
) This PR collapses housenumber values into the form min(housenumber)-max(housenumber) for cases where housenumber is a semi-colon separated list. If the list is all numbers, the bounds are the smallest and largest numbers. If the list includes non-numeric characters, it falls back to the first and last values in the list.
- Loading branch information
1 parent
e06ab64
commit ac86bb2
Showing
3 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE OR REPLACE FUNCTION display_housenumber_nonnumeric(raw_housenumber text) | ||
RETURNS text AS $$ | ||
-- Find the position of the semicolon in the input string | ||
-- and extract the first and last value | ||
SELECT substring(raw_housenumber from 1 for position(';' in raw_housenumber) - 1) | ||
|| '–' | ||
|| substring(raw_housenumber from position(';' in raw_housenumber) + 1); | ||
$$ LANGUAGE SQL IMMUTABLE; | ||
|
||
|
||
CREATE OR REPLACE FUNCTION display_housenumber(raw_housenumber text) | ||
RETURNS text AS $$ | ||
SELECT CASE | ||
WHEN raw_housenumber !~ ';' THEN raw_housenumber | ||
WHEN raw_housenumber ~ '[^0-9;]' THEN display_housenumber_nonnumeric(raw_housenumber) | ||
ELSE | ||
(SELECT min(value)::text || '–' || max(value)::text | ||
FROM unnest(string_to_array(raw_housenumber, ';')::int[]) AS value) | ||
END | ||
$$ LANGUAGE SQL IMMUTABLE; |