Skip to content

Commit

Permalink
Merge pull request #14 from LocationMind/fix-buildings-poi
Browse files Browse the repository at this point in the history
Add SQL folder to fix dev branch
  • Loading branch information
MatRouillard authored Jul 31, 2024
2 parents 1be2e68 + 90c32dd commit 1486399
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 0 deletions.
166 changes: 166 additions & 0 deletions SQL/buildings/create_tables.sql
Original file line number Diff line number Diff line change
@@ -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)
)
;
51 changes: 51 additions & 0 deletions SQL/buildings/download_import_ovt.sh
Original file line number Diff line number Diff line change
@@ -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"
28 changes: 28 additions & 0 deletions SQL/buildings/import_osm_tsv.sh
Original file line number Diff line number Diff line change
@@ -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;"

24 changes: 24 additions & 0 deletions SQL/readme.md
Original file line number Diff line number Diff line change
@@ -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 .
```

0 comments on commit 1486399

Please sign in to comment.