2018-09-09 06:32:12 -04:00
|
|
|
"""Download and load a small open dataset for testing
|
|
|
|
"""
|
2018-09-10 05:44:09 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-09-09 06:32:12 -04:00
|
|
|
import os
|
|
|
|
import osmnx
|
|
|
|
|
|
|
|
# configure logging/caching
|
|
|
|
osmnx.config(log_console=True, use_cache=True)
|
|
|
|
|
|
|
|
# configure the image display
|
|
|
|
size = 256
|
|
|
|
|
|
|
|
# load buildings from about 1.5km² around UCL
|
|
|
|
point = (51.524498, -0.133874)
|
|
|
|
dist = 612
|
|
|
|
gdf = osmnx.buildings_from_point(point=point, distance=dist)
|
|
|
|
|
|
|
|
# preview image
|
2018-09-10 05:44:09 -04:00
|
|
|
gdf_proj = osmnx.project_gdf(gdf, to_crs={'init': 'epsg:3857'})
|
2018-09-09 06:32:12 -04:00
|
|
|
fig, ax = osmnx.plot_buildings(gdf_proj, bgcolor='#333333', color='w', figsize=(4,4),
|
2018-09-10 05:44:09 -04:00
|
|
|
save=True, show=False, close=True,
|
|
|
|
filename='test_buildings_preview', dpi=600)
|
2018-09-09 06:32:12 -04:00
|
|
|
|
|
|
|
# save as geojson
|
|
|
|
test_data_file = os.path.join(os.path.dirname(__file__), 'test_buildings.geojson')
|
|
|
|
|
2018-09-10 05:44:09 -04:00
|
|
|
gdf_to_save = gdf_proj.reset_index(
|
2018-09-09 06:32:12 -04:00
|
|
|
)[
|
|
|
|
['index', 'geometry']
|
|
|
|
]
|
|
|
|
|
|
|
|
gdf_to_save.rename(
|
|
|
|
columns={'index': 'fid'}
|
|
|
|
).to_file(
|
|
|
|
test_data_file, driver='GeoJSON'
|
|
|
|
)
|