GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
python.vector Namespace Reference

Functions

def vector_db
 Return the database connection details for a vector map (interface to `v.db.connect -g').
def vector_layer_db
 Return the database connection details for a vector map layer.
def vector_columns
 Return a dictionary (or a list) of the columns for the database table connected to a vector map (interface to `v.info -c').
def vector_history
 Set the command history for a vector map to the command used to invoke the script (interface to `v.support').
def vector_info_topo
 Return information about a vector map (interface to `v.info -t').
def vector_db_select
 Get attribute data of selected vector map layer.
def vector_what
 Query vector map at given locations.

Function Documentation

def python.vector.vector_columns (   map,
  layer = None,
  getDict = True,
  args 
)

Return a dictionary (or a list) of the columns for the database table connected to a vector map (interface to `v.info -c').

>>> vector_columns(urbanarea, getDict = True)
{'UA_TYPE': {'index': 4, 'type': 'CHARACTER'}, 'UA': {'index': 2, 'type': 'CHARACTER'}, 'NAME': {'index': 3, 'type': 'CHARACTER'}, 'OBJECTID': {'index': 1, 'type': 'INTEGER'}, 'cat': {'index': 0, 'type': 'INTEGER'}}
>>> vector_columns(urbanarea, getDict = False)
['cat', 'OBJECTID', 'UA', 'NAME', 'UA_TYPE']
Parameters
mapmap name
layerlayer number or name (None for all layers)
getDictTrue to return dictionary of columns otherwise list of column names is returned
args(v.info's arguments)
Returns
dictionary/list of columns

Definition at line 97 of file vector.py.

References python.core.read_command().

def python.vector.vector_db (   map,
  args 
)

Return the database connection details for a vector map (interface to `v.db.connect -g').

Example:

>>> grass.vector_db('lakes')
{1: {'layer': '1', 'name': '',
'database': '/home/martin/grassdata/nc_spm_08/PERMANENT/dbf/',
'driver': 'dbf', 'key': 'cat', 'table': 'lakes'}}
Parameters
mapvector map
args
Returns
dictionary { layer : { 'layer', 'table, 'database', 'driver', 'key' }

Definition at line 37 of file vector.py.

References python.core.read_command(), and gui_modules.utils.split().

Referenced by python.vector.vector_db_select(), and python.vector.vector_layer_db().

def python.vector.vector_db_select (   map,
  layer = 1,
  kwargs 
)

Get attribute data of selected vector map layer.

Function returns list of columns and dictionary of values ordered by key column value. Example:

>>> print grass.vector_select('lakes')['values'][3]
['3', '19512.86146', '708.44683', '4', '55652', 'LAKE/POND', '39000', '']
Parameters
mapmap name
layerlayer number
kwargsv.db.select options
Returns
dictionary ('columns' and 'values')

Definition at line 172 of file vector.py.

References python.core.read_command(), gui_modules.utils.split(), and python.vector.vector_db().

def python.vector.vector_history (   map)

Set the command history for a vector map to the command used to invoke the script (interface to `v.support').

Parameters
mapmapname
Returns
v.support output

Definition at line 136 of file vector.py.

References python.core.run_command().

def python.vector.vector_info_topo (   map)

Return information about a vector map (interface to `v.info -t').

Example:

>>> grass.vector_info_topo('lakes')
{'kernels': 0, 'lines': 0, 'centroids': 15279,
'boundaries': 27764, 'points': 0, 'faces': 0,
'primitives': 43043, 'islands': 7470, 'nodes': 35234, 'map3d': 0, 'areas': 15279}
Parameters
mapmap name
Returns
parsed output

Definition at line 148 of file vector.py.

References python.core.parse_key_val(), and python.core.read_command().

def python.vector.vector_layer_db (   map,
  layer 
)

Return the database connection details for a vector map layer.

If db connection for given layer is not defined, fatal() is called.

Parameters
mapmap name
layerlayer number
Returns
parsed output

Definition at line 79 of file vector.py.

References python.core.fatal(), and python.vector.vector_db().

def python.vector.vector_what (   map,
  coord,
  distance = 0.0 
)

Query vector map at given locations.

To query one vector map at one location

print grass.vector_what(map = 'archsites', coord = (595743, 4925281), distance = 250)
[{'Category': 8, 'Map': 'archsites', 'Layer': 1, 'Key_column': 'cat',
'Database': '/home/martin/grassdata/spearfish60/PERMANENT/dbf/',
'Mapset': 'PERMANENT', 'Driver': 'dbf',
'Attributes': {'str1': 'No_Name', 'cat': '8'},
'Table': 'archsites', 'Type': 'Point', 'Id': 8}]

To query one vector map at more locations

for q in grass.vector_what(map = ('archsites', 'roads'), coord = (595743, 4925281),
distance = 250):
print q['Map'], q['Attributes']
archsites {'str1': 'No_Name', 'cat': '8'}
roads {'label': 'interstate', 'cat': '1'}

To query more vector maps at one location

for q in grass.vector_what(map = 'archsites', coord = [(595743, 4925281), (597950, 4918898)],
distance = 250):
print q['Map'], q['Attributes']
archsites {'str1': 'No_Name', 'cat': '8'}
archsites {'str1': 'Bob_Miller', 'cat': '22'}
Parameters
mapvector map(s) to query given as string or list/tuple
coordcoordinates of query given as tuple (easting, northing) or list of tuples
distancequery threshold distance (in map units)
Returns
parsed list

Definition at line 227 of file vector.py.

References python.core.read_command(), and gui_modules.psmap_dialogs.type.