Last active
August 6, 2020 15:00
-
-
Save JhoLee/29910ce32a6f843b045cfe0e848c89f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension hstore; | |
create table if not exists planet_osm_line | |
( | |
osm_id bigint, | |
access text, | |
"addr:housename" text, | |
"addr:housenumber" text, | |
"addr:interpolation" text, | |
admin_level text, | |
aerialway text, | |
aeroway text, | |
amenity text, | |
barrier text, | |
bicycle text, | |
bridge text, | |
boundary text, | |
building text, | |
construction text, | |
covered text, | |
foot text, | |
highway text, | |
historic text, | |
horse text, | |
junction text, | |
landuse text, | |
layer integer, | |
leisure text, | |
lock text, | |
man_made text, | |
military text, | |
name text, | |
"natural" text, | |
oneway text, | |
place text, | |
power text, | |
railway text, | |
ref text, | |
religion text, | |
route text, | |
service text, | |
shop text, | |
surface text, | |
tourism text, | |
tracktype text, | |
tunnel text, | |
water text, | |
waterway text, | |
way_area real, | |
z_order integer, | |
tags hstore, | |
way geometry(LineString,3857) | |
); | |
alter table planet_osm_line owner to DB_USER; | |
create table if not exists planet_osm_nodes | |
( | |
id bigint not null | |
constraint planet_osm_nodes_pkey | |
primary key, | |
lat integer not null, | |
lon integer not null | |
); | |
alter table planet_osm_nodes owner to DB_USER; | |
create table if not exists planet_osm_point | |
( | |
osm_id bigint, | |
access text, | |
"addr:housename" text, | |
"addr:housenumber" text, | |
admin_level text, | |
aerialway text, | |
aeroway text, | |
amenity text, | |
barrier text, | |
boundary text, | |
building text, | |
highway text, | |
historic text, | |
junction text, | |
landuse text, | |
layer integer, | |
leisure text, | |
lock text, | |
man_made text, | |
military text, | |
name text, | |
"natural" text, | |
oneway text, | |
place text, | |
power text, | |
railway text, | |
ref text, | |
religion text, | |
shop text, | |
tourism text, | |
water text, | |
waterway text, | |
tags hstore, | |
way geometry(Point,3857) | |
); | |
alter table planet_osm_point owner to DB_USER; | |
create table if not exists planet_osm_polygon | |
( | |
osm_id bigint, | |
access text, | |
"addr:housename" text, | |
"addr:housenumber" text, | |
"addr:interpolation" text, | |
admin_level text, | |
aerialway text, | |
aeroway text, | |
amenity text, | |
barrier text, | |
bicycle text, | |
bridge text, | |
boundary text, | |
building text, | |
construction text, | |
covered text, | |
foot text, | |
highway text, | |
historic text, | |
horse text, | |
junction text, | |
landuse text, | |
layer integer, | |
leisure text, | |
lock text, | |
man_made text, | |
military text, | |
name text, | |
"natural" text, | |
oneway text, | |
place text, | |
power text, | |
railway text, | |
ref text, | |
religion text, | |
route text, | |
service text, | |
shop text, | |
surface text, | |
tourism text, | |
tracktype text, | |
tunnel text, | |
water text, | |
waterway text, | |
way_area real, | |
z_order integer, | |
tags hstore, | |
way geometry(Geometry,3857) | |
); | |
alter table planet_osm_polygon owner to DB_USER; | |
create table if not exists planet_osm_rels | |
( | |
id bigint not null | |
constraint planet_osm_rels_pkey | |
primary key, | |
way_off smallint, | |
rel_off smallint, | |
parts bigint[], | |
members text[], | |
tags text[] | |
); | |
alter table planet_osm_rels owner to DB_USER; | |
create table if not exists planet_osm_roads | |
( | |
osm_id bigint, | |
access text, | |
"addr:housename" text, | |
"addr:housenumber" text, | |
"addr:interpolation" text, | |
admin_level text, | |
aerialway text, | |
aeroway text, | |
amenity text, | |
barrier text, | |
bicycle text, | |
bridge text, | |
boundary text, | |
building text, | |
construction text, | |
covered text, | |
foot text, | |
highway text, | |
historic text, | |
horse text, | |
junction text, | |
landuse text, | |
layer integer, | |
leisure text, | |
lock text, | |
man_made text, | |
military text, | |
name text, | |
"natural" text, | |
oneway text, | |
place text, | |
power text, | |
railway text, | |
ref text, | |
religion text, | |
route text, | |
service text, | |
shop text, | |
surface text, | |
tourism text, | |
tracktype text, | |
tunnel text, | |
water text, | |
waterway text, | |
way_area real, | |
z_order integer, | |
tags hstore, | |
way geometry(LineString,3857) | |
); | |
alter table planet_osm_roads owner to DB_USER; | |
create table if not exists planet_osm_ways | |
( | |
id bigint not null | |
constraint planet_osm_ways_pkey | |
primary key, | |
nodes bigint[] not null, | |
tags text[] | |
); | |
alter table planet_osm_ways owner to DB_USER; | |
create table if not exists planet_osm_ways | |
( | |
id bigint not null | |
constraint planet_osm_ways_pkey | |
primary key, | |
nodes bigint[] not null, | |
tags text[] | |
); | |
alter table planet_osm_ways owner to DB_USER; | |
create table if not exists spatial_ref_sys | |
( | |
srid integer not null | |
constraint spatial_ref_sys_pkey | |
primary key | |
constraint spatial_ref_sys_srid_check | |
check ((srid > 0) AND (srid <= 998999)), | |
auth_name varchar(256), | |
auth_srid integer, | |
srtext varchar(2048), | |
proj4text varchar(2048) | |
); | |
alter table spatial_ref_sys owner to DB_USER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import shutil | |
import tempfile | |
def get_environ(key): | |
try: | |
return os.environ[key] | |
except KeyError as e: | |
return None | |
SQL_DIR = '/config/docker' | |
SQL_PATHS = [os.path.join(SQL_DIR, name) for name in os.listdir(SQL_DIR) if '.sql' in name] | |
DB_USER = get_environ("DB_USER") | |
DB_USER = DB_USER if DB_USER is not None else "postgres" | |
for sqls in SQL_PATHS: | |
f_old = open(sqls, 'r') | |
with tempfile.NamedTemporaryFile(mode='w') as tmp_f: | |
for line in f_old: | |
line = line.replace('DB_USER', DB_USER) | |
tmp_f.write(line) | |
f_old.close() | |
tmp_f.flush() | |
os.fsync(tmp_f) | |
shutil.copy2(tmp_f.name, sqls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export PGPASSWORD=$DB_PASSWORD | |
/config/docker/init_sql.py | |
echo "iniiit" | |
#SQL_LIST=($(ls /config/docker/osm-ddl/*.sql*)) | |
#count=1 | |
#for f in $SQL_LIST; do | |
echo "[O2P] ${count}/${#SQL_LIST[@]} Creating table... " | |
psql \ | |
-h $DB_HOST \ | |
-p $DB_PORT \ | |
-d $DB_NAME \ | |
-U $DB_USER \ | |
-f /config/docker/init_osm.sql | |
count=$((count+1)) | |
#done | |
echo "[O2P] Creating tables done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment