I am rerunning code in GRASS that has worked in the past (about six months ago) and am now having problems.
In the GUI, I have created a new mapset and imported the 'SimplifedCoastline' file to the location (and set the default region based of the coastline's extent) before entering the code below into the Python Shell within GRASS. The objective is to create a visibility graph of shortest paths/lines between the points (centroids.txt) while going around the coastline as an obstacle.
import os import grass.script as gscript directory = r"E:\CollabProject\VisibilityAnalysis\VisibilityInputs\IntegerInputs" os.listdir(directory) centroids = open(os.path.join(directory, "Centroids.txt"), 'r') data = centroids.read() vn = "Centroids_visibility" gscript.run_command("v.net.visibility",input="SimplifiedCoastline", output=vn, coordinate=data) outname = "E:\CollabProject\VisibilityAnalysis\VisibilityOutputs" gscript.run_command("v.out.ogr", input=vn, type="line", dsn=outname, output="visibility_output.shp")
The v.out.ogr command results in:
Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\OSGEO4~1\apps\grass\grass-7.2.2\etc\python\grass\script\core.py", line 410, in run_command return handle_errors(returncode, returncode, args, kwargs) File "C:\OSGEO4~1\apps\grass\grass-7.2.2\etc\python\grass\script\core.py", line 329, in handle_errors returncode=returncode) CalledModuleError: Module run None ['v.out.ogr', 'dsn=E:\\CollabProject\\VisibilityAnalysis\\VisibilityOutputs', 'input=Centroids_visibility', 'type=line', 'output=visibility_output.shp'] ended with error Process ended with non-zero return code 1. See errors in the (error) output.
I'm not sure if it is failing because of an issue with v.out.ogr or perhaps because v.net.visibility isn't running correctly and creating an empty output, so therefore v.out.ogr can't run properly?
I have tried:
- running this code on several other computers, as some forum posts suggested this error could result from GDAL conflicts from downloading through OSGeo
- downloading GRASS alone onto a computer and running the code; downloading GRASS and QGIS onto a computer and running the code
- importing the data from a shapefile rather than text file
- running the code on a test dataset with only 27 points so it shouldn't be maxing out data limits
- going through the documentation for v.net.visibility and v.out.ogr and searching on forums
I seek any suggestions on how to correct this, as well as view the output of v.net.visibility to confirm it is being created correctly.
I can view the visibility graph that is being created in GRASS' Map Display so I know it exists, but I can't export it using v.out.ogr. The error I receive when trying to export it through the Python Shell is above; the error I receive when trying to export it through the point and click method is:
v.out.ogr input=inputdatatestttt@PERMANENT output=E:\CollabProject\VisibilityAnalysis\VisibilityOutputs\visgraphout format=ESRI_Shapefile WARNING: No attribute table found -> using only category numbers as attributes Exporting 2470954 features... WARNING: 2470954 features without category were skipped. Features without category are written only when -c flag is given. WARNING: Output layer is empty, no features written v.out.ogr complete. 0 features (Line String type) written to <inputdatatestttt> (ESRI_Shapefile format).
I'm not sure why the visibility graph is being created without attributes or how to fix this.