[GRASS-user] Updating v.net-report results directly to attribute table

Johannes Radinger johannesradinger at gmail.com
Wed Jun 29 02:26:50 PDT 2016


Hi all,

is there an easy way to transfer the information reported by v.net
(operation=report)
directly to the attribute table of the vector network (arc-table)?

The approach I am using so far is to create an temporary database table
(using python)
where I store the output from v.net operation=report, and then use a SQL
statement to update the original arc-table from the temporary table:

###########
fidimo_db.execute('''CREATE TEMP TABLE arcs_temp
(cat INTEGER, from INTEGER, to INTEGER)''')

# Get for each arc the orig cat for the start (from) and end point (to)
e = [(int(x.split()[0]),int(x.split()[1]),int(x.split()[2])) for x in
grass.read_command("v.net",
quiet=True,
input="my_net",
operation="report",
arc_layer=3).splitlines()]
my_db.executemany("INSERT INTO arcs_tmp (cat, from, to) VALUES (?,?,?)", e)

my_db.execute('''UPDATE arcs SET
from = (SELECT from FROM arcs_tmp WHERE cat=arcs.cat),
to = (SELECT to FROM arcs_tmp WHERE cat=arcs.cat)
WHERE EXISTS (SELECT cat FROM arcs_tmp WHERE cat=arcs.cat)''')
##########

That approach works for me, but I was wondering if there is something
easier/more direct? However it seems a direct update of the attribute table
is not included in v.net. The module v.db.update has an option for adding
start/end points of lines, however this refers to coordinate pairs rather
than to category values of nodes in a network.

Any other ideas?

Best,
Johannes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20160629/79f91952/attachment.html>


More information about the grass-user mailing list