Exemplo n.º 1
0
def pop_calc(distance: int):
    motorways_buffered_population = 'motorways_buffered_population_' + str(
        distance)
    v.buffer(input=motorways,
             output=motorways_buffered,
             overwrite=True,
             distance=distance,
             type='line')
    v_to_rast(overwrite=True,
              input=motorways_buffered,
              output=motorways_buffered_raster,
              type='area',
              use='val',
              value=1)
    r_stats_zonal(base=motorways_buffered_raster,
                  cover=pop_layer,
                  method='sum',
                  output=motorways_buffered_population,
                  overwrite=True,
                  verbose=True)
Exemplo n.º 2
0
def main(opts, flgs):
    TMPVECT = []
    DEBUG = True if flgs["d"] else False
    atexit.register(cleanup, vect=TMPVECT, debug=DEBUG)
    # check input maps
    rhydro = ["kind_label", "discharge", "id_point", "id_plant"]
    rother = ["kind_label", "discharge", "id_point", "id_plant"]
    ovwr = overwrite()

    try:
        hydro = check_required_columns(
            opts["hydro"], int(opts["hydro_layer"]), rhydro, "hydro"
        )
        if opts["other"]:
            other = check_required_columns(
                opts["other"], opts["other_layer"], rother, "other"
            )
        else:
            other = None
        # minflow = check_float_or_raster(opts['minflow'])
    except ParameterError as exc:
        exception2error(exc)

    # start working
    hydro.open("r")
    el, mset = (
        opts["elevation"].split("@")
        if "@" in opts["elevation"]
        else (opts["elevation"], "")
    )
    elev = RasterRow(name=el, mapset=mset)
    elev.open("r")
    # import ipdb; ipdb.set_trace()
    plants, skipped = read_plants(
        hydro,
        elev=elev,
        restitution=opts["hydro_kind_turbine"],
        intake=opts["hydro_kind_intake"],
    )
    hydro.close()
    rvname, rvmset = (
        opts["river"].split("@") if "@" in opts["river"] else (opts["river"], "")
    )

    vplants = opts["output_plants"] if opts["output_plants"] else "tmpplants"
    # FIXME: I try with tmpplants in my mapset and it doesn'work
    if opts["output_plants"] == "":
        TMPVECT.append(vplants)
    with VectorTopo(rvname, rvmset, mode="r") as river:
        write_plants(plants, vplants, river, elev, overwrite=ovwr)

    if skipped:
        for skip in skipped:
            print("Plant: %r, Point: %r, kind: %r" % skip)
    elev.close()

    # compute a buffer around the plants
    buff = vplants + "buff"
    v.buffer(input=vplants, type="line", output=buff, distance=0.1, overwrite=ovwr)
    TMPVECT.append(buff)
    # return all the river segments that are not already with plants
    v.overlay(
        flags="t",
        ainput=opts["river"],
        atype="line",
        binput=buff,
        operator="not",
        output=opts["output_streams"],
        overwrite=ovwr,
    )
# folder
folder_path = r'D:\bernardo\00_academico\01_artigos\ms_Lucas_world_landscape_metrics\world-landscape-metrics-repo\01_data\community_locations'
os.chdir(folder_path) # Change to this folder

# import points
v.in_ogr(input = 'comm_data_neotro_checked_2020_d11_06.shp', 
	output = 'comm_data_neotro_checked_2020_d11_06', overwrite = True)
        grass.run_command('v.import', input = i, output = name, overwrite = True) # Import maps


# make buffer of 5km
# 1km (approx, in reality 900m) = 30 arcsec = 0.008333 degrees
# 5km = 0.045 degrees (approx)
v.buffer(input = 'comm_data_neotro_checked_2020_d11_06', 
	output = 'buffers_5km_comm_data_neotro_checked_2020_d11_06',
	type = 'point', distance = 0.045, flags = 't') 

#---------------------------------------
# cutting variables using buffers
#
# Here we cut the tree cover data from GFW to each buffer.
# Then we set as 0 the tree cover of areas deforested until the correspondent year of the sampling
# at each point, and create binary forest/non-forest maps using the threshold or tree cover
# > 70, 80, and 90.

# years for forest prop

# read all lines, column sampling_y
years = grass.read_command('v.db.select', map = 'buffers_5km_comm_data_neotro_checked_2020_d11_06',
 columns = 'sampling_y')
    v.distance('TankPoints',
               to='Storage',
               upload='dist',
               column='distance'
               )
    """
    """
    Method-2:
    This method will Join all the Tank Points using Triangulation method
    implemented in v.to.lines and the optimal distance is generated by using
    v.net.spawningtree. Creating a buffer for this route will give the pipe
    Layout for the given Pipe diameter.
    """
    v.to_lines(input='TankPoints', output='JoinedTankPoints', flags=O)
    v.net_spanningtree(input='JoinedTankPoints', output='Layout2', flags=O)
    v.buffer(input='Layout2', output='Layout2_Buffer', distance=dia, flags=O)

    # Prepare Map for the Layout
    v.db_addcolumn(map='Buildings', columns='color varchar(10)')
    v.db_addcolumn(map='TankPoints', columns='size double precision')
    for id, color in enumerate(Colors, start=1):
        whr = 'id like %s' % id
        v.db_update(map='Buildings', column='color', where=whr, value=color)
    v.db_update(map='TankPoints', column='size', value=10)
    v.db_update(map='TankPoints', column='size', value=20, where='id like 1')
    ps = Module('ps.map')
    ps(input=Join('Test1', '#ps_scripts', 'GenLayout.psmap'),
       output='PipeLayout.ps',
       flags=O)

    #Removing the GRASS Vectors
Exemplo n.º 5
0
def main(opts, flgs):
    TMPVECT = []
    DEBUG = True if flgs['d'] else False
    atexit.register(cleanup, vect=TMPVECT, debug=DEBUG)
    # check input maps
    rhydro = ['kind_label', 'discharge', 'id_point', 'id_plant']
    rother = ['kind_label', 'discharge', 'id_point', 'id_plant']
    ovwr = overwrite()

    try:
        hydro = check_required_columns(opts['hydro'], int(opts['hydro_layer']),
                                       rhydro, 'hydro')
        if opts['other']:
            other = check_required_columns(opts['other'], opts['other_layer'],
                                           rother, 'other')
        else:
            other = None
        #minflow = check_float_or_raster(opts['minflow'])
    except ParameterError as exc:
        exception2error(exc)

    # start working
    hydro.open('r')
    el, mset = (opts['elevation'].split('@') if '@' in opts['elevation'] else
                (opts['elevation'], ''))
    elev = RasterRow(name=el, mapset=mset)
    elev.open('r')
    #import ipdb; ipdb.set_trace()
    plants, skipped = read_plants(hydro,
                                  elev=elev,
                                  restitution=opts['hydro_kind_turbine'],
                                  intake=opts['hydro_kind_intake'])
    hydro.close()
    rvname, rvmset = (opts['river'].split('@') if '@' in opts['river'] else
                      (opts['river'], ''))

    vplants = opts['output_plants'] if opts['output_plants'] else 'tmpplants'
    #FIXME: I try with tmpplants in my mapset and it doesn'work
    if opts['output_plants'] == '':
        TMPVECT.append(vplants)
    with VectorTopo(rvname, rvmset, mode='r') as river:
        write_plants(plants, vplants, river, elev, overwrite=ovwr)

    if skipped:
        for skip in skipped:
            print("Plant: %r, Point: %r, kind: %r" % skip)
    elev.close()

    # compute a buffer around the plants
    buff = vplants + 'buff'
    v.buffer(input=vplants,
             type='line',
             output=buff,
             distance=0.1,
             overwrite=ovwr)
    TMPVECT.append(buff)
    # return all the river segments that are not already with plants
    v.overlay(flags='t',
              ainput=opts['river'],
              atype='line',
              binput=buff,
              operator='not',
              output=opts['output_streams'],
              overwrite=ovwr)