Note: A new GRASS GIS stable version has been released: GRASS GIS 7.8. Go directly to the new manual page here
Fast and exit-safe interface to PyGRASS Raster and Vector layer using multiprocessing
(C) 2015 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: object
This is the base class for send and receive RPC server It uses a Pipe for IPC.
>>> import grass.script as gscript >>> from grass.pygrass.rpc.base import RPCServerBase >>> import time >>> provider = RPCServerBase()>>> provider.is_server_alive() True>>> provider.is_check_thread_alive() True>>> provider.stop() >>> time.sleep(1) >>> provider.is_server_alive() False>>> provider.is_check_thread_alive() False>>> provider = RPCServerBase() >>> provider.is_server_alive() True >>> provider.is_check_thread_alive() TrueKill the server process with an exception, it should restart
>>> provider.client_conn.send([1]) >>> provider.is_server_alive() True>>> provider.is_check_thread_alive() True
Receive the data and throw a FatalError exception in case the server process was killed and the pipe was closed by the checker thread
Fast and exit-safe interface to PyGRASS Raster and Vector layer using multiprocessing
(C) 2015 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: pygrass.rpc.base.RPCServerBase
Fast and exit-safe interface to PyGRASS data delivery functions
Return the attribute table of a vector map as dictionary.
See documentation of: pygrass.raster.raster2numpy_img
Usage:
>>> from grass.pygrass.rpc import DataProvider
>>> import time
>>> provider = DataProvider()
>>> ret = provider.get_raster_image_as_np(name=test_raster_name)
>>> len(ret)
64
>>> extent = {"north":30, "south":10, "east":30, "west":10,
... "rows":2, "cols":2}
>>> ret = provider.get_raster_image_as_np(name=test_raster_name,
... extent=extent)
>>> len(ret)
16
>>> extent = {"rows":3, "cols":1}
>>> ret = provider.get_raster_image_as_np(name=test_raster_name,
... extent=extent)
>>> len(ret)
12
>>> extent = {"north":100, "south":10, "east":30, "west":10,
... "rows":2, "cols":2}
>>> ret = provider.get_raster_image_as_np(name=test_raster_name,
... extent=extent)
>>> provider.stop()
>>> time.sleep(1)
>>> extent = {"rows":3, "cols":1}
>>> ret = provider.get_raster_image_as_np(name=test_raster_name,
... extent=extent)
>>> len(ret)
12
..
Return the features of a vector map as wkb list.
Parameters: |
|
---|
Usage:
>>> from grass.pygrass.rpc import DataProvider
>>> provider = DataProvider()
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=None,
... feature_type="point")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
1 1 21
2 1 21
3 1 21
>>> extent = {"north":6.6, "south":5.5, "east":14.5, "west":13.5}
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=extent,
... feature_type="point")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
3 1 21
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=None,
... feature_type="line")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
4 2 57
5 2 57
6 2 57
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=None,
... feature_type="centroid")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
19 3 21
18 3 21
20 3 21
21 3 21
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=None,
... feature_type="area")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
1 3 225
2 3 141
3 3 93
4 3 141
>>> wkb = provider.get_vector_features_as_wkb_list(name=test_vector_name,
... extent=None,
... feature_type="boundary")
>>> for entry in wkb:
... f_id, cat, string = entry
... print(f_id, cat, len(string))
10 None 41
7 None 41
8 None 41
9 None 41
11 None 89
12 None 41
14 None 41
13 None 41
17 None 41
15 None 41
16 None 41
>>> provider.stop()
..
Return the attribute table of a vector map as dictionary.
See documentation of: pygrass.vector.VectorTopo::table_to_dict
Usage:
>>> from grass.pygrass.rpc import DataProvider
>>> provider = DataProvider()
>>> ret = provider.get_vector_table_as_dict(name=test_vector_name)
>>> ret["table"]
{1: [1, u'point', 1.0], 2: [2, u'line', 2.0], 3: [3, u'centroid', 3.0]}
>>> ret["columns"]
Columns([(u'cat', u'INTEGER'), (u'name', u'varchar(50)'), (u'value', u'double precision')])
>>> ret = provider.get_vector_table_as_dict(name=test_vector_name,
... where="value > 1")
>>> ret["table"]
{2: [2, u'line', 2.0], 3: [3, u'centroid', 3.0]}
>>> ret["columns"]
Columns([(u'cat', u'INTEGER'), (u'name', u'varchar(50)'), (u'value', u'double precision')])
>>> provider.get_vector_table_as_dict(name="no_map",
... where="value > 1")
>>> provider.stop()
..
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.4.5dev Reference Manual