Skip to content

Commit

Permalink
Merge pull request #248 from rustprooflabs/dev
Browse files Browse the repository at this point in the history
Merge development into main
  • Loading branch information
rustprooflabs authored Apr 16, 2022
2 parents 12edff2 + 086b5c7 commit 517e508
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 40 deletions.
15 changes: 11 additions & 4 deletions docker/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def connection_string(admin=False):
pg_pass = pg_details['pg_pass']
pg_host = pg_details['pg_host']
pg_db = pg_details['pg_db']
pg_port = pg_details['pg_port']

if admin:
if pg_host == 'localhost':
Expand All @@ -53,9 +54,9 @@ def connection_string(admin=False):
db_name = pg_db

if pg_pass is None:
conn_string = f'postgresql://{pg_user}@{pg_host}/{db_name}{app_str}'
conn_string = f'postgresql://{pg_user}@{pg_host}:{pg_port}/{db_name}{app_str}'
else:
conn_string = f'postgresql://{pg_user}:{pg_pass}@{pg_host}/{db_name}{app_str}'
conn_string = f'postgresql://{pg_user}:{pg_pass}@{pg_host}:{pg_port}/{db_name}{app_str}'

return conn_string

Expand Down Expand Up @@ -87,7 +88,13 @@ def pg_conn_parts():
pg_host = 'localhost'
LOGGER.debug(f'POSTGRES_HOST not configured. Defaulting to {pg_host}')

LOGGER.debug(f'PG Host: {pg_host}')
try:
pg_port = os.environ['POSTGRES_PORT']
except KeyError:
pg_port = '5432'
LOGGER.debug(f'POSTGRES_HOST not configured. Defaulting to {pg_port}')

LOGGER.debug(f'PG Host: {pg_host} -- Port: {pg_port}')

default_db = 'pgosm'
pg_db = None
Expand All @@ -111,6 +118,7 @@ def pg_conn_parts():
pg_details = {'pg_user': pg_user,
'pg_pass': pg_pass,
'pg_host': pg_host,
'pg_port': pg_port,
'pg_db': pg_db}

return pg_details
Expand Down Expand Up @@ -554,7 +562,6 @@ def run_pg_dump(export_path, data_only, schema_name):
schema_name : str
"""
logger = logging.getLogger('pgosm-flex')
db_name = os.environ['POSTGRES_DB']
conn_string = os.environ['PGOSM_CONN']

if data_only:
Expand Down
2 changes: 2 additions & 0 deletions docs/DOCKER-RUN.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export POSTGRES_USER=your_login_role
export POSTGRES_PASSWORD=mysecretpassword
export POSTGRES_HOST=your-host-or-ip
export POSTGRES_DB=your_db_name
export POSTGRES_PORT=5432
```
Run the container with the additional environment variables.
Expand All @@ -306,6 +307,7 @@ docker run --name pgosm -d --rm \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-e POSTGRES_HOST=$POSTGRES_HOST \
-e POSTGRES_DB=$POSTGRES_DB \
-e POSTGRES_PORT=$POSTGRES_PORT \
-p 5433:5432 -d rustprooflabs/pgosm-flex
```
Expand Down
3 changes: 3 additions & 0 deletions flex-config/style/building.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function address_only_building(tags)
or tags.office
or tags.tourism
or tags.boundary -- included in place layer
or tags.natural
or tags.aeroway
or tags.demolished
then
return false
end
Expand Down
73 changes: 41 additions & 32 deletions flex-config/style/infrastructure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,51 +64,60 @@ tables.infrastructure_polygon = osm2pgsql.define_table({
}
})

local function get_osm_type_subtype(object)
local function get_osm_type_subtype(tags)
local osm_type_table = {}

if object.tags.amenity == 'fire_hydrant'
or object.tags.emergency == 'fire_hydrant' then
osm_type_table['osm_type'] = 'fire_hydrant'
osm_type_table['osm_subtype'] = nil
elseif object.tags.amenity == 'emergency_phone'
or object.tags.emergency == 'phone' then
osm_type_table['osm_type'] = 'emergency_phone'
osm_type_table['osm_subtype'] = nil
elseif object.tags.highway == 'emergency_access_point' then
osm_type_table['osm_type'] = 'emergency_access'
osm_type_table['osm_subtype'] = nil
elseif object.tags.man_made == 'tower'
or object.tags.man_made == 'communications_tower'
or object.tags.man_made == 'mast'
or object.tags.man_made == 'lighthouse'
or object.tags.man_made == 'flagpole'
if tags.amenity == 'fire_hydrant'
or tags.emergency == 'fire_hydrant' then
osm_type_table['osm_type'] = 'emergency'
osm_type_table['osm_subtype'] = 'fire_hydrant'
elseif tags.amenity == 'emergency_phone'
or tags.emergency == 'phone' then
osm_type_table['osm_type'] = 'emergency'
osm_type_table['osm_subtype'] = 'phone'
elseif tags.emergency then
osm_type_table['osm_type'] = 'emergency'
osm_type_table['osm_subtype'] = tags.emergency
elseif tags.highway == 'emergency_access_point' then
osm_type_table['osm_type'] = 'emergency'
osm_type_table['osm_subtype'] = 'highway_access'
elseif tags.man_made == 'tower'
or tags.man_made == 'communications_tower'
or tags.man_made == 'mast'
or tags.man_made == 'lighthouse'
or tags.man_made == 'flagpole'
then
osm_type_table['osm_type'] = object.tags.man_made
osm_type_table['osm_subtype'] = object.tags['tower:type']
osm_type_table['osm_type'] = tags.man_made
osm_type_table['osm_subtype'] = tags['tower:type']

elseif object.tags.man_made == 'silo'
or object.tags.man_made == 'storage_tank'
or object.tags.man_made == 'water_tower'
or object.tags.man_made == 'reservoir_covered'
elseif tags.man_made == 'silo'
or tags.man_made == 'storage_tank'
or tags.man_made == 'water_tower'
or tags.man_made == 'reservoir_covered'
then
osm_type_table['osm_type'] = object.tags.man_made
osm_type_table['osm_subtype'] = object.tags['content']
elseif object.tags.power
osm_type_table['osm_type'] = tags.man_made
osm_type_table['osm_subtype'] = tags['content']
elseif tags.power
then
osm_type_table['osm_type'] = 'power'
osm_type_table['osm_subtype'] = object.tags['power']
elseif object.tags.utility then
osm_type_table['osm_subtype'] = tags['power']
elseif tags.utility then
osm_type_table['osm_type'] = 'utility'
osm_type_table['osm_subtype'] = nil
elseif object.tags.aeroway then
elseif tags.aeroway then
osm_type_table['osm_type'] = 'aeroway'
osm_type_table['osm_subtype'] = object.tags.aeroway
osm_type_table['osm_subtype'] = tags.aeroway
else
osm_type_table['osm_type'] = 'unknown'
osm_type_table['osm_subtype'] = nil
end

if osm_type_table['osm_type'] == 'emergency'
and osm_type_table['osm_subtype'] == 'no' then
osm_type_table['osm_type'] = 'unknown'
osm_type_table['osm_subtype'] = nil
end

return osm_type_table
end

Expand All @@ -120,7 +129,7 @@ function infrastructure_process_node(object)
return
end

local osm_types = get_osm_type_subtype(object)
local osm_types = get_osm_type_subtype(object.tags)

if osm_types.osm_type == 'unknown' then
return
Expand Down Expand Up @@ -152,7 +161,7 @@ function infrastructure_process_way(object)
return
end

local osm_types = get_osm_type_subtype(object)
local osm_types = get_osm_type_subtype(object.tags)

if osm_types.osm_type == 'unknown' then
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
aeroway|runway|2
aeroway|taxiway|1
emergency|yes|3
power|cable|6
power|line|11
power|minor_line|2
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
aeroway|helipad|9
aeroway|navigationaid|1
communications_tower||1
emergency_access||1
emergency_phone||16
fire_hydrant||357
emergency|ambulance_station|1
emergency|fire_hydrant|357
emergency|highway_access|1
emergency|phone|16
flagpole||248
mast||2
power|generator|2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ aeroway|hangar|2
aeroway|helipad|12
aeroway|heliport|2
aeroway|runway|3
emergency|yes|11
power|generator|9
power|plant|1
power|substation|15
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/vbuilding_all_osm_type_subtype_count.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
address||16819
address||16807
building|39|1
building|44|1
building|Gym|1
Expand Down

0 comments on commit 517e508

Please sign in to comment.