Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here
Created on Fri Aug 17 16:05:25 2012
@author: pietro
Bases: object
Raster_abstract_base: The base class from which all sub-classes inherit. It does not implement any row or map access methods:
Return True if the map already exist, and set the mapset if were not set.
call the C function G_find_raster.
>>> ele = RasterAbstractBase('elevation')
>>> ele.exist()
True
Return the full name of a raster map: name@mapset
This method returns the pixel value of a given pair of coordinates:
Parameters: | point – pair of coordinates in tuple object |
---|
Return True if the map is open False otherwise.
>>> ele = RasterAbstractBase('elevation')
>>> ele.is_open()
False
Private method to get the Raster type
Private method to return the Raster name
Return the full name of the Raster.
>>> ele = RasterAbstractBase('elevation')
>>> ele.name_mapset()
u'elevation@PERMANENT'
Created on Thu Jun 28 17:44:14 2012
@author: pietro
Bases: list
I would like to add the following functions:
Getting the umber of cats: Rast_number_of_cats() <- Important for ith access
Getting and setting the title: Rast_get_cats_title() Rast_set_cats_title()
Do not use these functions for category access: Rast_get_cat() and the specialized types for CELL, FCELL and DCELL. Since these functions are working on hidden static buffer.
Use the ith-get methods: Rast_get_ith_c_cat() Rast_get_ith_f_cat() Rast_get_ith_d_cat()
This can be implemented using an iterator too. So that the category object provides the [] access operator to the categories, returning a tuple (label, min, max). Using this, the category object must be aware of its raster map type.
Set categories using: Rast_set_c_cat() Rast_set_f_cat() Rast_set_d_cat()
Misc: Rast_sort_cats() Rast_copy_cats() <- This should be wrapped so that categories from an existing Python category class are copied.
>>> import grass.lib.raster as libraster
>>> import ctypes
>>> from grass.pygrass.raster.category import Category
>>> cats = Category('landuse')
>>> cats.read()
>>> cats.labels()
['undefined', 'developed', 'agriculture', ..., 'water', 'sediment']
>>> cats[0]
('undefined', 0, None)
>>> cats[1]
('developed', 1, None)
Copy from another Category class
Parameters: | category (Category object) – Category class to be copied |
---|
Set or obtain raster data type
Read categories from a raster map
The category file for raster map name in mapset is read into the cats structure. If there is an error reading the category file, a diagnostic message is printed.
Copy categories from a rules file, default separetor is ‘:’, the columns must be: min and/or max and label.
1:forest
2:road
3:urban
0.:0.5:forest
0.5:1.0:road
1.0:1.5:urban
Parameters: |
|
---|
Set or obtain raster title
Copy categories from a rules file, default separetor is ‘:’, the columns must be: min and/or max and label.
1:forest
2:road
3:urban
0.:0.5:forest
0.5:1.0:road
1.0:1.5:urban
Parameters: |
|
---|
Created on Thu Jun 28 17:44:45 2012
@author: pietro
Bases: object
History class help to manage all the metadata of a raster map
>>> import grass.lib.gis as libgis
>>> libgis.G_gisinit('')
>>> hist = History('elevation')
>>> hist.read()
>>> hist.creator
'helena'
>>> hist.src1
''
>>> hist.src2
''
>>> hist.keyword
'generated by r.proj'
>>> hist.date
datetime.datetime(2006, 11, 7, 1, 9, 51)
>>> hist.mapset
'PERMANENT'
>>> hist.maptype
'raster'
>>> hist.title
'elev_ned10m'
Set or obtain the creator of map
Set or obtain the date of map
Set or obtain the keywords of map
Set or obtain the mapset of map
Set or obtain the type of map
Read the history of map, users need to use this function to obtain all the information of map.
>>> import grass.lib.gis as libgis
>>> libgis.G_gisinit('')
>>> import ctypes
>>> import grass.lib.raster as libraster
>>> hist = libraster.History()
>>> libraster.Rast_read_history(ctypes.c_char_p('elevation'),
... ctypes.c_char_p(''),
... ctypes.byref(hist))
0
>>> libraster.Rast_get_history(ctypes.byref(hist),
... libraster.HIST_MAPID)
'Tue Nov 7 01:09:51 2006'
Set or obtain the first source of map
Set or obtain the second source of map
Set or obtain the title of map
Created on Mon Jun 18 13:22:38 2012
@author: pietro
Created on Mon Jun 11 18:02:27 2012
@author: pietro
Bases: object
Flush pending updates to disk. Forces all pending updates generated by Segment_put() to be written to the segment file seg. Must be called after the final Segment_put() to force all pending updates to disk. Must also be called before the first call to Segment_get_row.
The segmentation routines require a disk file to be used for paging segments in and out of memory. This routine formats the file open for write on file descriptor fd for use as a segment file.
Bases: grass.pygrass.raster.abstract.RasterAbstractBase
Raster_row_access”: Inherits: “Raster_abstract_base” and implements the default row access of the Rast library.
- Implements row access using row id
- The get_row() method must accept a Row object as argument that will be used for value storage, so no new buffer will be allocated
- Implements sequential writing of rows
- Implements indexed value read only access using the [row][col] operator
- Implements the [row] read method that returns a new Row object
- Writing is limited using the put_row() method which accepts a Row as argument
- No mathematical operation like __add__ and stuff for the Raster object (only for rows), since r.mapcalc is more sophisticated and faster
Examples:
>>> elev = RasterRow('elevation')
>>> elev.exist()
True
>>> elev.is_open()
False
>>> elev.open()
>>> elev.is_open()
True
>>> elev.has_cats()
False
>>> elev.mode
u'r'
>>> elev.mtype
'FCELL'
>>> elev.num_cats()
0
>>> elev.info.range
(56, 156)
>>> elev.info
elevation@
rows: 1350
cols: 1500
north: 228500.0 south: 215000.0 nsres:10.0
east: 645000.0 west: 630000.0 ewres:10.0
range: 56, 156
proj: 99
Each Raster map have an attribute call cats that allow user to interact with the raster categories.
>>> land = RasterRow('geology')
>>> land.open()
>>> land.cats
[('Zml', 1, None),
...
('Tpyw', 1832, None)]
Open a raster map using the with statement:
>>> with RasterRow('elevation') as elev:
... for row in elev[:3]:
... row[:4]
...
Buffer([ 141.99613953, 141.27848816, 141.37904358, 142.29821777], dtype=float32)
Buffer([ 142.90461731, 142.39450073, 142.68611145, 143.59086609], dtype=float32)
Buffer([ 143.81854248, 143.54707336, 143.83972168, 144.59527588], dtype=float32)
>>> elev.is_open()
False
Private method that return the row using the read mode call the Rast_get_row C function.
Parameters: |
|
---|
>>> elev = RasterRow('elevation')
>>> elev.open()
>>> elev[0]
Buffer([ 141.99613953, 141.27848816, 141.37904358, ..., 58.40825272,
58.30711365, 58.18310547], dtype=float32)
>>> elev.get_row(0)
Buffer([ 141.99613953, 141.27848816, 141.37904358, ..., 58.40825272,
58.30711365, 58.18310547], dtype=float32)
Open the raster if exist or created a new one.
Parameters: |
|
---|
if the map already exist, automatically check the type and set:
- self.mtype
Set all the privite, attributes:
- self._fd;
- self._gtype
- self._rows and self._cols
Bases: pygrass.raster.RasterRow
Raster_row_cache_access”: The same as “Raster_row_access” but uses the ROWIO library for cached row access
This method returns the row using:
- the read mode and
- rowcache method
Parameters: |
|
---|
Open the raster if exist or created a new one.
Parameters: |
|
---|
Bases: grass.pygrass.raster.abstract.RasterAbstractBase
Raster_segment_access”: Inherits “Raster_abstract_base” and uses the segment library for cached randomly reading and writing access.
- Implements the [row][col] operator for read and write access using Segment_get() and Segment_put() functions internally
- Implements row read and write access with the [row] operator using Segment_get_row() Segment_put_row() internally
- Implements the get_row() and put_row() method using Segment_get_row() Segment_put_row() internally
- Implements the flush_segment() method
- Implements the copying of raster maps to segments and vice verse
- Overwrites the open and close methods
- No mathematical operation like __add__ and stuff for the Raster object (only for rows), since r.mapcalc is more sophisticated and faster
Close the map, copy the segment files to the map.
Parameters: | rm_temp_files (bool) – if True all the segments file will be removed |
---|
Return the map value using the segment.get method
Parameters: |
|
---|
Return the row using the segment.get_row method
Parameters: |
|
---|
Set or obtain the opening mode of raster
Open the map, if the map already exist: determine the map type and copy the map to the segment files; else, open a new segment map.
Parameters: |
|
---|
Write the value to the map using the segment.put method
Parameters: |
|
---|
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