Skip to content

Commit

Permalink
Fix issue with clipping rasters
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Jun 20, 2019
1 parent da81430 commit e992cd6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions gridfinder/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ def clip_raster(raster, boundary, boundary_layer=None):
if isinstance(raster, str):
raster = rasterio.open(raster)

crs = raster.crs

if isinstance(boundary, Path):
boundary = str(boundary)
if isinstance(boundary, str):
Expand All @@ -137,7 +135,8 @@ def clip_raster(raster, boundary, boundary_layer=None):

boundary = gpd.read_file(boundary, layer=boundary_layer, driver=driver)

boundary = boundary.to_crs(crs=raster.crs)
if not (boundary.crs == raster.crs or boundary.crs == raster.crs.data):
boundary = boundary.to_crs(crs=raster.crs)
coords = [json.loads(boundary.to_json())["features"][0]["geometry"]]

# mask/clip the raster using rasterio.mask
Expand All @@ -146,4 +145,4 @@ def clip_raster(raster, boundary, boundary_layer=None):
if len(clipped.shape) >= 3:
clipped = clipped[0]

return clipped, affine, crs
return clipped, affine, raster.crs

0 comments on commit e992cd6

Please sign in to comment.