cumulative_density_function_global.py
def extract_feature(
        vector_path, feature_id, projection_wkt, target_vector_path,
        target_complete_token_path):
    """Make a local projection of a single feature in a vector.

    Parameters:
        vector_path (str): base vector in WGS84 coordinates.
        feature_id (int): FID for the feature to extract.
        projection_wkt (str): projection wkt code to project feature to.
        target_gpkg_vector_path (str): path to new GPKG vector that will
            contain only that feature.
        target_complete_token_path (str): path to a file that is created if
             the function successfully completes.

    Returns:
        None.

    """
    base_vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR)
    base_layer = base_vector.GetLayer()
    feature = base_layer.GetFeature(feature_id)
    geom = feature.GetGeometryRef()

    epsg_srs = osr.SpatialReference()
    epsg_srs.ImportFromWkt(projection_wkt)

    base_srs = base_layer.GetSpatialRef()
    base_to_utm = osr.CoordinateTransformation(base_srs, epsg_srs)

    # clip out watershed to its own file
    # create a new shapefile
    if os.path.exists(target_vector_path):
        os.remove(target_vector_path)
    driver = ogr.GetDriverByName('GPKG')
    target_vector = driver.CreateDataSource(
        target_vector_path)
    layername = (os.path.splitext(os.path.basename(target_vector_path))[0])
    target_layer = target_vector.CreateLayer(
        layername, epsg_srs, ogr.wkbMultiPolygon)
    layer_defn = target_layer.GetLayerDefn()
    feature_geometry = geom.Clone()
    base_feature = ogr.Feature(layer_defn)
    feature_geometry.Transform(base_to_utm)
    base_feature.SetGeometry(feature_geometry)
    target_layer.CreateFeature(base_feature)
    target_layer.SyncToDisk()
    geom = None
    feature_geometry = None
    base_feature = None
    target_layer = None
    target_vector = None
    base_layer = None
    base_vector = None
    with open(target_complete_token_path, 'w') as token_file:
        token_file.write(str(datetime.datetime.now()))
Make a local projection of a single feature in a vector.

    Parameters:
        vector_path (str): base vector in WGS84 coordinates.
        feature_id (int): FID for the feature to extract.
        projection_wkt (str): projection wkt code to project feature to.
        target_gpkg_vector_path (str): path to new GPKG vector that will
            contain only that feature.
        target_complete_token_path (str): path to a file that is created if
             the function successfully completes.

    Returns:
        None.

    
Make a local projection of a single feature in a vector.
Make a local projection of a single feature in a vector .
def extract_feature(
        vector_path, feature_id, projection_wkt, target_vector_path,
        target_complete_token_path):
    base_vector = gdal.OpenEx(vector_path, gdal.OF_VECTOR)
    base_layer = base_vector.GetLayer()
    feature = base_layer.GetFeature(feature_id)
    geom = feature.GetGeometryRef()
    epsg_srs = osr.SpatialReference()
    epsg_srs.ImportFromWkt(projection_wkt)
    base_srs = base_layer.GetSpatialRef()
    base_to_utm = osr.CoordinateTransformation(base_srs, epsg_srs)
    if os.path.exists(target_vector_path):
        os.remove(target_vector_path)
    driver = ogr.GetDriverByName('GPKG')
    target_vector = driver.CreateDataSource(
        target_vector_path)
    layername = (os.path.splitext(os.path.basename(target_vector_path))[0])
    target_layer = target_vector.CreateLayer(
        layername, epsg_srs, ogr.wkbMultiPolygon)
    layer_defn = target_layer.GetLayerDefn()
    feature_geometry = geom.Clone()
    base_feature = ogr.Feature(layer_defn)
    feature_geometry.Transform(base_to_utm)
    base_feature.SetGeometry(feature_geometry)
    target_layer.CreateFeature(base_feature)
    target_layer.SyncToDisk()
    geom = None
    feature_geometry = None
    base_feature = None
    target_layer = None
    target_vector = None
    base_layer = None
    base_vector = None
    with open(target_complete_token_path, 'w') as token_file:
        token_file.write(str(datetime.datetime.now()))
def extract_feature ( vector_path , feature_id , projection_wkt , target_vector_path , target_complete_token_path ) : base_vector = gdal . OpenEx ( vector_path , gdal . OF_VECTOR ) base_layer = base_vector . GetLayer ( ) feature = base_layer . GetFeature ( feature_id ) geom = feature . GetGeometryRef ( ) epsg_srs = osr . SpatialReference ( ) epsg_srs . ImportFromWkt ( projection_wkt ) base_srs = base_layer . GetSpatialRef ( ) base_to_utm = osr . CoordinateTransformation ( base_srs , epsg_srs ) if os . path . exists ( target_vector_path ) : os . remove ( target_vector_path ) driver = ogr . GetDriverByName ( 'GPKG' ) target_vector = driver . CreateDataSource ( target_vector_path ) layername = ( os . path . splitext ( os . path . basename ( target_vector_path ) ) [ 0 ] ) target_layer = target_vector . CreateLayer ( layername , epsg_srs , ogr . wkbMultiPolygon ) layer_defn = target_layer . GetLayerDefn ( ) feature_geometry = geom . Clone ( ) base_feature = ogr . Feature ( layer_defn ) feature_geometry . Transform ( base_to_utm ) base_feature . SetGeometry ( feature_geometry ) target_layer . CreateFeature ( base_feature ) target_layer . SyncToDisk ( ) geom = None feature_geometry = None base_feature = None target_layer = None target_vector = None base_layer = None base_vector = None with open ( target_complete_token_path , 'w' ) as token_file : token_file . write ( str ( datetime . datetime . now ( ) ) )
Make a local projection of a single feature in a vector.
Make a local projection of a single feature in a vector .
"""Make a local projection of a single feature in a vector.

    Parameters:
        vector_path (str): base vector in WGS84 coordinates.
        feature_id (int): FID for the feature to extract.
        projection_wkt (str): projection wkt code to project feature to.
        target_gpkg_vector_path (str): path to new GPKG vector that will
            contain only that feature.
        target_complete_token_path (str): path to a file that is created if
             the function successfully completes.

    Returns:
        None.

    """ # clip out watershed to its own file
 # create a new shapefile

None
vector_path
base vector in WGS84 coordinates.
base vector in WGS84 coordinates .
feature_id
FID for the feature to extract.
FID for the feature to extract .
projection_wkt
projection wkt code to project feature to.
projection wkt code to project feature to .
target_vector_path
target_complete_token_path
path to a file that is created if
the function successfully completes.
path to a file that is created if the function successfully completes .
target_gpkg_vector_path
path to new GPKG vector that will
contain only that feature.
path to new GPKG vector that will contain only that feature .