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)[source]

Read a PBF data file of a geographic region.

Parameters
  • subregion_name (str) – name of a geographic region (case-insensitive) available on BBBike’s 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) – whether to return an absolute path to the saved pickle file (when pickle_it=True)

  • 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 as the function runs, defaults to False

Returns

dictionary of the .osm.pbf data; when pickle_it=True, return a tuple of the dictionary and an absolute 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()

>>> sr_name = 'Leeds'
>>> dat_dir = "tests"

>>> # (Note that this process may take a long time.)
>>> leeds_osm_pbf = bbbike_reader.read_osm_pbf(sr_name, dat_dir,
...                                            parse_raw_feat=True,
...                                            transform_geom=True,
...                                            transform_other_tags=True,
...                                            verbose=True)
Parsing "\tests\Leeds.osm.pbf" ... Done.

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

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

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