From 90c32ddc6362f7085a23a4db329ecbc7bc366ee6 Mon Sep 17 00:00:00 2001 From: Mathis ROUILLARD <119948655+MatRouillard@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:10:03 +0900 Subject: [PATCH] Add SQL folder to fix dev branch --- SQL/buildings/create_tables.sql | 166 +++++++++++++++++++++++++++ SQL/buildings/download_import_ovt.sh | 51 ++++++++ SQL/buildings/import_osm_tsv.sh | 28 +++++ SQL/readme.md | 24 ++++ 4 files changed, 269 insertions(+) create mode 100644 SQL/buildings/create_tables.sql create mode 100644 SQL/buildings/download_import_ovt.sh create mode 100644 SQL/buildings/import_osm_tsv.sh create mode 100644 SQL/readme.md diff --git a/SQL/buildings/create_tables.sql b/SQL/buildings/create_tables.sql new file mode 100644 index 0000000..17de207 --- /dev/null +++ b/SQL/buildings/create_tables.sql @@ -0,0 +1,166 @@ +drop table ovt.tokyo_bld; +create table ovt.tokyo_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50) +) +; + +drop table ovt.hamamatsu_bld; +create table ovt.hamamatsu_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50)) +; + +drop table ovt.tateyama_bld; +create table ovt.tateyama_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50) +) +; + +drop table ovt.kumamoto_bld; +create table ovt.kumamoto_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50) +) +; + +drop table ovt.higashi_hiroshima_bld; +create table ovt.higashi_hiroshima_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50) +) +; + +drop table ovt.morioka_bld; +create table ovt.morioka_bld ( + ogc_fid integer, + wkb_geometry geometry(MULTIPOLYGON, 4326), + id varchar, + version integer, + update_time timestamp with time zone, + sources json, + subtype varchar, + names json, + class varchar, + level integer, + has_parts boolean, + height double precision, + min_height double precision, + num_floors integer, + facade_color varchar, + facade_material varchar, + min_floor integer, + roof_material varchar, + roof_shape varchar, + roof_direction double precision, + roof_orientation varchar, + roof_color varchar, + area_name char(50) +) +; diff --git a/SQL/buildings/download_import_ovt.sh b/SQL/buildings/download_import_ovt.sh new file mode 100644 index 0000000..da84737 --- /dev/null +++ b/SQL/buildings/download_import_ovt.sh @@ -0,0 +1,51 @@ +# It will takes 25 minutes to process 5 areas +# Initialize the command in seconds. +SECONDS=0 + +# move to working directory +SCRIPT_DIR=$(cd $(dirname $0); pwd) +cd "${SCRIPT_DIR}" + +mkdir ./data/202405/overturemaps/ + +psql -U postgres -d postgres -c "create schema ovt;" + +psql -U postgres -d postgres -c "drop table if exists ovt.hamamatsu_bld;" +psql -U postgres -d postgres -c "drop table if exists ovt.tokyo_bld;" +psql -U postgres -d postgres -c "drop table if exists ovt.tateyama_bld;" +psql -U postgres -d postgres -c "drop table if exists ovt.kumamoto_bld;" +psql -U postgres -d postgres -c "drop table if exists ovt.higashi_hiroshima_bld;" +psql -U postgres -d postgres -c "drop table if exists ovt.morioka_bld;" + +psql -U postgres -d postgres -f ./create_tables.sql + +# Tokyo +overturemaps download --bbox=139.74609375,35.67514744,139.83398438,35.74651226 -f geojson --type=building -o ./data/202405/overturemaps/tokyo.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.tokyo_bld -nlt multipolygon ./data/202405/overturemaps/tokyo.geojson + +# Hamamatsu +overturemaps download --bbox=137.63671875,34.66935855,137.72460938,34.7416125 -f geojson --type=building -o ./data/202405/overturemaps/hamamatsu.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.hamamatsu_bld -nlt multipolygon ./data/202405/overturemaps/hamamatsu.geojson + +# Tateyama +overturemaps download --bbox=139.83398438,34.95799531,139.921875,35.02999637 -f geojson --type=building -o ./data/202405/overturemaps/tateyama.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.tateyama_bld -nlt multipolygon ./data/202405/overturemaps/tateyama.geojson + +# Kumamoto +overturemaps download --bbox=130.68726409,32.72948989,130.77515472,32.80174385 -f geojson --type=building -o ./data/202405/overturemaps/kumamoto.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.kumamoto_bld -nlt multipolygon ./data/202405/overturemaps/kumamoto.geojson + +# Higashi_hiroshima +overturemaps download --bbox=132.69418348,34.38622724,132.7820741,34.45848119 -f geojson --type=building -o ./data/202405/overturemaps/higashi_hiroshima.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.higashi_hiroshima_bld -nlt multipolygon ./data/202405/overturemaps/higashi_hiroshima.geojson + +# Morioka +overturemaps download --bbox=141.07765453,39.6823863,141.16554516,39.75375112 -f geojson --type=building -o ./data/202405/overturemaps/morioka.geojson +ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln ovt.morioka_bld -nlt multipolygon ./data/202405/overturemaps/morioka.geojson + + +# Display the measurement time. +time=$SECONDS +((sec=time%60, min=(time%3600)/60, hrs=time/3600)) +timestamp=$(printf "%d:%02d:%02d" "$hrs" "$min" "$sec") +echo "Processing time is $timestamp" diff --git a/SQL/buildings/import_osm_tsv.sh b/SQL/buildings/import_osm_tsv.sh new file mode 100644 index 0000000..7a24254 --- /dev/null +++ b/SQL/buildings/import_osm_tsv.sh @@ -0,0 +1,28 @@ +#!/bin/bash -e + +# Initialize the command in seconds. +SECONDS=0 + +psql -U postgres -d postgres -c "create schema osm;" + +psql -U postgres -d postgres -c "drop table if exists osm.tokyo_bld;" +psql -U postgres -d postgres -c "drop table if exists osm.tateyama_bld;" +psql -U postgres -d postgres -c "drop table if exists osm.hamamatsu_bld;" +psql -U postgres -d postgres -c "drop table if exists osm.kumamoto_bld;" +psql -U postgres -d postgres -c "drop table if exists osm.higashi_hiroshima_bld;" +psql -U postgres -d postgres -c "drop table if exists osm.morioka_bld;" + +psql -U postgres -d postgres -c "create table osm.tokyo_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" +psql -U postgres -d postgres -c "create table osm.tateyama_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" +psql -U postgres -d postgres -c "create table osm.hamamatsu_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" +psql -U postgres -d postgres -c "create table osm.kumamoto_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" +psql -U postgres -d postgres -c "create table osm.higashi_hiroshima_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" +psql -U postgres -d postgres -c "create table osm.morioka_bld(area_id bigint, id bigint, geom geometry(MultiPolygon,4326));" + +psql -U postgres -d postgres -c "\copy osm.tokyo_bld from './data/202405/osm/osm_building_tokyo.tsv' delimiter E'\t' csv;" +psql -U postgres -d postgres -c "\copy osm.tateyama_bld from './data/202405/osm/osm_building_tateyama.tsv' delimiter E'\t' csv;" +psql -U postgres -d postgres -c "\copy osm.hamamatsu_bld from './data/202405/osm/osm_building_hamamatsu.tsv' delimiter E'\t' csv;" +psql -U postgres -d postgres -c "\copy osm.kumamoto_bld from './data/202405/osm/osm_building_kumamoto.tsv' delimiter E'\t' csv;" +psql -U postgres -d postgres -c "\copy osm.higashi_hiroshima_bld from './data/202405/osm/osm_building_higashi_hiroshima.tsv' delimiter E'\t' csv;" +psql -U postgres -d postgres -c "\copy osm.morioka_bld from './data/202405/osm/osm_building_morioka.tsv' delimiter E'\t' csv;" + diff --git a/SQL/readme.md b/SQL/readme.md new file mode 100644 index 0000000..1e6dde0 --- /dev/null +++ b/SQL/readme.md @@ -0,0 +1,24 @@ +# Buildings + +## Overture Maps + +Install a CLI tool to download Overture Maps data. + +``` +pip install overturemaps +``` + +Run the following code and it will download buildings in target areas from Overture Maps and import them into PostgreSQL. + +``` +bash buildings/download_import_ovt.sql +``` + +## OpenStreetMap + +This script just import tsv files into PostgreSQL. +You need to extract data before running this script. + +``` +bash building/import_osm_tsv.shcd . +```