osm_flex.extract

This file is part of OSM-flex. Copyright (C) 2023 OSM-flex contributors listed in AUTHORS. OSM-flex is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. OSM-flex is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. —– extraction functions

Module Contents

Functions

_query_builder(geo_type, constraint_dict)

This function builds an SQL query from the values passed to the extract()

extract(osm_path, geo_type, osm_keys[, osm_query])

Function to extract geometries and tag info for entires in the OSM file

extract_cis(osm_path, ci_type)

A wrapper around extract() to conveniently extract map info for a

Attributes

LOGGER

DATA_DIR

osm_flex.extract.LOGGER[source]
osm_flex.extract.DATA_DIR = ''[source]
osm_flex.extract._query_builder(geo_type, constraint_dict)[source]

This function builds an SQL query from the values passed to the extract() function.

Parameters

geo_typestr

Type of geometry to extract. One of [points, lines, multipolygons]

constraint_dict : dict

Returns

querystr

an SQL query string.

osm_flex.extract.extract(osm_path, geo_type, osm_keys, osm_query=None)[source]

Function to extract geometries and tag info for entires in the OSM file matching certain OSM keys, or key-value constraints. from an OpenStreetMap osm.pbf file.

Parameters

osm_pathstr or Path

location of osm.pbf file from which to parse

geo_typestr

Type of geometry to extract. One of [points, lines, multipolygons]

osm_keyslist

a list with all the osm keys that should be reported as columns in the output gdf.

osm_querystr

optional. query string of the syntax “key=’value’ (and/or further queries)”. If left empty, all objects for which the first entry of osm_keys is not Null will be parsed. See examples in DICT_CIS_OSM in case of doubt.

Returns

gpd.GeoDataFrame

A gdf with all results from the osm.pbf file matching the specified constraints.

Note

1) The keys that are searchable are specified in the osmconf.ini file. Make sure that they exist in the attributes=… paragraph under the respective geometry section. For example, to extract multipolygons with building=’yes’, building must be in the attributes under the [multipolygons] section of the file. You can find it in the same folder as the osm_dataloader.py module is located. 2) OSM keys that have : in their name must be changed to _ in the search dict, but not in the osmconf.ini E.g. tower:type is called tower_type, since it would interfere with the SQL syntax otherwise, but still tower:type in the osmconf.ini 3) If the osm_query is left empty (None), then all objects will be parsed for which the first entry of osm_keys is not Null. E.g. if osm_keys = [‘building’, ‘name’] and osm_query = None, then all items matching building=* will be parsed.

See also

https://taginfo.openstreetmap.org/ to check what keys and key/value pairs are valid. https://overpass-turbo.eu/ for a direct visual output of the query, and to quickly check the validity. The wizard can help you find the correct keys / values you are looking for.

osm_flex.extract.extract_cis(osm_path, ci_type)[source]

A wrapper around extract() to conveniently extract map info for a selection of critical infrastructure types from the given osm.pbf file. No need to search for osm key/value tags and relevant geometry types. Parameters ———- osm_path : str or Path

location of osm.pbf file from which to parse

ci_typestr

one of DICT_CIS_OSM.keys(), i.e. ‘education’, ‘healthcare’, ‘water’, ‘telecom’, ‘road’, ‘rail’, ‘air’, ‘gas’, ‘oil’, ‘power’, ‘wastewater’, ‘food’

See also

DICT_CIS_OSM for the keys and key/value tags queried for the respective CIs. Modify if desired.