2

I tried the following script to get drainage basin of specific points:

import sys, os
import fiona
import networkx as nx
import itertools
from shapely.geometry import Point, LineString
import numpy
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))
import grass.script as g
print 'import GRASS ok'
import grass.script.setup as gsetup
gisbase = os.environ['GISBASE']
gisdb = 'C:\Users\Heinz\Documents\grassdata'
location = 'nl'
mapset = 'nl' 
gsetup.init(gisbase, gisdb, location, mapset)
H = nx.Graph()
for line in fiona.open('tc_line.shp'):
 for seg_start, seg_end in itertools.izip(line['geometry']['coordinates'],line['geometry']['coordinates'][1:]):
 H.add_edge(seg_start, seg_end)
edge_node = []
i = 1
for node in H.nodes_iter():
 if H.degree(node) > 2:
 for edge in H.edges(node):
 print edge
 g.run_command('r.water.outlet', overwrite = True, input = 'dra', basin = 'netx' + str(i), coordinates = edge[1][0], edge[1][1])

And the script ran fine until I add g.run_command('r.water.outlet', overwrite = True, input = 'dra', basin = 'netx' + str(i), coordinates = edge[1][0], edge[1][1]), and the error showed up:

File "C:\Users\Heinz\Desktop\netx_test.py", line 29
g.run_command('r.water.outlet', overwrite = True, input = 'dra', basin = 'netx' + str(i), coordinates = edge[1][0], edge[1][1])
SyntaxError: non-keyword arg after keyword arg
[Finished in 0.1s]

So I am wondering that could Fiona work with GRASSGIS? And I want to know how to solve this problem.

I am working under Win10 64bits with python 2.7.12, Fiona 1.7.0, networkx 1.11 and GRASS GIS 7.0.5 installed via OSGeo4W pacakge.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 29, 2016 at 8:48
2

1 Answer 1

3

The error message is self explanatory. You have a non keyword argument after your keyword arguments.

coordinates = edge[1][0] is being interpreted as the entire (keyword) argument and edge[1][1] as a separate (non-keyword) argument.

Try the following instead:

g.run_command('r.water.outlet', overwrite = True, input = 'dra', basin = 'netx' + str(i), coordinates = (edge[1][0], edge[1][1])) 
answered Oct 30, 2016 at 6:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.