Updating admin0
This commit is contained in:
@@ -3,7 +3,13 @@ Administrative regions geocoder - Level 0
|
|||||||
|
|
||||||
# Function
|
# Function
|
||||||
|
|
||||||
Accepts a list of terms. Terms are searched against the ```name_``` column in ```admin0_synonyms```. The ```name_``` column is an automatically cleaned and populated column based on the raw values in ```name_``` . The synonym table returns the proper ISO code (based on rank values in table below). The iso code is then matched against the single row in ```ne_admin0_v3``` to return the polygon.
|
Accepts a list of terms. Terms are searched against the `name_` column in `admin0_synonyms`. The `name_ column is an automatically cleaned and populated column based on the raw values in `name_ . The synonym table returns the proper ISO code (based on rank values in table below). The ISO code is then matched against the single row in `ne_admin0_v3 to return the polygon.
|
||||||
|
|
||||||
|
# Usage example
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT (geocode_admin0_polygons(Array['Spain', 'USA', ''])).*;
|
||||||
|
```
|
||||||
|
|
||||||
# Creation steps
|
# Creation steps
|
||||||
|
|
||||||
@@ -237,7 +243,7 @@ The table contains the following columns to be populated:
|
|||||||
The following query can be used:
|
The following query can be used:
|
||||||
|
|
||||||
|
|
||||||
````
|
````sql
|
||||||
INSERT INTO admin0_synonym_additions (adm0_a3, name, notes, rank) VALUES ($iso3_code, $synonym, $notes, 10)
|
INSERT INTO admin0_synonym_additions (adm0_a3, name, notes, rank) VALUES ($iso3_code, $synonym, $notes, 10)
|
||||||
````
|
````
|
||||||
|
|
||||||
@@ -284,6 +290,8 @@ For country boundaries, we use the data provided by Natural Earth Data. The whol
|
|||||||
# Known issues
|
# Known issues
|
||||||
|
|
||||||
# Historic
|
# Historic
|
||||||
|
* [19/10/2015]:
|
||||||
|
* Revision and usage examples addition
|
||||||
* [06/10/2015]:
|
* [06/10/2015]:
|
||||||
* Added information for response types
|
* Added information for response types
|
||||||
* [28/09/2015]:
|
* [28/09/2015]:
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
--- Geocoding function ---
|
--- Geocoding function ---
|
||||||
--CREATE TYPE geocode_admin_v1 AS (q TEXT, geom GEOMETRY, success BOOLEAN);
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION geocode_admin0_polygons(name text[])
|
CREATE OR REPLACE FUNCTION geocode_admin0_polygons(name text[])
|
||||||
RETURNS SETOF geocode_admin_v1 AS $$
|
RETURNS SETOF geocode_admin_v1 AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@@ -15,8 +13,6 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
|||||||
--- Helper functions ---
|
--- Helper functions ---
|
||||||
|
|
||||||
-- admin0_synonym_lookup
|
-- admin0_synonym_lookup
|
||||||
--CREATE TYPE synonym_lookup_v1 AS (q TEXT, s TEXT);
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION admin0_synonym_lookup(name text[])
|
CREATE OR REPLACE FUNCTION admin0_synonym_lookup(name text[])
|
||||||
RETURNS SETOF synonym_lookup_v1 AS $$
|
RETURNS SETOF synonym_lookup_v1 AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@@ -25,4 +21,3 @@ CREATE OR REPLACE FUNCTION admin0_synonym_lookup(name text[])
|
|||||||
SELECT d.q, s.adm0_a3 FROM (SELECT q, lower(regexp_replace(q, '[^a-zA-Z\u00C0-\u00ff]+', '', 'g'))::text x FROM (SELECT unnest(name) q) g) d LEFT OUTER JOIN admin0_synonyms s ON name_ = d.x GROUP BY d.q, s.adm0_a3;
|
SELECT d.q, s.adm0_a3 FROM (SELECT q, lower(regexp_replace(q, '[^a-zA-Z\u00C0-\u00ff]+', '', 'g'))::text x FROM (SELECT unnest(name) q) g) d LEFT OUTER JOIN admin0_synonyms s ON name_ = d.x GROUP BY d.q, s.adm0_a3;
|
||||||
END
|
END
|
||||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
--CREATE TYPE synonym_lookup_v1 AS (q TEXT, adm0_a3 TEXT);
|
|
||||||
|
|
||||||
--EXAMPLE
|
--EXAMPLE
|
||||||
-- SELECT (admin0_synonym_lookup(Array['United States', 'ESP'])).*
|
-- SELECT (admin0_synonym_lookup(Array['United States', 'ESP'])).*
|
||||||
|
|||||||
Reference in New Issue
Block a user