Update get_test_polygons.py for osmnx 1.6.0
TODO - update `etl/requirements.txt` to reflect osmnx==1.6.0
This commit is contained in:
parent
6d13ab8048
commit
df65152198
@ -21,43 +21,52 @@ size = 256
|
|||||||
# load buildings from about 1.5km² around UCL
|
# load buildings from about 1.5km² around UCL
|
||||||
point = (51.524498, -0.133874)
|
point = (51.524498, -0.133874)
|
||||||
dist = 612
|
dist = 612
|
||||||
gdf = osmnx.footprints_from_point(point=point, dist=dist)
|
tags = {"building": True}
|
||||||
|
gdf = osmnx.features_from_point(point, tags, dist=dist)
|
||||||
|
|
||||||
# preview image
|
# preview image
|
||||||
gdf_proj = osmnx.projection.project_gdf(gdf, to_crs={'init': 'epsg:3857'})
|
gdf_proj = osmnx.projection.project_gdf(gdf, to_crs={"init": "epsg:3857"})
|
||||||
gdf_proj = gdf_proj[gdf_proj.geometry.apply(lambda g: g.geom_type != 'MultiPolygon')] # noqa
|
gdf_proj = gdf_proj[gdf_proj.geometry.type == "Polygon"]
|
||||||
|
|
||||||
fig, ax = osmnx.plot_footprints(gdf_proj, bgcolor='#333333',
|
fig, ax = osmnx.plot_footprints(
|
||||||
color='w', figsize=(4, 4),
|
gdf_proj,
|
||||||
save=True, show=False, close=True,
|
bgcolor="#333333",
|
||||||
filename='test_buildings_preview', dpi=600)
|
color="w",
|
||||||
|
figsize=(4, 4),
|
||||||
|
save=True,
|
||||||
|
show=False,
|
||||||
|
close=True,
|
||||||
|
filepath="test_buildings_preview.png",
|
||||||
|
dpi=600,
|
||||||
|
)
|
||||||
|
|
||||||
# save
|
# save
|
||||||
test_dir = os.path.dirname(__file__)
|
test_dir = os.path.dirname(__file__)
|
||||||
test_data_geojson = str(os.path.join(test_dir, 'test_buildings.geojson'))
|
test_data_geojson = str(os.path.join(test_dir, "test_buildings.geojson"))
|
||||||
subprocess.run(["rm", test_data_geojson])
|
subprocess.run(["rm", test_data_geojson])
|
||||||
|
gdf_to_save = gdf_proj.reset_index()[["osmid", "geometry"]]
|
||||||
gdf_to_save = gdf_proj.reset_index(
|
|
||||||
)[
|
|
||||||
['index', 'geometry']
|
|
||||||
]
|
|
||||||
|
|
||||||
gdf_to_save.rename(
|
gdf_to_save.rename(
|
||||||
columns={'index': 'fid'}
|
columns={"osmid": "fid"}
|
||||||
).to_file(
|
).to_file(
|
||||||
test_data_geojson, driver='GeoJSON'
|
test_data_geojson,
|
||||||
|
driver="GeoJSON"
|
||||||
)
|
)
|
||||||
|
|
||||||
# convert to CSV
|
# convert to CSV
|
||||||
test_data_csv = str(os.path.join(test_dir, 'test_buildings.3857.csv'))
|
test_data_csv = str(os.path.join(test_dir, "test_buildings.3857.csv"))
|
||||||
subprocess.run(["rm", test_data_csv])
|
subprocess.run(["rm", test_data_csv])
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["ogr2ogr", "-f", "CSV", test_data_csv,
|
[
|
||||||
test_data_geojson, "-lco", "GEOMETRY=AS_WKT"]
|
"ogr2ogr",
|
||||||
|
"-f",
|
||||||
|
"CSV",
|
||||||
|
test_data_csv,
|
||||||
|
test_data_geojson,
|
||||||
|
"-lco",
|
||||||
|
"GEOMETRY=AS_WKT",
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# add SRID for ease of loading to PostgreSQL
|
# add SRID for ease of loading to PostgreSQL
|
||||||
subprocess.run(
|
subprocess.run(["sed", "-i", 's/^"POLYGON/"SRID=3857;POLYGON/', test_data_csv])
|
||||||
["sed", "-i", "s/^\"POLYGON/\"SRID=3857;POLYGON/",
|
|
||||||
test_data_csv]
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user