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.