Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here
Bases: dict
Dictionary that remembers insertion order
and values equal to v (which defaults to None).
If key is not found, d is returned if given, otherwise KeyError is raised.
Pairs are returned in LIFO order if last is true or FIFO order if false.
If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items(): od[k] = v
Convert coordinates into a pixel row and col
>>> reg = Region()
>>> coor2pixel((reg.west, reg.north), reg)
(0.0, 0.0)
>>> coor2pixel((reg.east, reg.south), reg) == (reg.rows, reg.cols)
True
Copy a map
>>> copy('census', 'mycensus', 'vect')
>>> rename('mycensus', 'mynewcensus', 'vect')
>>> remove('mynewcensus', 'vect')
Return a list of tuple contining the names of the:
Return the path of the libname contained in the module.
Return the mapset of the raster map
>>> get_mapset_raster('elevation')
'PERMANENT'
Return the mapset of the vector map
>>> get_mapset_vector('census')
'PERMANENT'
Query a raster map for each point feature of a vector
Example
>>> from grass.pygrass.vector import VectorTopo
>>> from grass.pygrass.raster import RasterRow
>>> ele = RasterRow('elevation')
>>> copy('schools','myschools','vect')
>>> sch = VectorTopo('myschools')
>>> sch.open(mode='r')
>>> get_raster_for_points(sch, ele)
[(1, 633649.2856743174, 221412.94434781274, 145.06602)...
>>> sch.table.columns.add('elevation','double precision')
>>> 'elevation' in sch.table.columns
True
>>> get_raster_for_points(sch, ele, 'elevation')
True
>>> sch.table.filters.select('NAMESHORT','elevation')
Filters(u'SELECT NAMESHORT, elevation FROM myschools;')
>>> cur = sch.table.execute()
>>> cur.fetchall()
[(u'SWIFT CREEK', 145.06602), ... (u'9TH GRADE CTR', None)]
>>> remove('myschools','vect')
Parameters: |
|
---|
Return the current grass environment variables
>>> getenv("MAPSET")
'user1'
Return if the name is valid
>>> is_clean_name('census')
True
>>> is_clean_name('0census')
True
>>> is_clean_name('census?')
False
>>> is_clean_name('cénsus')
False
>>> import grass.lib.vector as libvect
>>> sorted(looking(libvect, '*by_box*'))
['Vect_select_areas_by_box', 'Vect_select_isles_by_box',
'Vect_select_lines_by_box', 'Vect_select_nodes_by_box']
Convert row and col of a pixel into a coordinates
>>> reg = Region()
>>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
True
>>> pixel2coor((reg.cols, reg.rows), reg) == (reg.south, reg.east)
True
Set sys.path looking in the the local directory GRASS directories.
Parameters: |
|
---|
“set_path” example working locally with the source code of a module (r.green) calling the function with all the parameters. Below it is reported the directory structure on the r.green module.
grass_prompt> pwd
~/Download/r.green/r.green.hydro/r.green.hydro.financial
grass_prompt> tree ../../../r.green
../../../r.green
|-- ...
|-- libgreen
| |-- pyfile1.py
| +-- pyfile2.py
+-- r.green.hydro
|-- Makefile
|-- libhydro
| |-- pyfile1.py
| +-- pyfile2.py
|-- r.green.hydro.*
+-- r.green.hydro.financial
|-- Makefile
|-- ...
+-- r.green.hydro.financial.py
21 directories, 125 files
in the source code the function is called with the following parameters:
set_path('r.green', 'libhydro', '..')
set_path('r.green', 'libgreen', os.path.join('..', '..'))
when we are executing the module: r.green.hydro.financial locally from the command line:
grass_prompt> python r.green.hydro.financial.py --ui
In this way we are executing the local code even if the module was already installed as grass-addons and it is available in GRASS standards path.
The function is cheching if the dirname is provided and if the directory exists and it is available using the path provided as third parameter, if yes add the path to sys.path to be importable, otherwise it will check on GRASS GIS standard paths.
Split a list in chunk.
>>> for chunk in split_in_chunk(range(25)): print chunk
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
(10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
(20, 21, 22, 23, 24)
>>> for chunk in split_in_chunk(range(25), 3): print chunk
(0, 1, 2)
(3, 4, 5)
(6, 7, 8)
(9, 10, 11)
(12, 13, 14)
(15, 16, 17)
(18, 19, 20)
(21, 22, 23)
(24,)
Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here
Help Index | Topics Index | Keywords Index | Full Index
© 2003-2018 GRASS Development Team, GRASS GIS 7.0.7svn Reference Manual