GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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'). More...
 
def vector_layer_db
 Return the database connection details for a vector map layer. More...
 
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'). More...
 
def vector_history
 Set the command history for a vector map to the command used to invoke the script (interface to `v.support'). More...
 
def vector_info_topo
 Return information about a vector map (interface to `v.info -t'). More...
 
def vector_db_select
 Get attribute data of selected vector map layer. More...
 
def vector_what
 Query vector map at given locations. More...
 

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').

1 >>> vector_columns(urbanarea, getDict = True)
2 {'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'}}
3 
4 >>> vector_columns(urbanarea, getDict = False)
5 ['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 98 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:

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

Definition at line 38 of file vector.py.

References python.core.read_command(), and 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:

1 >>> print grass.vector_db_select('lakes')['columns']
2 ['cat', 'AREA', 'PERIMETER', 'FULL_HYDRO', 'FULL_HYDR2', 'FTYPE', 'FCODE', 'NAME']
3 >>> print grass.vector_db_select('lakes')['values'][3]
4 ['3', '19512.86146', '708.44683', '4', '55652', 'LAKE/POND', '39000', '']
5 >>> print grass.vector_db_select('lakes', columns = 'FTYPE')['values'][3]
6 ['LAKE/POND']
Parameters
mapmap name
layerlayer number
kwargsv.db.select options
Returns
dictionary ('columns' and 'values')

Definition at line 173 of file vector.py.

References python.core.read_command(), 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 137 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:

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

Definition at line 149 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 80 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

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

To query one vector map with multiple layers (no additional parameters required)

1 for q in grass.vector_what(map = 'some_map', coord = (596532.357143,4920486.21429), distance = 100.0):
2  print q['Map'], q['Layer'], q['Attributes']
3 
4 new_bug_sites 1 {'str1': 'Beetle_site', 'GRASSRGB': '', 'cat': '80'}
5 new_bug_sites 2 {'cat': '80'}

To query more vector maps at one location

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

To query one vector map at more locations

1 for q in grass.vector_what(map = 'archsites', coord = [(595743, 4925281), (597950, 4918898)],
2  distance = 250):
3  print q['Map'], q['Attributes']
4 
5 archsites {'str1': 'No_Name', 'cat': '8'}
6 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 232 of file vector.py.

References python.core.read_command(), and dialogs.type.