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.
-
1It is not a problem of Fiona here but a problem of NetworkX because you work with edges (How to get lines and nodes around the confluence point in a network system (line shapefile)?). and errors in your script (comment of Luke)gene– gene2016年10月29日 18:52:43 +00:00Commented Oct 29, 2016 at 18:52
-
I tried @Luke's comment and it works, thank you both for the advice! Should I close the question?Heinz– Heinz2016年10月30日 06:38:07 +00:00Commented Oct 30, 2016 at 6:38
1 Answer 1
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]))