Skip to content

Instantly share code, notes, and snippets.

@ei-grad
Last active February 22, 2024 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ei-grad/1c91fbdcfdfb59fe2ee5da1dfad1559b to your computer and use it in GitHub Desktop.
Save ei-grad/1c91fbdcfdfb59fe2ee5da1dfad1559b to your computer and use it in GitHub Desktop.
Draw OSM geometries over each other projected to 1km units
#!/usr/bin/env python
#
# Draw OSM geometries over each other projected to 1km units
#
# Install requirements:
# pip install osmnx matplotlib
#
# Usage:
# draw-projected "Cyprus island" "RU-MOW"
#
# Copyright (c) 2024 Andrew Grigorev <andrew@ei-grad.ru>
#
# This software is licensed under the MIT License - see the MIT License for details:
# https://opensource.org/licenses/MIT
import sys
import matplotlib.pyplot as plt
import osmnx as ox
def norm(gdf):
gdf = gdf.to_crs(gdf.estimate_utm_crs())
centroid = gdf.geometry.unary_union.centroid
gdf = gdf.translate(-centroid.x, -centroid.y)
return gdf.scale(.001, .001, origin=(0, 0))
ax = plt.axes()
for i in sys.argv[1:]:
gdf = ox.geocode_to_gdf(i)
norm(gdf).plot(ax=ax, facecolor="none")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment