-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emma Ai
committed
Nov 19, 2024
1 parent
52c37a0
commit 4435edd
Showing
6 changed files
with
126 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import dask | ||
import fiona | ||
from rasterio import features | ||
|
||
|
||
def rasterize_vector_mask(shape_file, transform, dst_shape, threshold=None): | ||
with fiona.open(shape_file) as source_ds: | ||
geoms = [s["geometry"] for s in source_ds] | ||
|
||
mask = features.rasterize( | ||
geoms, | ||
transform=transform, | ||
out_shape=dst_shape[1:], | ||
all_touched=False, | ||
fill=0, | ||
default_value=1, | ||
dtype="uint8", | ||
) | ||
|
||
# if valid area >= threshold | ||
# then the whole tile is valid | ||
if threshold is not None: | ||
if mask.sum() > mask.size * threshold: | ||
return dask.array.ones(dst_shape, name=False) | ||
|
||
return dask.array.from_array(mask.reshape(dst_shape), name=False) |
File renamed without changes.
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
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
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
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