[GRASS-user] v.net.path extension

Robbie Heremans robbie.heremans at gmail.com
Sun Sep 19 15:18:58 EDT 2010


Hi Mohammed,

Thanks for your answer. However, when I tried to run your python script I
get errors. I run GRASS 6.4.0 on a Mac, downloaded the file wx.path.py,
changed permissions. This is what I get:

Welcome to GRASS 6.4.0 (2010)
GRASS homepage:                          http://grass.osgeo.org/
This version running thru:               Bash Shell (/bin/bash)
Help is available with the command:      g.manual -i
See the licence terms with:              g.version -c
Start the GUI with:                      g.gui wxpython
When ready to quit enter:                exit

GRASS 6.4.0 (spearfish60):~ > ls -l wx.path.py
-rwxr-xr-x@ 1 robbie  staff  12384 18 sep 10:38 wx.path.py
GRASS 6.4.0 (spearfish60):~ > g.gisenv
GISDBASE=/Users/robbie/grassdata
LOCATION_NAME=spearfish60
MAPSET=PERMANENT
GRASS_GUI=text
GRASS 6.4.0 (spearfish60):~ > python wx.path.py
Traceback (most recent call last):
  File "wx.path.py", line 371, in <module>
    path_app = PathApp(0)
  File
"/Users/Shared/unix/wxpython-snow/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py",
line 7978, in __init__
  File
"/Users/Shared/unix/wxpython-snow/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py",
line 7552, in _BootstrapApp
  File "wx.path.py", line 361, in OnInit
    size=globalvar.MAP_WINDOW_SIZE)
  File "wx.path.py", line 131, in __init__
    self.AddToolbar(toolb)
  File "wx.path.py", line 336, in AddToolbar
    self.toolbars['map'] = toolbars.MapToolbar(self, self.Map)
  File
"/Applications/GRASS-6.4.app/Contents/MacOS/etc/wxpython/gui_modules/toolbars.py",
line 165, in __init__
    log = self.parent.gismanager.goutput
AttributeError: 'NoneType' object has no attribute 'goutput'

So, I tried to run an example from
http://grass.osgeo.org/wiki/GRASS_and_Python.

I created a new text-file with following code, saved it to regnrowcol.py,
changed permissions,...

#!/usr/bin/env python#-*- coding:utf-8
-*-###############################################################################
MODULE:       g.region.resolution# AUTHOR(S):    based on a post at
GRASS-USER mailing list [1]               # PURPOSE:	Parses "g.region
-g", prints out number of rows, cols# COPYLEFT:     ;-)# COMMENT:
...a lot of comments to be easy-to-read for/by
beginners################################################################################%Module#%
description: Print number of rows, cols of current geographic region#%
keywords: region#%end
 # importing required modulesimport sys # the sys module [2]from
grass.script import core as grass # the core module [3]
 # information about imported modules can be obtained using the dir()
function# e.g.: dir(sys)
 # define the "main" function: get number of rows, cols of regiondef main():

    # #######################################################################
    # the following commented code works but is kept only for learning purposes

    ## assigning the output of the command "g.region -g" in a string
called "return_rows_x_cols"
    # return_rows_x_cols = grass.read_command('g.region', flags = 'g')

    ## parsing arguments of interest (rows, cols) in a dictionary
named "rows_x_cols"
    # rows_x_cols = grass.parse_key_val(return_rows_x_cols)

    ## selectively print rows, cols from the dictionary "rows_x_cols"
    # print 'rows=%d \ncols=%d' % (int(rows_x_cols['rows']),
int(rows_x_cols['cols']))

    # #######################################################################

    # faster/ easier way: use of the "grass.region()" function
    gregion = grass.region()
    rows = gregion['rows']
    cols = gregion['cols']

    # print rows, cols properly formated
    print 'rows=%d \ncols=%d' % (rows, cols)
 # this "if" condition instructs execution of code contained in this
script, *only* if the script is being executed directly if __name__ ==
"__main__": # this allows the script to be used as a module in other
scripts or as a standalone script
    options, flags = grass.parser() #

sys.exit(main()) #

This is also not working:

GRASS 6.4.0 (spearfish60):~ > ls -l regnrowcol.py
-rw-r--r--@ 1 robbie  wheel  1839 19 sep 21:01 regnrowcol.py
GRASS 6.4.0 (spearfish60):~ > chmod a+x regnrowcol.py
GRASS 6.4.0 (spearfish60):~ > ls -l regnrowcol.py
-rwxr-xr-x@ 1 robbie  wheel  1839 19 sep 21:01 regnrowcol.py
GRASS 6.4.0 (spearfish60):~ > g.region -p
projection: 1 (UTM)
zone:       13
datum:      nad27
ellipsoid:  clark66
north:      4928000
south:      4914000
west:       590000
east:       609000
nsres:      100
ewres:      100
rows:       140
cols:       190
cells:      26600
GRASS 6.4.0 (spearfish60):~ > python regnrowcol.py
Line too long or missing newline at line 54

What can be the problem? Apparently, I'm missing a clue to run python
scripts (on my Mac).

Robbie



2010/9/18 Mohammed Rashad <mohammedrashadkm at gmail.com>

> try
> wx.path python version.
> but it will not fulfil your needs but more interactive than v.net.path
> now it only support spearfish dataset
> will extend to use any data if anyone needs
>
> http://svn.osgeo.org/grass/grass-addons/gui/wxpython/wx.path/wx.path.py
>
>
> On Fri, Sep 17, 2010 at 7:01 PM, Robbie Heremans <
> robbie.heremans at gmail.com> wrote:
>
>> Starting from a file with start and end positions  (x_start, y_start,
>> x_stop, y_stop) and a vector map of roads, I have to find places on the
>> roads where most people pass, assuming they will use the shortest path or
>> path with the least cost.
>>
>> Is there a command in Grass that can do this (ic v.net.path for each
>> record and summary  map of these shortest paths)?
>>
>> Any suggestions/examples?
>>
>> Robbie
>>
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-user
>>
>>
>
>
> --
> Rashad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20100919/8ddd1dfd/attachment-0001.html


More information about the grass-user mailing list