Skip to content

Instantly share code, notes, and snippets.

@butchtm
Last active August 2, 2022 08:40
Show Gist options
  • Save butchtm/3eff004bae150ea1b1d2dfeffdb5de17 to your computer and use it in GitHub Desktop.
Save butchtm/3eff004bae150ea1b1d2dfeffdb5de17 to your computer and use it in GitHub Desktop.
Sample generation of geometry from bing tile quadkey
import geopandas as gpd
import morecantile
import shapely.geometry as geom
import pandas as pd
tms = morecantile.tms.get('WebMercatorQuad')
schools = pd.DataFrame(dict(name=['Rurubao School'], quadkey=['133332330000'], amenity=['school'],))
def quadkey_to_geom(x):
tile = tms.quadkey_to_tile(x)
feature = tms.feature(tile)
geometry = geom.shape(feature['geometry'])
return geometry
schools['geometry'] = schools.quadkey.apply(quadkey_to_geom); schools
schools_gdf = gpd.GeoDataFrame(schools, geometry='geometry', crs='EPSG:4326')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment