BBBikeReader.read_geojson_xz

BBBikeReader.read_geojson_xz(subregion_name, data_dir=None, parse_geometry=False, download=False, verbose=False, **kwargs)[source]

Read a .geojson.xz data file of a geographic (sub)region.

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

  • data_dir (str | None) – directory where the .geojson.xz data file is located/saved; if None (default), the default directory

  • parse_geometry (bool) – whether to represent coordinates in a format of a geometric object, defaults to False

  • download (bool) – whether to try to download the requisite data file if it does not exist, defaults to True

  • verbose (bool | int) – whether to print relevant information in console as the function runs, defaults to False

Returns:

tabular data of the .csv.xz file

Return type:

pandas.DataFrame | None

Examples:

>>> from pydriosm.reader import BBBikeReader
>>> from pyhelpers.dirs import cd, delete_dir
>>> import os

>>> bbr = BBBikeReader()

>>> subrgn_name = 'Leeds'
>>> dat_dir = "tests\osm_data"

>>> leeds_geoj = bbr.read_geojson_xz(subrgn_name, dat_dir, verbose=True)
The requisite data file "./tests/osm_data/leeds/Leeds.osm.geojson.xz" does not exist.

>>> # Set `try_download=True`
>>> leeds_geoj = bbr.read_geojson_xz(subrgn_name, dat_dir, verbose=True, download=True)
Downloading "Leeds.osm.geojson.xz" 100%|██████████| 60.4M/60.4M | 20.7MB/s | ...
  Saving "Leeds.osm.geojson.xz" to "./tests/osm_data/leeds/" ... Done.
Parsing the data ... Done.
>>> leeds_geoj.head()
                                geometry                                    properties
0  {'type': 'Point', 'coordinates': [...  {'highway': 'motorway_junction', 'name': ...
1  {'type': 'Point', 'coordinates': [...  {'highway': 'motorway_junction', 'name': ...
2  {'type': 'Point', 'coordinates': [...  {'highway': 'motorway_junction', 'name': ...
3  {'type': 'Point', 'coordinates': [...  {'highway': 'motorway_junction', 'name': ...
4  {'type': 'Point', 'coordinates': [...  {'highway': 'motorway_junction', 'name': ...

>>> # Set `parse_geometry` to be True
>>> leeds_geoj_ = bbr.read_geojson_xz(
...     subrgn_name, dat_dir, parse_geometry=True, verbose=True)
Parsing "./tests/osm_data/leeds/Leeds.osm.geojson.xz" ... Done.
>>> leeds_geoj_['geometry'].head()
0    POINT (-1.5560511 53.6879848)
1       POINT (-1.34293 53.844618)
2     POINT (-1.517335 53.7499667)
3     POINT (-1.514175 53.7418444)
4     POINT (-1.516511 53.7256632)
Name: geometry, dtype: object

>>> # Delete the download directory
>>> delete_dir(dat_dir, verbose=True)
To delete the directory "./tests/osm_data/" (Not empty)
? [No]|Yes: yes
Deleting "./tests/osm_data/" ... Done.