Last active
May 13, 2021 21:07
-
-
Save richpsharp/294fdae44658c35f693a89507097fe14 to your computer and use it in GitHub Desktop.
how to clip to area and mask by vector bounds and values
This file contains hidden or 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
vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR) | |
layer = vector.GetLayer() | |
layer.SetAttributeFilter('Country="USA"') # or whatever... | |
feature = layer.GetNextFeature() | |
geom = feature.GetGeometryRef() | |
envelope = geom.GetEnvelope() | |
target_bb = [envelope[i] for i in [0, 2, 1, 3]]) | |
geom = None | |
feature = None | |
layer = None | |
vector = None | |
pygeoprocessing.align_and_resize_raster_stack( | |
raster_stack, target_stack, ['near']*len(raster_stack), | |
target_bb, vector_mask_options={ | |
'mask_vector_path': vector_path, | |
'mask_vector_where_filter': 'Country="USA"', | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment