Skip to content

Commit

Permalink
fix osm script
Browse files Browse the repository at this point in the history
  • Loading branch information
ke-lm committed Jul 30, 2024
1 parent 2a1f29a commit eb27545
Show file tree
Hide file tree
Showing 47 changed files with 648 additions and 498 deletions.
2 changes: 1 addition & 1 deletion Bash/OMF/ETL/omf_import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "Change psql user(-U) or database(-d) if threre is error about postgres"
psql -U postgres -d postgres -c "create schema omf;"

# create table
psql -U postgres -d postgres -f ./create_tables_$TYPE.sql
psql -U postgres -d postgres -f "$SCRIPT_DIR/sql/create_tables_$TYPE.sql"

# Tokyo
ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=postgres" -nln omf.tokyo_$TYPE -nlt multipolygon $DATA_DIR/tokyo_$TYPE.geojson
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions Bash/OMF/overturemaps-py
Submodule overturemaps-py added at 5148bf
10 changes: 10 additions & 0 deletions Bash/OSM/Analyze/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# postgres
POSTGRES_USER=postgres
POSTGRES_DATABASE=postgres

# define cities
cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
city_labels=("Tokyo" "Tateyama" "Hmaamatsu" "Higashi-hiroshima" "Kumamoto" "Morioka") ## becase of shape file 'Hmaamatsu'

24 changes: 24 additions & 0 deletions Bash/OSM/Analyze/copy_building_tags_cnt_to_tsv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

for city in "${cities[@]}"; do
echo $city
sql="\copy (
select
building,
count(*) as cnt
from osm.building_$city
group by
building
order by
cnt desc
) to '$SCRIPT_DIR/tsv/osm_building_cnt_$city.tsv'
with csv delimiter E'\t';"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"
done
17 changes: 17 additions & 0 deletions Bash/OSM/Analyze/copy_building_tags_to_tsv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

sql="\copy (
select
distinct building
from osm.building
order by building
) to '$SCRIPT_DIR/tsv/osm_building_distinct_tag.tsv'
with csv delimiter E'\t';"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"
20 changes: 17 additions & 3 deletions Bash/OSM/Analyze/copy_building_to_tsv.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
#!/bin/bash

cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

for city in "${cities[@]}"; do
echo $city
sql="\copy (select area_id, id, ST_AsText(geom)from building_$city) to '~/tsv/osm_building_$city.tsv' with csv delimiter E'\t';"
psql -d shimazaki -U postgres -c "$sql"
sql="\copy (
select
area_id,
id,
ST_AsText(geom),
building,
height
from osm.building_$city
) to '$SCRIPT_DIR/tsv/osm_building_$city.tsv'
with csv delimiter E'\t';"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"
done
17 changes: 11 additions & 6 deletions Bash/OSM/Analyze/copy_poi_cnt_to_tsv.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/bin/bash

cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

for city in "${cities[@]}"; do
echo $city
sql="\copy (
select
class, subclass, count(*) as subclass_cnt
from poi_$city
from osm.poi_$city
group by class, subclass
order by class, subclass_cnt desc)
to '~/osm/tsv/poi_cnt_$city.tsv'
with csv delimiter E'\t';
order by class, subclass_cnt desc
) to '$SCRIPT_DIR/tsv/osm_poi_cnt_$city.tsv'
with csv delimiter E'\t';
"
psql -d shimazaki -U postgres -c "$sql"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"
done
13 changes: 9 additions & 4 deletions Bash/OSM/Analyze/copy_poi_to_tsv.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash

cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

for city in "${cities[@]}"; do
echo $city
Expand All @@ -12,7 +17,7 @@ for city in "${cities[@]}"; do
class ,
subclass ,
ST_AsText(geom)
from poi_$city
) to '~/tsv/osm_poi_$city.tsv' with csv delimiter E'\t';"
psql -d shimazaki -U postgres -c "$sql"
from osm.poi_$city
) to '$SCRIPT_DIR/tsv/osm_poi_$city.tsv' with csv delimiter E'\t';"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"
done
9 changes: 0 additions & 9 deletions Bash/OSM/Analyze/copy_tags_cnt_to_tsv.sh

This file was deleted.

4 changes: 0 additions & 4 deletions Bash/OSM/Analyze/copy_tags_to_tsv.sh

This file was deleted.

21 changes: 21 additions & 0 deletions Bash/OSM/Analyze/count_building_height.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

cnt=0
for city in "${cities[@]}"; do
echo $city
sql="
select
count(height) as cnt_height
from osm.building_$city
"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"

((cnt++))
done
19 changes: 0 additions & 19 deletions Bash/OSM/Analyze/count_height.sh

This file was deleted.

28 changes: 15 additions & 13 deletions Bash/OSM/Analyze/count_poi_amenity_shop.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash

cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
city_labels=("Tokyo" "Tateyama" "Hamamatsu" "Higashi-hiroshima" "Kumamoto" "Morioka")
# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

cnt=0
for city in "${cities[@]}"; do
echo $city
city_lable="$city_labels[$cnt]"

echo $city
sql="
select
name,
Expand All @@ -16,27 +18,27 @@ for city in "${cities[@]}"; do
select
'poi_cnt' as name,
count(*) as cnt
from poi_$city
from osm.poi_$city
union
select
select
'poi_amenity_cnt' as name,
count(*) as cnt
from poi_$city
count(*) as cnt
from osm.poi_$city
where class='amenity'
union
select
'poi_shop_cnt' as name,
count(*) as cnt
from poi_$city
where class='shop'
count(*) as cnt
from osm.poi_$city
where class='shop'
) a
order by name
"
psql -d shimazaki -U postgres -c "$sql"
psql -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql"

((cnt++))
done
17 changes: 10 additions & 7 deletions Bash/OSM/Analyze/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/bin/bash

cities=("tokyo" "tateyama" "hamamatsu" "higashi_hiroshima" "kumamoto" "morioka")
city_labels=("Tokyo" "Tateyama" "Hamamatsu" "Higashi-hiroshima" "Kumamoto" "Morioka")
# move to working directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
cd "${SCRIPT_DIR}"

# set config
source config.sh

cnt=0
for city in "${cities[@]}"; do
echo $city
city_lable="$city_labels[$cnt]"

sql="select sum(ST_Area(building_$city.geom::geography)) / 1000000 from building_$city"
building_area=$(psql -t -d shimazaki -U postgres -c "$sql")
sql="select sum(ST_Area(building_$city.geom::geography)) / 1000000 from osm.building_$city"
building_area=$(psql -t -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql")
echo $building_area

sql="select ST_Area(geom::geography) / 1000000 from shape where name='${city_labels[$cnt]}'"
whole_area=$(psql -t -d shimazaki -U postgres -c "$sql")
sql="select ST_Area(geom::geography) / 1000000 from osm.shape where name='${city_labels[$cnt]}'"
whole_area=$(psql -t -d $POSTGRES_DATABASE -U $POSTGRES_USER -c "$sql")
echo $whole_area

echo "scale=5; $building_area / $whole_area * 100" | bc
Expand Down
16 changes: 16 additions & 0 deletions Bash/OSM/Analyze/sql/building2tsv.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
copy (
select
area_id,
id,
ST_asText (geom),
building,
height
from
osm.building
where
area_id is not null
and geom is not null
order by
area_id
)
to STDOUT with csv header delimiter E'\t' \g '../tsv/building.tsv'
2 changes: 0 additions & 2 deletions Bash/OSM/Analyze/sql/copy_building_from_tsv.sql

This file was deleted.

42 changes: 0 additions & 42 deletions Bash/OSM/Analyze/sql/create_table_building.sql

This file was deleted.

Loading

0 comments on commit eb27545

Please sign in to comment.