0

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.

enter image description here

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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
uetli
  • 85
  • 10

1 Answers1

2

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?

gene
  • 54,868
  • 3
  • 110
  • 187
  • 1
    In addition, see also the new GRASS GIS 7 vector classes: https://grass.osgeo.org/grass71/manuals/libpython/pygrass_vector.html – markusN Sep 01 '15 at 22:12