Note: A new GRASS GIS stable version has been released: GRASS GIS 7.8. 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(test_raster_name)
>>> 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 or class object with coords() method |
---|
Return True if the map is open False otherwise.
>>> ele = RasterAbstractBase(test_raster_name)
>>> 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(test_raster_name)
>>> name = ele.name_mapset().split("@")
>>> name
[u'abstract_test_map']
Set the computational region that can be different from the current region settings. This region will be used by all raster map layers that are opened in the same process.
The GRASS region settings will not be modified.
Set the computational region from a map, if rastername and mapset is not specify, use itself. This region will be used by all raster map layers that are opened in the same process.
The GRASS region settings will not be modified.
call C function Rast_get_cellhd, Rast_set_window
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.
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
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
>>> import ctypes
>>> import grass.lib.raster as libraster
>>> hist = libraster.History()
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
- Raises IndexError if [row] is out of range
Examples:
>>> elev = RasterRow(test_raster_name) >>> elev.exist() True >>> elev.is_open() False >>> elev.open() >>> elev.is_open() True >>> elev.has_cats() True >>> elev.mode u'r' >>> elev.mtype 'CELL' >>> elev.num_cats() 16 >>> elev.info.range (11, 44) >>> elev.info.cols 4 >>> elev.info.rows 4Editing the history
>>> elev.hist.read() >>> elev.hist.title = "A test map" >>> elev.hist.write() >>> elev.hist.title 'A test map' >>> elev.hist.keyword 'This is a test map'>>> attrs = list(elev.hist) >>> attrs[0] ('name', u'Raster_test_map') >>> attrs[2] ('mtype', '')Each Raster map have an attribute call cats that allow user to interact with the raster categories.
>>> elev.cats [(u'A', 11, None), (u'B', 12, None), ... (u'P', 44, None)]>>> elev.cats.labels() [u'A', u'B', u'C', u'D', u'E', u'F', u'G', u'H', u'I', u'J', u'K', u'L', u'M', u'n', u'O', u'P'] >>> elev.cats[0] (u'A', 11, None) >>> elev.cats[2] (u'C', 13, None) >>> elev.cats[0] = ('AA', 11) >>> elev.cats[1] = ('BB', 12) >>> elev.cats.write() >>> elev.cats.read() >>> elev.cats[0] (u'AA', 11, None) >>> elev.cats[1] (u'BB', 12, None)Open a raster map using the with statement:
>>> with RasterRow(test_raster_name) as elev: ... for row in elev: ... row Buffer([11, 21, 31, 41], dtype=int32) Buffer([12, 22, 32, 42], dtype=int32) Buffer([13, 23, 33, 43], dtype=int32) Buffer([14, 24, 34, 44], dtype=int32)>>> elev.is_open() False
Private method that return the row using the read mode call the Rast_get_row C function.
Parameters: |
|
---|
>>> elev = RasterRow(test_raster_name)
>>> elev.open()
>>> elev[0]
Buffer([11, 21, 31, 41], dtype=int32)
>>> elev.get_row(0)
Buffer([11, 21, 31, 41], dtype=int32)
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: |
|
---|
Write the row using the segment.put_row method
Parameters: | row (Buffer object) – a Row object to insert into raster |
---|
Input and output must have the same type in case of row copy
>>> map_a = RasterSegment(test_raster_name)
>>> map_b = RasterSegment(test_raster_name + "_segment")
>>> map_a.open('r')
>>> map_b.open('w', mtype="CELL", overwrite=True)
>>> for row in xrange(map_a.info.rows):
... map_b[row] = map_a[row] + 1000
>>> map_a.close()
>>> map_b.close()
>>> map_b = RasterSegment(test_raster_name + "_segment")
>>> map_b.open("r")
>>> for row in map_b:
... row
Buffer([1011, 1021, 1031, 1041], dtype=int32)
Buffer([1012, 1022, 1032, 1042], dtype=int32)
Buffer([1013, 1023, 1033, 1043], dtype=int32)
Buffer([1014, 1024, 1034, 1044], dtype=int32)
>>> map_b.close()
Save a numpy array to a raster map
Parameters: |
|
---|
Return a numpy array from a raster map
Parameters: | rastname (str) – the name of raster map |
---|---|
Parar str mapset: | |
the name of mapset containig raster map |
Convert a raster map layer into a string with 32Bit ARGB, 24Bit RGB or 8Bit Gray little endian encoding.
Return a numpy array from a raster map of type uint8 that contains the colored map data as 32 bit ARGB, 32Bit RGB or 8 bit image
Parameters: |
|
---|---|
Returns: | A numpy array of size rows*cols*4 in case of ARGB, RGB and rows*cols*1 in case of gray scale |
Attention: This function will change the computational raster region of the current process while running.
Note: A new GRASS GIS stable version has been released: GRASS GIS 7.8. Go directly to the new manual page here
Help Index | Topics Index | Keywords Index | Full Index
© 2003-2020 GRASS Development Team, GRASS GIS 7.6.2dev Reference Manual