BBBikeReader.read_osm_pbf

BBBikeReader.read_osm_pbf(subregion_name, data_dir=None, chunk_size_limit=50, parse_raw_feat=False, transform_geom=False, transform_other_tags=False, update=False, download_confirmation_required=True, pickle_it=False, ret_pickle_path=False, rm_osm_pbf=False, verbose=False, **kwargs)

Read a PBF data file of a geographic region.

Parameters
  • subregion_name (str) – name of a geographic region (case-insensitive) that is available on BBBike free download server

  • data_dir (str or None) – directory where the PBF data file is saved; if None (default), the default directory

  • chunk_size_limit (int) – threshold (in MB) that triggers the use of chunk parser, defaults to 50; if the size of the .osm.pbf file (in MB) is greater than chunk_size_limit, it will be parsed in a chunk-wise way

  • parse_raw_feat (bool) – whether to parse each feature in the raw data, defaults to False

  • transform_geom (bool) – whether to transform a single coordinate (or a collection of coordinates) into a geometric object, defaults to False

  • transform_other_tags (bool) – whether to transform a 'other_tags' into a dictionary, defaults to False

  • update (bool) – whether to check to update pickle backup (if available), defaults to False

  • download_confirmation_required (bool) – whether to ask for confirmation before starting to download a file, defaults to True

  • pickle_it (bool) – whether to save the .pbf data as a .pickle file, defaults to False

  • ret_pickle_path (bool) – (when pickle_it=True) whether to return a path to the saved pickle file

  • rm_osm_pbf (bool) – whether to delete the downloaded .osm.pbf file, defaults to False

  • verbose (bool or int) – whether to print relevant information in console, defaults to False

  • kwargs – optional parameters of parse_osm_pbf()

Returns

dictionary of the .osm.pbf data; when pickle_it=True, return a tuple of the dictionary and a path to the pickle file

Return type

dict or tuple or None

Example:

>>> import os
>>> from pyhelpers.dir import cd
>>> from pydriosm.reader import BBBikeReader

>>> bbbike_reader = BBBikeReader()

>>> region_name = 'Leeds'
>>> dat_dir = "tests"

>>> # (Parsing the data in this example might take up to a few minutes.)
>>> leeds_osm_pbf = bbbike_reader.read_osm_pbf(region_name, dat_dir,
...                                            parse_raw_feat=True,
...                                            transform_geom=True,
...                                            transform_other_tags=True,
...                                            verbose=True)
To download .pbf data of the following geographic region(s):
    Leeds
? [No]|Yes: yes
Downloading "Leeds.osm.pbf" to "tests\" ... Done.
Parsing "tests\Leeds.osm.pbf" ... Done.

>>> list(leeds_osm_pbf.keys())
['points', 'lines', 'multilinestrings', 'multipolygons', 'other_relations']

>>> # Data of the 'multipolygons' layer
>>> leeds_osm_pbf_multipolygons = leeds_osm_pbf['multipolygons']

>>> leeds_osm_pbf_multipolygons.head()
      id                                        coordinates  ... tourism other_tags
0  10595  (POLYGON ((-1.5030223 53.6725382, -1.5034495 5...  ...    None       None
1  10600  (POLYGON ((-1.5116994 53.6764287, -1.5099361 5...  ...    None       None
2  10601  (POLYGON ((-1.5142403 53.6710831, -1.5143686 5...  ...    None       None
3  10612  (POLYGON ((-1.5129341 53.6704885, -1.5131883 5...  ...    None       None
4  10776  (POLYGON ((-1.5523801 53.7029081, -1.5522831 5...  ...    None       None
[5 rows x 27 columns]

>>> # Delete the downloaded PBF data file
>>> os.remove(cd(dat_dir, "Leeds.osm.pbf"))