Project

General

Profile

« Previous | Next » 

Revision 10389

inputs/.geoscrub/geoscrub_output/: translated single-column filters to postprocessing derived columns, using the steps at wiki.vegpath.org/Adding_new-style_import_to_a_datasource#Translating-filters-to-postprocessing-derived-columns

View differences:

postprocess.sql
1 1
SELECT util.search_path_append('util');
2 2

  
3
-- runtime: 25 s ("real 0m21.770s")
3
-- runtime: 40 s ("real 0m21.770s" + "Time: 17304.769 ms") @starscream
4 4
SELECT set_col_types(:table_str, ARRAY[
5
  ('decimallatitude', 'double precision')
6
, ('decimallongitude', 'double precision')
5
  ('decimallatitude'      , 'double precision')
6
, ('decimallongitude'     , 'double precision')
7
, ('latlonvalidity'       , 'integer')
8
, ('countryvalidity'      , 'integer')
9
, ('stateprovincevalidity', 'integer')
10
, ('countyvalidity'       , 'integer')
7 11
]::col_cast[]);
8 12

  
9 13
ALTER TABLE :table ALTER COLUMN decimallatitude SET NOT NULL;
......
11 15

  
12 16
-- runtime: 55 s ("real 0m53.677s")
13 17
SELECT create_if_not_exists($$CREATE INDEX geoscrub_output_input ON geoscrub_output (decimallatitude, decimallongitude, country, stateprovince, county)$$);
18

  
19

  
20
-- map_*() derived cols
21
-- runtime: 2 min @starscream
22

  
23
CREATE OR REPLACE FUNCTION map_coord_validity(value integer)
24
  RETURNS boolean AS
25
$BODY$
26
/*
27
"For latlonvalidity:
28
-1: Latitude and/or longitude is null
29
 0: Coordinate is not a valid geographic location
30
 1: Coordinate is a valid geographic location
31
" (http://vegpath.org/fs/inputs/.geoscrub/_src/README.TXT)
32
*/
33
SELECT util._map('-1=>NULL, 0=>false, 1=>true', $1::text)::boolean
34
$BODY$
35
  LANGUAGE sql IMMUTABLE
36
  COST 100;
37

  
38
SELECT mk_derived_col((:table_str, 'latLongDomainValid'), $$map_coord_validity("latlonvalidity")$$); -- runtime: 25 s ("Time: 26708.932 ms") @starscream
39

  
40
CREATE OR REPLACE FUNCTION map_geovalidity(value integer)
41
  RETURNS boolean AS
42
$BODY$
43
/*
44
"For countryvalidity/stateprovincevalidity/countyvalidity:
45
-1: Name is null at this or some higher level
46
 0: Complete name provided, but couldn't be scrubbed to GADM
47
 1: Point is >5km from putative GADM polygon
48
 2: Point is <=5km from putative GADM polygon, but still outside it
49
 3: Point is in (or on border of) putative GADM polygon
50
" (http://vegpath.org/fs/inputs/.geoscrub/_src/README.TXT)
51
*/
52
SELECT util._map('-1=>NULL, 0=>NULL, 1=>false, 2=>true, 3=>true', $1::text)::boolean
53
$BODY$
54
  LANGUAGE sql IMMUTABLE
55
  COST 100;
56

  
57
SELECT mk_derived_col((:table_str, 'latLongInCountry'      ), $$map_geovalidity("countryvalidity"      )$$); -- runtime: 25 s ("Time: 27884.129 ms") @starscream
58
SELECT mk_derived_col((:table_str, 'latLongInStateProvince'), $$map_geovalidity("stateprovincevalidity")$$); -- runtime: 25 s ("Time: 27228.239 ms") @starscream
59
SELECT mk_derived_col((:table_str, 'latLongInCounty'       ), $$map_geovalidity("countyvalidity"       )$$); -- runtime: 25 s ("Time: 27337.520 ms") @starscream

Also available in: Unified diff