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"
    to "tests\osm_data\leeds\" ... Done.
Parsing the data ... Done.
>>> leeds_geoj.head()
                                            geometry                          properties
0  {'type': 'Point', 'coordinates': [-1.5558097, ...  {'highway': 'motorway_junction'...
1  {'type': 'Point', 'coordinates': [-1.34293, 53...  {'highway': 'motorway_junction'...
2  {'type': 'Point', 'coordinates': [-1.517335, 5...  {'highway': 'motorway_junction'...
3  {'type': 'Point', 'coordinates': [-1.514124, 5...  {'highway': 'motorway_junction'...
4  {'type': 'Point', 'coordinates': [-1.516511, 5...  {'highway': 'motorway_junction'...

>>> # 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.514124 53.7416937)
4     POINT (-1.516511 53.7256632)
Name: geometry, dtype: object

>>> # Delete the download directory
>>> delete_dir(dat_dir, verbose=True)