Compare commits
11 Commits
cdb_geocod
...
cdb_geocod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4c8d11ef7 | ||
|
|
2d05db5597 | ||
|
|
d0e0e5e94f | ||
|
|
3dd0827765 | ||
|
|
cfef57be74 | ||
|
|
182b34244e | ||
|
|
df1d6c0d8d | ||
|
|
905d1c9348 | ||
|
|
2805a1c05c | ||
|
|
3e6593d480 | ||
|
|
913c4ade63 |
@@ -1247,6 +1247,84 @@ Data library
|
||||
|
||||
**Source URL**: http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/datalayers/structures.html
|
||||
|
||||
#### Municipalities of Spain
|
||||
**Description**: Geometries for the municipalities of Spain. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm3_municipalities
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
#### Municipalities of Spain with displaced Canary Islands
|
||||
**Description**: Geometries for the municipalities of Spain with the Canary Islands displaced. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm3_municipalities_displaced_canary
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
#### Provinces of Spain
|
||||
**Description**: Geometries for the provinces of Spain. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm2_provinces
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
#### Provinces of Spain with displaced Canary Islands
|
||||
**Description**: Geometries for the provinces of Spain with the Canary Islands displaced. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm2_provinces_displaced_canary
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
#### Autonomous Communities of Spain.
|
||||
**Description**: Geometries for the autonomous communities of Spain. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm1_ccaa
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
#### Autonomous communities of Spain with displaced Canary Islands
|
||||
**Description**: Geometries for the autonomous communities of Spain with the Canary Islands displaced. Official dataset from Instituto Geográfico Nacional de España.
|
||||
|
||||
**Source**: [Instituto Geográfico Nacional](http://www.ign.es/)
|
||||
|
||||
**License**: Public data - Attribution required
|
||||
|
||||
**Table Name**: ign_spanish_adm1_ccaa_displaced_canary
|
||||
|
||||
**Sync Table**: `false`
|
||||
|
||||
**Source URL**: http://centrodedescargas.cnig.es/CentroDescargas/equipamiento/lineas_limite.zip
|
||||
|
||||
***
|
||||
|
||||
### Historic
|
||||
|
||||
@@ -46,13 +46,25 @@ SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array
|
||||
Portland | Maine | USA | | f
|
||||
(3 rows)
|
||||
|
||||
SELECT namedplace_guess_country(Array['granada', 'jaen', 'cordoba', 'madrid', 'valladolid']);
|
||||
namedplace_guess_country
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- Add a named place source
|
||||
COPY global_cities_alternates_limited (geoname_id, name, the_geom, created_at, updated_at, the_geom_webmercator, preferred, lowername, cartodb_id, admin1_geonameid, iso2, admin1) FROM stdin;
|
||||
COPY global_cities_points_limited (geoname_id, name, asciiname, altnames, featclass, featcode, iso2, admin1, admin2, population, the_geom, created_at, updated_at, the_geom_webmercator, cartodb_id, lowername) FROM stdin;
|
||||
-- Check that the geocoding function is callable, should return success = true
|
||||
SELECT (geocode_namedplace(Array['Barcelona'])).*
|
||||
SELECT (geocode_namedplace(Array['Barcelona'])).*;
|
||||
q | geom | success
|
||||
-----------+----------------------------------------------------+---------
|
||||
Barcelona | 0101000020E6100000CA15DEE522E653C0A4C2D842902B4540 | t
|
||||
(1 row)
|
||||
|
||||
SELECT namedplace_guess_country(Array['Barcelona']);
|
||||
namedplace_guess_country
|
||||
--------------------------
|
||||
ES
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -288,6 +288,40 @@ CREATE OR REPLACE FUNCTION geocode_namedplace(places text[]) RETURNS SETOF geoco
|
||||
END
|
||||
$$;
|
||||
|
||||
CREATE OR REPLACE FUNCTION namedplace_guess_country(places text[])
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
country_code text;
|
||||
threshold CONSTANT float := 0.8;
|
||||
input_length integer := array_length(places, 1);
|
||||
BEGIN
|
||||
BEGIN
|
||||
WITH hist AS (
|
||||
SELECT count(DISTINCT(lower(p.s), gp.iso2)) AS c, iso2
|
||||
FROM global_cities_points_limited gp
|
||||
inner join (SELECT unnest(places) AS s) p
|
||||
ON (gp.lowername = lower(s))
|
||||
GROUP BY iso2
|
||||
),
|
||||
best_two AS (
|
||||
SELECT iso2, c
|
||||
FROM hist
|
||||
WHERE c > input_length * threshold
|
||||
ORDER BY c DESC
|
||||
LIMIT 2
|
||||
)
|
||||
SELECT iso2 INTO STRICT country_code
|
||||
FROM (SELECT iso2, c, max(c) over() AS maxcount FROM best_two) bt
|
||||
WHERE bt.c = bt.maxcount;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND OR too_many_rows THEN
|
||||
RETURN NULL;
|
||||
END;
|
||||
RETURN country_code;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER IMMUTABLE;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Support tables
|
||||
|
||||
@@ -5,6 +5,7 @@ SELECT (geocode_namedplace(Array['sunapee', 'sunapeeee', 'New York City', 'Madri
|
||||
SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array['Maine', 'Oregon', NULL], 'USA')).*;
|
||||
SELECT (geocode_namedplace(Array['Portland'], 'Oregon', 'USA')).*;
|
||||
SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array['Maine', 'Oregon', NULL], Array['USA'])).*;
|
||||
SELECT namedplace_guess_country(Array['granada', 'jaen', 'cordoba', 'madrid', 'valladolid']);
|
||||
|
||||
-- Add a named place source
|
||||
COPY global_cities_alternates_limited (geoname_id, name, the_geom, created_at, updated_at, the_geom_webmercator, preferred, lowername, cartodb_id, admin1_geonameid, iso2, admin1) FROM stdin;
|
||||
@@ -16,5 +17,6 @@ COPY global_cities_points_limited (geoname_id, name, asciiname, altnames, featcl
|
||||
\.
|
||||
|
||||
-- Check that the geocoding function is callable, should return success = true
|
||||
SELECT (geocode_namedplace(Array['Barcelona'])).*
|
||||
SELECT (geocode_namedplace(Array['Barcelona'])).*;
|
||||
SELECT namedplace_guess_country(Array['Barcelona']);
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
-- Return a guess about the country where the places are located, if possible.
|
||||
-- E.g: SELECT namedplace_guess_country(Array['granada', 'jaen', 'cordoba', 'madrid', 'valladolid']); => NULL
|
||||
-- E.g: SELECT namedplace_guess_country(Array['granada', 'jaén', 'córdoba', 'madrid', 'valladolid', 'peligros'])); => 'ES'
|
||||
CREATE OR REPLACE FUNCTION namedplace_guess_country(places text[])
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
country_code text;
|
||||
threshold CONSTANT float := 0.8;
|
||||
input_length integer := array_length(places, 1);
|
||||
BEGIN
|
||||
BEGIN
|
||||
WITH hist AS (
|
||||
SELECT count(DISTINCT(lower(p.s), gp.iso2)) AS c, iso2
|
||||
FROM global_cities_points_limited gp
|
||||
inner join (SELECT unnest(places) AS s) p
|
||||
ON (gp.lowername = lower(s))
|
||||
GROUP BY iso2
|
||||
),
|
||||
best_two AS (
|
||||
SELECT iso2, c
|
||||
FROM hist
|
||||
WHERE c > input_length * threshold
|
||||
ORDER BY c DESC
|
||||
LIMIT 2
|
||||
)
|
||||
SELECT iso2 INTO STRICT country_code
|
||||
FROM (SELECT iso2, c, max(c) over() AS maxcount FROM best_two) bt
|
||||
WHERE bt.c = bt.maxcount;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND OR too_many_rows THEN
|
||||
RETURN NULL;
|
||||
END;
|
||||
RETURN country_code;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER IMMUTABLE;
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user