[GRASS-user] GRASS GIS 7.8.5 r.water.outlet

Hi,

I am trying to use the r.water.outlet function in a python script in GRASS. For the ‘coordinates’ parameter my x,y coordinate values are stored in two columns in the attribute table of another layer. Is there a way to access these values from the attribute table directly?

Thanks,

Kelsey

On 5/19/21 9:52 PM, Kelsey Wong wrote:

Hi,

I am trying to use the r.water.outlet function in a python script in GRASS. For the ‘coordinates’ parameter my x,y coordinate values are stored in two columns in the attribute table of another layer. Is there a way to access these values from the attribute table directly?

The grass.script command 'parse_command' returns the module output as a python dict, so something like:

import grass.script as gscript

xy = gscript.parse_command('v.db.select', map_="another_table", columns=['x_coord'_column, 'y_coord_column'], separator="comma")

will probably get you on the right track. If you have multiple points in the "another_table", then you'll have to loop thru the list, and run r.water.outlet on each pair separately.

The addon `r.streams.basins`, on the other hand, can deal with a list of coordinate pairs. So if you convert the output of v.db.select into a comma separated list like: x1,y1,x2,y2, x3,y3... then you can get all basins in one go. What's more, this addon can accept a point vector of drainage outlet points, and prepare basins for each. So if your "another_table" is indeed a point vector, and the two columns in the attribute table are the point coordinates, then no need to extract coordinate from the attrib table. just feed the point vector to the `points` parameter of `r.streams.basins`.

Thanks,

Kelsey
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

Hi Kelesy,

In addition to Michas very good suggestions you can try the table module in pygrass: https://grass.osgeo.org/grass78/manuals/libpython/pygrass.vector.html?highlight=table#module-pygrass.vector.table
Or the db_select module from the scripting library: https://grass.osgeo.org/grass78/manuals/libpython/script.html?highlight=select#script.db.db_select for all kind of tables
Or the vector_db_select module: https://grass.osgeo.org/grass78/manuals/libpython/script.html?highlight=select#script.vector.vector_db_select for tables connected to vector maps
To get the coordinates in Python...

Cheers
Stefan

-----Original Message-----
From: grass-user <grass-user-bounces@lists.osgeo.org> On Behalf Of Kelsey Wong
Sent: onsdag 19. mai 2021 20:52
To: grass-user@lists.osgeo.org
Subject: [GRASS-user] GRASS GIS 7.8.5 r.water.outlet

Hi,

I am trying to use the r.water.outlet function in a python script in GRASS. For the 'coordinates' parameter my x,y coordinate values are stored in two columns in the attribute table of another layer. Is there a way to access these values from the attribute table directly?

Thanks,

Kelsey
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fgrass-user&amp;data=04|01||d2729cbc538a4733864908d91af73bb6|6cef373021314901831055b3abf02c73|0|0|637570471438665050|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&amp;sdata=OrVazRa4Mkas0DxUkYtb8i0lfHwFul06zoYFzxO0Dhs%3D&amp;reserved=0

Hi Micha and Stefan,

Thank you for you suggestions! I was able to extract the attributes into a list, and use the r.water.outlet to create the watersheds.

I now have a number of different maps in grass, each with one record representing a different watershed. I was wondering if there was a grass module that would compile each record/watershed from each map into a singular map with each watershed having one record? I’ve tried v.patch but it seems to merge all of the watersheds into one record in the final output map.

Thanks,

Kelsey

On May 19, 2021, at 12:24 PM, Stefan Blumentrath <Stefan.Blumentrath@nina.no> wrote:

Hi Kelesy,

In addition to Michas very good suggestions you can try the table module in pygrass: https://grass.osgeo.org/grass78/manuals/libpython/pygrass.vector.html?highlight=table#module-pygrass.vector.table
Or the db_select module from the scripting library: https://grass.osgeo.org/grass78/manuals/libpython/script.html?highlight=select#script.db.db_select for all kind of tables
Or the vector_db_select module: https://grass.osgeo.org/grass78/manuals/libpython/script.html?highlight=select#script.vector.vector_db_select for tables connected to vector maps
To get the coordinates in Python...

Cheers
Stefan

-----Original Message-----
From: grass-user <grass-user-bounces@lists.osgeo.org> On Behalf Of Kelsey Wong
Sent: onsdag 19. mai 2021 20:52
To: grass-user@lists.osgeo.org
Subject: [GRASS-user] GRASS GIS 7.8.5 r.water.outlet

Hi,

I am trying to use the r.water.outlet function in a python script in GRASS. For the 'coordinates' parameter my x,y coordinate values are stored in two columns in the attribute table of another layer. Is there a way to access these values from the attribute table directly?

Thanks,

Kelsey
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fgrass-user&amp;data=04|01||d2729cbc538a4733864908d91af73bb6|6cef373021314901831055b3abf02c73|0|0|637570471438665050|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&amp;sdata=OrVazRa4Mkas0DxUkYtb8i0lfHwFul06zoYFzxO0Dhs%3D&amp;reserved=0