Created
December 20, 2018 17:07
-
-
Save nrweir/b56e8289f248da30838f6a372986c496 to your computer and use it in GitHub Desktop.
load in gdf and geotiff and return transformed gdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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