wip:Road.has_cars

This commit is contained in:
Paul Bienkowski 2022-04-05 17:51:39 +02:00
parent 9d97489ac9
commit bf740a0695
2 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,24 @@
"""add road column has_cars
Revision ID: ddde1cdc767b
Revises: a049e5eb24dd
Create Date: 2022-04-03 20:13:22.874195
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "ddde1cdc767b"
down_revision = "a049e5eb24dd"
branch_labels = None
depends_on = None
def upgrade():
op.add_column("road", sa.Column("has_cars", sa.Boolean))
def downgrade():
op.drop_column("road", "has_cars")

View file

@ -35,6 +35,11 @@ local HIGHWAY_TYPES = {
"track", "track",
"road", "road",
} }
local UNMOTORIZED_TRAFFIC_HIGHWAY_TYPES = {
"cycleway",
"footway",
"path",
}
local ZONE_TYPES = { local ZONE_TYPES = {
"urban", "urban",
"rural", "rural",
@ -68,6 +73,7 @@ local roads = osm2pgsql.define_way_table('road', {
{ column = 'name', type = 'text' }, { column = 'name', type = 'text' },
{ column = 'geometry', type = 'linestring' }, { column = 'geometry', type = 'linestring' },
{ column = 'oneway', type = 'bool' }, { column = 'oneway', type = 'bool' },
{ column = 'has_cars', type = 'bool' },
}) })
local regions = osm2pgsql.define_relation_table('region', { local regions = osm2pgsql.define_relation_table('region', {
@ -83,7 +89,9 @@ function osm2pgsql.process_way(object)
-- only import certain highway ways, i.e. roads and pathways -- only import certain highway ways, i.e. roads and pathways
if not tags.highway then return end if not tags.highway then return end
if not contains(HIGHWAY_TYPES, tags.highway) then return end
local unmotorized_traffic = contains(UNMOTORIZED_TRAFFIC_HIGHWAY_TYPES, tags.highway)
if not contains(HIGHWAY_TYPES, tags.highway) and not unmotorized_traffic then return end
-- do not import areas (plazas etc.) -- do not import areas (plazas etc.)
if tags.area == "yes" then return end if tags.area == "yes" then return end
@ -139,6 +147,7 @@ function osm2pgsql.process_way(object)
zone = zone, zone = zone,
directionality = directionality, directionality = directionality,
oneway = oneway, oneway = oneway,
has_cars = not unmotorized_traffic
}) })
end end