From: Nicolas Boisselier Date: Sat, 6 Jan 2018 06:01:45 +0000 (+0000) Subject: lib/postgres/geo.sql X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=83a121c60fb22fba1d1129c8e237c6a6752a761a;p=nb.git lib/postgres/geo.sql --- diff --git a/lib/postgres/continent.sql b/lib/postgres/continent.sql index 2f458c3f..e420499c 100644 --- a/lib/postgres/continent.sql +++ b/lib/postgres/continent.sql @@ -6,5 +6,9 @@ CREATE TABLE IF NOT EXISTS continent ( ); BEGIN TRANSACTION; DELETE FROM continent; -COPY continent FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/readme.txt | awk "/^Continent codes/ {ok=1} ok==1 && /^$/{exit} ok==1 {print \$0}" | tail -n +2 | sed -e "s/ : /\t/" -e "s/[\t ]\+geonameId=/\t/"' WITH (format 'text', NULL ''); +COPY continent FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/readme.txt \ +| awk "/^Continent codes/ {ok=1} ok==1 && /^$/{exit} ok==1 {print \$0}" \ +| tail -n +2 \ +| sed -e "s/ : /\t/" -e "s/[\t ]\+geonameId=/\t/" \ +' WITH (format 'text', NULL ''); COMMIT; diff --git a/lib/postgres/geo.sql b/lib/postgres/geo.sql index c4f37a09..8c892c5f 100644 --- a/lib/postgres/geo.sql +++ b/lib/postgres/geo.sql @@ -25,8 +25,9 @@ CREATE TABLE geo ( altnames varchar(10000), latitude numeric(7,4), longitude numeric(7,4), - feature_class char(1), - feature_code varchar(10), +-- NB 06.01.18 feature_class char(1), +-- NB 06.01.18 feature_code varchar(10), + feature varchar(10), country char(2), cc2 varchar(200), -- NB 06.01.18 admin1 varchar(20), @@ -43,5 +44,10 @@ CREATE INDEX IF NOT EXISTS geo_country_idx ON geo (country); BEGIN TRANSACTION; DELETE FROM geo; -- NB 06.01.18 COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat' WITH (format 'text', NULL ''); -COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat | cut -f -10,15-' WITH (format 'text', NULL ''); +-- NB 06.01.18 COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat | cut -f -10,15-' WITH (format 'text', NULL ''); +COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip \ +| zcat \ +| awk "{\$7=\$7\".\"\$8;print}" FS="\t" OFS="\t" \ +| cut -f -7,9-10,15- +' WITH (format 'text', NULL ''); COMMIT; diff --git a/lib/postgres/geofeature.sql b/lib/postgres/geofeature.sql index dec6c0b3..41aee382 100644 --- a/lib/postgres/geofeature.sql +++ b/lib/postgres/geofeature.sql @@ -7,5 +7,12 @@ CREATE TABLE geofeature ( -- CREATE INDEX IF NOT EXISTS geofeature_country_idx ON geofeature (country); BEGIN TRANSACTION; DELETE FROM geofeature; -COPY geofeature FROM PROGRAM 'curl -s http://www.geonames.org/export/codes.html | tr -d "\n" | sed "s/<.tr>/\n/g" | grep "]*> *)/\t/g" -e "s/^.*?=.([A-Z0-9\.]*)[^\t]+\t/\1/" -e "s/\t+/\t/g" | cut -f 1-3 | grep -v "not available"' WITH (format 'text', NULL ''); +COPY geofeature FROM PROGRAM 'curl -s http://www.geonames.org/export/codes.html \ +| tr -d "\n" \ +| sed "s/<.tr>/\n/g" \ +| grep "]*> *)/\t/g" -e "s/^.*?=.([A-Z0-9\.]*)[^\t]+\t/\1/" -e "s/\t+/\t/g" \ +| cut -f 1-3 \ +| grep -v "not available" +' WITH (format 'text', NULL ''); COMMIT;