pygrass package¶
Subpackages¶
- pygrass.gis package
- Submodules
- pygrass.gis.region module
RegionRegion.adjust()Region.align()Region.bottomRegion.byref()Region.cellsRegion.colsRegion.depthsRegion.eastRegion.ewresRegion.from_rast()Region.from_vect()Region.get_bbox()Region.get_current()Region.items()Region.keys()Region.northRegion.nsresRegion.projRegion.read()Region.read_default()Region.rowsRegion.set_bbox()Region.set_current()Region.set_raster_region()Region.southRegion.tbresRegion.topRegion.westRegion.write()Region.zoneRegion.zoom()
- Module contents
- pygrass.messages package
- pygrass.modules package
- Subpackages
- pygrass.modules.grid package
- pygrass.modules.interface package
- Submodules
- pygrass.modules.interface.docstring module
- pygrass.modules.interface.env module
- pygrass.modules.interface.flag module
- pygrass.modules.interface.module module
- pygrass.modules.interface.parameter module
- pygrass.modules.interface.read module
- pygrass.modules.interface.typedict module
- Module contents
- Submodules
- pygrass.modules.shortcuts module
- Module contents
- Subpackages
- pygrass.raster package
- Submodules
- pygrass.raster.abstract module
InfoRasterAbstractBaseRasterAbstractBase.cats_titleRasterAbstractBase.close()RasterAbstractBase.copy_cats()RasterAbstractBase.exist()RasterAbstractBase.fullname()RasterAbstractBase.get_cat()RasterAbstractBase.get_cats()RasterAbstractBase.get_value()RasterAbstractBase.has_cats()RasterAbstractBase.is_open()RasterAbstractBase.modeRasterAbstractBase.mtypeRasterAbstractBase.nameRasterAbstractBase.name_mapset()RasterAbstractBase.num_cats()RasterAbstractBase.overwriteRasterAbstractBase.read_cats()RasterAbstractBase.read_cats_rules()RasterAbstractBase.remove()RasterAbstractBase.rename()RasterAbstractBase.set_cat()RasterAbstractBase.set_cats()RasterAbstractBase.set_region()RasterAbstractBase.set_region_from_rast()RasterAbstractBase.sort_cats()RasterAbstractBase.write_cats()RasterAbstractBase.write_cats_rules()
- pygrass.raster.buffer module
- pygrass.raster.category module
- pygrass.raster.history module
- pygrass.raster.raster_type module
- pygrass.raster.rowio module
- pygrass.raster.segment module
- Module contents
- pygrass.rpc package
- pygrass.shell package
- pygrass.tests package
- Submodules
- pygrass.tests.benchmark module
OptionParserOptionWithDefaultget_testdict()get_testlist()get_txt()main()mytimer()print_test()run_benchmark()test__RasterRowIO_row_access__add()test__RasterRowIO_row_access__if()test__RasterRow_row_access__add()test__RasterRow_row_access__if()test__RasterRow_value_access__add()test__RasterRow_value_access__if()test__RasterSegment_row_access__add()test__RasterSegment_row_access__if()test__RasterSegment_value_access__add()test__RasterSegment_value_access__if()test__mapcalc__add()test__mapcalc__if()
- pygrass.tests.set_mapset module
- Module contents
- pygrass.vector package
- Submodules
- pygrass.vector.abstract module
InfoInfo.build()Info.close()Info.commentInfo.dateInfo.exist()Info.full_nameInfo.is_3D()Info.is_open()Info.map_dateInfo.mapsetInfo.maptypeInfo.modeInfo.nameInfo.open()Info.organizationInfo.personInfo.projInfo.proj_nameInfo.remove()Info.rename()Info.scaleInfo.threshInfo.titleInfo.write_header()Info.zone
is_open()
- pygrass.vector.basic module
- pygrass.vector.find module
- pygrass.vector.geometry module
AreaAttrsBoundaryCentroidGeoIsleIslesLineLine.alive()Line.append()Line.bbox()Line.buffer()Line.delete()Line.distance()Line.extend()Line.first_cat()Line.from_wkt()Line.gtypeLine.insert()Line.length()Line.length_geodesic()Line.nodes()Line.point_on_line()Line.pop()Line.prune()Line.prune_thresh()Line.remove()Line.reset()Line.reverse()Line.segment()Line.to_array()Line.to_list()Line.to_wkt_p()
LineDistNodePointc_read_line()c_read_next_line()get_xyz()intersects()read_WKB()read_WKT()read_line()read_next_line()
- pygrass.vector.sql module
- pygrass.vector.table module
- pygrass.vector.vector_type module
- Module contents
VectorVectorTopoVectorTopo.areas_to_wkb_list()VectorTopo.bbox()VectorTopo.cat()VectorTopo.close()VectorTopo.delete()VectorTopo.features_to_wkb_list()VectorTopo.is_empty()VectorTopo.num_primitive_of()VectorTopo.num_primitives()VectorTopo.number_of()VectorTopo.read()VectorTopo.restore()VectorTopo.rewind()VectorTopo.rewrite()VectorTopo.table_to_dict()VectorTopo.viter()
Submodules¶
pygrass.errors module¶
pygrass.utils module¶
- pygrass.utils.coor2pixel(coord, region)[source]¶
Convert coordinates into a pixel row and col
>>> from grass.pygrass.gis.region import Region >>> reg = Region() >>> coor2pixel((reg.west, reg.north), reg) (0.0, 0.0) >>> coor2pixel((reg.east, reg.south), reg) == (reg.rows, reg.cols) True
- pygrass.utils.copy(existingmap, newmap, maptype, **kwargs)[source]¶
Copy a map
>>> copy(test_vector_name, "mycensus", "vector") >>> rename("mycensus", "mynewcensus", "vector") >>> remove("mynewcensus", "vector")
- pygrass.utils.create_test_stream_network_map(map_name='streams')[source]¶
Create test data
This functions creates a vector map layer with lines that represent a stream network with two different graphs. The first graph contains a loop, the second can be used as directed graph.
This should be used in doc and unit tests to create location/mapset independent vector map layer.
param map_name: The vector map name that should be used
- 1(0,2) 3(2,2)
/
- 1 / 2
- /
2(1,1)
- 6(0,1) || 5(2,1)
- 5 || / 4
- ||/
4(1,0) | | 6 |7(1,-1)
- 7(0,-1) 8(2,-1)
/
- 8 / 9
- /
9(1, -2) | | 10 |
10(1,-3)
- pygrass.utils.create_test_vector_map(map_name='test_vector')[source]¶
This functions creates a vector map layer with points, lines, boundaries, centroids, areas, isles and attributes for testing purposes
This should be used in doc and unit tests to create location/mapset independent vector map layer. This map includes 3 points, 3 lines, 11 boundaries and 4 centroids. The attribute table contains cat, name and value columns.
- pygrass.utils.decode(obj, encoding=None)[source]¶
Decode string coming from c functions, can be ctypes class String, bytes, or None
- pygrass.utils.findmaps(type, pattern=None, mapset='', location='', gisdbase='')[source]¶
Return a list of tuple contining the names of the:
map
mapset,
location,
gisdbase
- pygrass.utils.get_lib_path(modname, libname=None)[source]¶
Return the path of the libname contained in the module.
Deprecated since version 7.1: Use
grass.script.utils.get_lib_path()instead.
- pygrass.utils.get_mapset_raster(mapname, mapset='')[source]¶
Return the mapset of the raster map
>>> get_mapset_raster(test_raster_name) == getenv("MAPSET") True
- pygrass.utils.get_mapset_vector(mapname, mapset='')[source]¶
Return the mapset of the vector map
>>> get_mapset_vector(test_vector_name) == getenv("MAPSET") True
- pygrass.utils.get_raster_for_points(poi_vector, raster, column=None, region=None)[source]¶
Query a raster map for each point feature of a vector
Example
>>> from grass.pygrass.raster import RasterRow >>> from grass.pygrass.gis.region import Region >>> from grass.pygrass.vector import VectorTopo >>> from grass.pygrass.vector.geometry import Point
Create a vector map
>>> cols = [("cat", "INTEGER PRIMARY KEY"), ("value", "double precision")] >>> vect = VectorTopo("test_vect_2") >>> vect.open("w", tab_name="test_vect_2", tab_cols=cols) >>> vect.write( ... Point(10, 6), ... cat=1, ... attrs=[ ... 10, ... ], ... ) >>> vect.write( ... Point(12, 6), ... cat=2, ... attrs=[ ... 12, ... ], ... ) >>> vect.write( ... Point(14, 6), ... cat=3, ... attrs=[ ... 14, ... ], ... ) >>> vect.table.conn.commit() >>> vect.close()
Setup the raster sampling
>>> region = Region() >>> region.from_rast(test_raster_name) >>> region.set_raster_region() >>> ele = RasterRow(test_raster_name)
Sample the raster layer at the given points, return a list of values
>>> l = get_raster_for_points(vect, ele, region=region) >>> l[0] (1, 10.0, 6.0, 1) >>> l[1] (2, 12.0, 6.0, 1)
Add a new column and sample again
>>> vect.open("r") >>> vect.table.columns.add(test_raster_name, "double precision") >>> vect.table.conn.commit() >>> test_raster_name in vect.table.columns True >>> get_raster_for_points(vect, ele, column=test_raster_name, region=region) True >>> vect.table.filters.select("value", test_raster_name) Filters('SELECT value, Utils_test_raster FROM test_vect_2;') >>> cur = vect.table.execute() >>> r = cur.fetchall() >>> r[0] (10.0, 1.0) >>> r[1] (12.0, 1.0) >>> remove("test_vect_2", "vect")
- Parameters:
poi_vector – A VectorTopo object that contains points
raster – raster object
column (str) – column name to update in the attrinute table, if set to None a list of sampled values will be returned
region – The region to work with, if not set the current computational region will be used
- Returns:
True in case of success and a specified column for update, if column name for update was not set a list of (id, x, y, value) is returned
- pygrass.utils.getenv(env)[source]¶
Return the current grass environment variables
>>> from grass.script.core import gisenv >>> getenv("MAPSET") == gisenv()["MAPSET"] True
- pygrass.utils.is_clean_name(name)[source]¶
Return if the name is valid
>>> is_clean_name("census") True >>> is_clean_name("0census") True >>> is_clean_name("census?") True >>> is_clean_name("cénsus") False
- pygrass.utils.looking(obj, filter_string)[source]¶
>>> 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']
- pygrass.utils.pixel2coor(pixel, region)[source]¶
Convert row and col of a pixel into a coordinates
>>> from grass.pygrass.gis.region import Region >>> reg = Region() >>> pixel2coor((0, 0), reg) == (reg.north, reg.west) True >>> pixel2coor((reg.cols, reg.rows), reg) == (reg.south, reg.east) True
- pygrass.utils.set_path(modulename, dirname=None, path='.')[source]¶
Set sys.path looking in the the local directory GRASS directories.
- Parameters:
modulename – string with the name of the GRASS module
dirname – string with the directory name containing the python libraries, default None
path – string with the path to reach the dirname locally.
Deprecated since version 7.1: Use
grass.script.utils.set_path()instead.
- pygrass.utils.split_in_chunk(iterable, length=10)[source]¶
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,)