I know similar questions have been asked several times, but none of the solutions seems suitable for my problem or don't work..
I computed flowlines using the r.flow tool from GRASS GIS, then I export these using v.out.ogr which gives me the files flowlines.dbf, flowlines.prj, flowlines.shp and flowlines.shx. The image shows the figure in GRASS of my flowlines over a DEM.
Now I need to read this shapefile into python and reproduce that same image in python. To read the file I downloaded the shapefile module, which seems to work fine, but after that I'm lost. I was told to use fiona module by a friend but it doesnt want to install on my ubuntu machine, not sure what's the problem, so a solution without fiona would be great..
Does anyone have good advice?
1 Answer 1
1) you don't need to export a shapefile. With the Python module GDAL (osgeo) you can read directly the layer from the GRASS folders hierarchy (look at GRASS 6 terminology)
from osgeo import ogr
# open the Grass layer shape1
ds = ogr.Open('/Users/grassdata/geol/MNT/vector/shape1/head')
layer = ds.GetLayer(0)
...
2) If you want to read the shapefile, you can use different modules -> look at Is it possible to look at the contents of Shapefile using Python without an ArcMap license?
-
1In addition, see also the new GRASS GIS 7 vector classes: grass.osgeo.org/grass71/manuals/libpython/pygrass_vector.htmlmarkusN– markusN2015年09月01日 22:12:01 +00:00Commented Sep 1, 2015 at 22:12