normalize_by_geometry.py
def clip_and_mask_raster(
        raster_path, vector_path, fid, target_mask_path):
    """Clip raster to feature and then mask by geometry.

    Parameters:
        raster_path (str): path to raster to clip.
        vector_path (str): path to vector that contains feature `fid`.
        fid (int): feature ID to use as the clipping feature.
        target_mask_path (str): raster is created as 0, 1, bounds extends the
            envelope of the feature and is 1 where it overlaps.

    Returns:
        None.

    """
    vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR)
    layer = vector.GetLayer()
    feature = layer.GetFeature(fid)
    geometry_ref = feature.GetGeometryRef()
    geometry = shapely.wkb.loads(geometry_ref.ExportToWkb())
    base_dir = os.path.dirname(target_mask_path)
    pixel_size = pygeoprocessing.get_raster_info(raster_path)['pixel_size']
    fh, target_clipped_path = tempfile.mkstemp(
        suffix='.tif', prefix='clipped', dir=base_dir)
    os.close(fh)
    LOGGER.debug('%s: %s', vector_path, str(geometry.bounds))
    pygeoprocessing.warp_raster(
        raster_path, pixel_size, target_clipped_path,
        'near', target_bb=geometry.bounds)
    pygeoprocessing.mask_raster(
        (target_clipped_path, 1), vector_path, target_mask_path,
        where_clause='FID=%d' % fid)
    os.remove(target_clipped_path)
Clip raster to feature and then mask by geometry.

    Parameters:
        raster_path (str): path to raster to clip.
        vector_path (str): path to vector that contains feature `fid`.
        fid (int): feature ID to use as the clipping feature.
        target_mask_path (str): raster is created as 0, 1, bounds extends the
            envelope of the feature and is 1 where it overlaps.

    Returns:
        None.

    
Clip raster to feature and then mask by geometry.
Clip raster to feature and then mask by geometry .
def clip_and_mask_raster(
        raster_path, vector_path, fid, target_mask_path):
    vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR)
    layer = vector.GetLayer()
    feature = layer.GetFeature(fid)
    geometry_ref = feature.GetGeometryRef()
    geometry = shapely.wkb.loads(geometry_ref.ExportToWkb())
    base_dir = os.path.dirname(target_mask_path)
    pixel_size = pygeoprocessing.get_raster_info(raster_path)['pixel_size']
    fh, target_clipped_path = tempfile.mkstemp(
        suffix='.tif', prefix='clipped', dir=base_dir)
    os.close(fh)
    LOGGER.debug('%s: %s', vector_path, str(geometry.bounds))
    pygeoprocessing.warp_raster(
        raster_path, pixel_size, target_clipped_path,
        'near', target_bb=geometry.bounds)
    pygeoprocessing.mask_raster(
        (target_clipped_path, 1), vector_path, target_mask_path,
        where_clause='FID=%d' % fid)
    os.remove(target_clipped_path)
def clip_and_mask_raster ( raster_path , vector_path , fid , target_mask_path ) : vector = gdal . OpenEx ( vector_path , gdal . OF_VECTOR ) layer = vector . GetLayer ( ) feature = layer . GetFeature ( fid ) geometry_ref = feature . GetGeometryRef ( ) geometry = shapely . wkb . loads ( geometry_ref . ExportToWkb ( ) ) base_dir = os . path . dirname ( target_mask_path ) pixel_size = pygeoprocessing . get_raster_info ( raster_path ) [ 'pixel_size' ] fh , target_clipped_path = tempfile . mkstemp ( suffix = '.tif' , prefix = 'clipped' , dir = base_dir ) os . close ( fh ) LOGGER . debug ( '%s: %s' , vector_path , str ( geometry . bounds ) ) pygeoprocessing . warp_raster ( raster_path , pixel_size , target_clipped_path , 'near' , target_bb = geometry . bounds ) pygeoprocessing . mask_raster ( ( target_clipped_path , 1 ) , vector_path , target_mask_path , where_clause = 'FID=%d' % fid ) os . remove ( target_clipped_path )
Clip raster to feature and then mask by geometry.
Clip raster to feature and then mask by geometry .
"""Clip raster to feature and then mask by geometry.

    Parameters:
        raster_path (str): path to raster to clip.
        vector_path (str): path to vector that contains feature `fid`.
        fid (int): feature ID to use as the clipping feature.
        target_mask_path (str): raster is created as 0, 1, bounds extends the
            envelope of the feature and is 1 where it overlaps.

    Returns:
        None.

    """
None
raster_path
path to raster to clip.
path to raster to clip .
vector_path
path to vector that contains feature `fid`.
path to vector that contains feature ` fid ` .
fid
feature ID to use as the clipping feature.
feature ID to use as the clipping feature .
target_mask_path
raster is created as 0, 1, bounds extends the
envelope of the feature and is 1 where it overlaps.
raster is created as 0 1 bounds extends the envelope of the feature and is 1 where it overlaps .