Project

General

Profile

1
/*
2
  SQL statements to generate tables mapping geonames features at each
3
  relevant administative level (country, state/province, county/parish)
4
  to GADM2 features.
5

    
6
  Todo:
7
  * Be tolerant to presence/absence of administrative qualifiers in
8
    names? (Already doing this mildly for County/Co/Co.)
9
    - Municipality
10
    - Barrio
11
    - District
12

    
13
  * Get rid of rudundancy
14
  * Try matching against GADM2 varname_* columns?
15

    
16
  Jim Regetz
17
  NCEAS
18
  Created Nov 2012
19
*/
20

    
21
-----------------------
22
-- Level 0 (Country) --
23
-----------------------
24
BEGIN;
25

    
26
TRUNCATE gadm_country_lookup;
27

    
28
DROP INDEX IF EXISTS "gadm_country_lookup_name_0_idx";
29

    
30
-- map gadm2 level0 to geonames countries
31
INSERT INTO gadm_country_lookup (countryid)
32
  SELECT DISTINCT geonameid
33
    FROM countries
34
    WHERE geonameid IS NOT NULL;
35
-- INSERT 0 250
36
-- Time: 20.770 ms
37
-- EXPLAIN ANALYZE 
38
UPDATE gadm_country_lookup lu
39
  SET name_0 = gadm.name_0
40
  FROM (SELECT DISTINCT iso, name_0 FROM gadm2) gadm,
41
       countries c
42
  WHERE lu.countryid = c.geonameid
43
    AND c.iso3 = gadm.iso;
44
-- UPDATE 248
45
-- Time: 3562.601 ms
46

    
47
CREATE INDEX "gadm_country_lookup_name_0_idx" ON gadm_country_lookup (name_0);
48

    
49
COMMIT;
50

    
(4-4/27)