Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from base64 import b64decode
import os
import re
import osmium as o
import osgeo.ogr as ogr
import osgeo.osr as osr
from shapely.wkb import loads, dumps
from shapely.prepared import prep
from osm_export_tool import GeomType, File
fab = o.geom.WKBFactory()
create_geom = lambda b : ogr.CreateGeometryFromWkb(bytes.fromhex(b))
epsg_4326 = osr.SpatialReference()
epsg_4326.ImportFromEPSG(4326)
CLOSED_WAY_KEYS = ['aeroway','amenity','boundary','building','building:part','craft','geological','historic','landuse','leisure','military','natural','office','place','shop','sport','tourism']
CLOSED_WAY_KEYVALS = {'highway':'platform','public_transport':'platform'}
def closed_way_is_polygon(tags):
for key in CLOSED_WAY_KEYS:
if key in tags:
return True
for key, val in CLOSED_WAY_KEYVALS.items():
if key in tags and tags[key] == val:
return True
return False
def make_filename(s):
"""Extract Ways from OSM PBF files."""
import os
import time
import osmium as o
import requests
import shapely.wkb as wkblib
from src.config import GEO_DATA_DIR
# http://docs.osmcode.org/pyosmium/latest/intro.html
# A global factory that creates WKB from a osmium geometry
wkbfab = o.geom.WKBFactory()
class WayMap():
"""Extract ways from OpenStreetMap PBF extracts."""
def __init__(self, extract_type='highway'):
"""The extract_type can be highway, footway, cycleway, or tennis."""
self.extracter = WayExtracter(extract_type)
def extract_files(self, file_list):
"""Extract ways from each PBF in file_list."""
for path in file_list:
self.run_extraction(path)
def run_extraction(self, file_path):
"""Extract ways from a PBF file at file_path."""