Skip to content

Instantly share code, notes, and snippets.

@nrweir
Created December 20, 2018 17:07
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 nrweir/b56e8289f248da30838f6a372986c496 to your computer and use it in GitHub Desktop.
Save nrweir/b56e8289f248da30838f6a372986c496 to your computer and use it in GitHub Desktop.
load in gdf and geotiff and return transformed gdf
import rasterio
import geopandas as gpd
def transform_gdf(gdf, geotiff):
"""Transform the coordinates of a GeoDataFrame.
Arguments
---------
gdf : gpd.GeoDataFrame
A geodataframe with an identity affine xform.
geotiff : str
Path to a GeoTIFF with the desired transformation for the output gdf.
Returns
-------
A gdf with the polygons transformed to the destination crs.
"""
with rasterio.open(geotiff) as src:
gdf.to_crs(src.profile['crs'])
src.close()
return gdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment