BBBikeReader.read_geojson_xz¶
-
BBBikeReader.
read_geojson_xz
(subregion_name, data_dir=None, fmt_geom=False, download_confirmation_required=True, verbose=False)¶ Read a .geojson.xz 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 .geojson.xz data file is located/saved; if
None
(default), the default directoryfmt_geom (bool) – whether to reformat coordinates into a geometric object, defaults to
False
download_confirmation_required (bool) – whether to ask for confirmation before starting to download a file, defaults to
True
verbose (bool or 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 or None
Examples:
>>> import os >>> from pyhelpers.dir import cd >>> from pydriosm.reader import BBBikeReader >>> bbbike_reader = BBBikeReader() >>> region_name = 'Leeds' >>> dat_dir = "tests" >>> leeds_geoj = bbbike_reader.read_geojson_xz(region_name, dat_dir, verbose=True) To download .geojson.xz data of the following geographic region(s): Leeds ? [No]|Yes: yes Downloading "Leeds.osm.geojson.xz" to "tests\" ... Done. Parsing "tests\Leeds.osm.geojson.xz" ... Done. >>> leeds_geoj.head() feature_name ... properties 0 Feature ... {'highway': 'motorway_junction', 'name': 'Flus... 1 Feature ... {'highway': 'motorway_junction', 'name': 'Bram... 2 Feature ... {'highway': 'motorway_junction', 'name': 'Bell... 3 Feature ... {'highway': 'motorway_junction', 'name': 'Loft... 4 Feature ... {'highway': 'motorway_junction', 'name': 'Loft... [5 rows x 4 columns] >>> leeds_geoj[['coordinates']].head() coordinates 0 [-1.5558097, 53.6873431] 1 [-1.34293, 53.844618] 2 [-1.517335, 53.7499667] 3 [-1.514124, 53.7416937] 4 [-1.516511, 53.7256632] >>> # Set `fmt_geom` to be True >>> leeds_geoj_ = bbbike_reader.read_geojson_xz(region_name, dat_dir, fmt_geom=True) >>> leeds_geoj_[['coordinates']].head() coordinates 0 POINT (-1.5558097 53.6873431) 1 POINT (-1.34293 53.844618) 2 POINT (-1.517335 53.7499667) 3 POINT (-1.514124 53.7416937) 4 POINT (-1.516511 53.7256632) >>> # Delete the downloaded .csv.xz data file >>> os.remove(cd(dat_dir, "Leeds.osm.geojson.xz"))