I wrote the following code to use
r.water.outlet module in GRASS GIS:
import os import sys #set up GRASS environment variables sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python')) import grass.script as g import grass.script.setup as gsetup gisbase = os.environ['GISBASE'] gisdb = 'C:\Users\Heinz\Documents\grassdata' location = 'newLocation' mapset = 'TC' gsetup.init(gisbase, gisdb, location, mapset) #csv file reading and importation import csv rows = list(open('tc_sta.csv')) totalrows = len(rows) - 1 #loop through the csv(coordinates) file in r.water.outlet module f = open('tc_sta.csv', 'r') element = list(csv.reader(f)) i = 0 j = 0 while True: if i <= totalrows: g.run_command('r.water.outlet', drainage = 'dra', basin = 'b' + str(i + 1), east = element[i][j], north = element[i][j + 1]) i = i + 1 else: break #print all files in grass database to check results of the module print g.read_command('g.list', _type='rast')
I stored the coordinates in tc_sta.csv, and input them to
r.water.outlet to calculate drainage area of each point.
Although the output raster files were fine, I had to export them as ESRI shapefile and use QGIS to calculate area of polygons, and finally store the area value of each point in a csv file containing coordinates and its related drainage area.
I felt that the procedure was not efficient, and is there a way I could calculate and store the output area immediately after I run