0

Goal: to store the sum of all values (lengths) of a vector map in a variable inside a Python script. This variable will later be shown to the user in a GUI. The computation time has to be as low as possible as well.

For the development of a tool I need to calculate certain parameters. I want to do this inside a Python script and all data is coming from GRASS GIS.

The data for this example is a vector map contain 26 lines, but this question is more about the general concept.

Here is a code snippet of my progress so far:

#import
from grass.exceptions import CalledModuleError
from grass.pygrass.vector import VectorTopo

#create transect lines
gscript.run_command('v.transects', overwrite=True, input=center_line, 
output=transect_line, transect_spacing=0.05, dleft=0.15 , dright=0.15, 
metric='along', transect_perpendicular='line')

#compute width(sum(val_features)/ nFeatures)
transects = VectorTopo(transect_line_clipped)
transects.open(mode='r')
        #nFeatures
nFeatures = transects.number_of("lines")

        #val_features
<>

I have tried the following approaches but keep running into errors:

Which of these approaches is recommended taking into account my purpose and computation time?

The data has the following structure:

  • Type: Line
  • ID: unique
  • Length: x (float)
  • Layer: 1
  • Category: unique

EDIT 30.05.2019

I can access my coordinates of the line via

test = gscript.run_command('v.out.ascii', overwrite=True, input=transect_line_clipped, output=attr)

Which I can put into a NumPy array:

np.loadtxt()

But this does not provide me with the length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.