[GRASS-user] Another r.stream.extract question

Bartolomei.Chris Bartolomei.Chris at ensco.com
Tue Oct 31 14:57:37 PDT 2017


In an effort to try and answer this myself, I tried the following:

(my stream vector map from r.stream.extract is "tmp_stream_vect")


v.db.addcolumn  map=tmp_stream_vect layer=1 columns="ReachTyp integer"

NewCat=`v.category input=tmp_stream_vect option=print layer=2`

v.db.update map=tmp_stream_vect layer=1 column=ReachTyp value="$NewCat"


which got me the following error:


ERROR: Error while executing: '0'
Traceback (most recent call last):
  File "C:/OSGeo4W64/apps/grass/grass-7.2.1/scripts/v.db.update.py", line 127, in <module>
    sys.exit(main())
  File "C:/OSGeo4W64/apps/grass/grass-7.2.1/scripts/v.db.update.py", line 118, in main
    grass.write_command('db.execute', input='-', database=database, driver=driver, stdin=cmd)
  File "C:\OSGEO4~1\apps\grass\grass-7.2.1\etc\python\grass\script\core.py", line 532, in write_command
    return handle_errors(returncode, returncode, args, kwargs)
  File "C:\OSGEO4~1\apps\grass\grass-7.2.1\etc\python\grass\script\core.py", line 329, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None ['db.execute', 'input=-', 'driver=sqlite', 'database=D:\\GRASSDATA\\UTM51\\ROI_Basin\\sqlite\\sqlite.db'] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.


My guess is it didn't like having a string of values piped into the "value=" option of v.db.update.

Is there a way to assign values to the whole column at once?

Here is what v.category provides as the cat values for each layer (there are both line and point features):


GRASS 7.2.1> v.category input=tmp_stream_vect option=print layer=2
2
0
0
0
0
0
0
1
1
0
0
1
1
0
0
0
0
1
1
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
1
1
GRASS 7.2.1> v.category input=tmp_stream_vect option=print layer=1
29
18
18
4
4
3
3
11
11
6
6
15
15
7
7
1
1
14
14
2
2
8
8
13
13
16
16
17
17
23
23
9
9
5
5
20
20
24
24
19
19
29
29
GRASS 7.2.1>


Chris Bartolomei P.E.
bartolomei.chris at ensco.com
________________________________
From: Bartolomei.Chris
Sent: Tuesday, October 31, 2017 1:56:58 PM
To: grass-user
Subject: Another r.stream.extract question


Hi all - While I see r.stream.extract is up for discussion (I didn't want to jump in on Rich's thread) could I ask for a bit of help?

I'm trying to get the cat values in layer 2 of the stream vector map that r.stream.extract creates into a separate column of layer 1 of the same map... clear as mud? Can I create a layer 3 with the cat values from layer 1 and then create a new column and populate it with the cat values from layer 2? Is there a way in the SQLite to tell it to select attributes from 2 different layers?


In more detail:  r.stream.extract creates a vector map of the stream system, layer 1 has CAT values of each of the stream reaches (internal feature ID) and an attribute for the type of reach (starting reach or intermediate, values are 0 and 1 respectively). Layer 2 of that same map has CAT values for the type of reach as well but introduce a value of 2 for the stream outlet - i.e values 0, 1, and 2 for starting reach, intermediate reach, and stream outlet(s). The problem is I would like the nodes (junctions - i.e. type=point) in a point map with their original cat values (CAT in layer 1) and the reach type values (CAT in layer 2) as the attributes. I would think v.extract would work but the attributes are on 2 different layers.  I tried to create a separate table for layer 2: there are 22 point features in my stream map but only three records are added to the table for layer 2 because the key column is "cat" for layer 2 which only has the values of 0, 1, or 2 for all the features. I'm beside myself trying to figure out how to combine the two layers... Has anyone done something like this?

Thanks!

Chris


Chris Bartolomei P.E.
bartolomei.chris at ensco.com

________________________________

The information contained in this email message is intended only for the use of the individual(s) to whom it is addressed and may contain information that is privileged and sensitive. If you are not the intended recipient, or otherwise have received this communication in error, please notify the sender immediately by email at the above referenced address and note that any further dissemination, distribution or copying of this communication is strictly prohibited.

The U.S. Export Control Laws regulate the export and re-export of technology originating in the United States. This includes the electronic transmission of information and software to foreign countries and to certain foreign nationals. Recipient agrees to abide by these laws and their regulations -- including the U.S. Department of Commerce Export Administration Regulations and the U.S. Department of State International Traffic in Arms Regulations -- and not to transfer, by electronic transmission or otherwise, any content derived from this email to either a foreign national or a foreign destination in violation of such laws.


More information about the grass-user mailing list