[GRASS-dev] grass.py: vector_db

Glynn Clements glynn at gclements.plus.com
Fri Dec 19 22:04:48 EST 2008


Martin Landa wrote:

> maybe we could change interfaces of vector_db. Now the function
> returns list of the list, e.g.
> 
> [['1', 'ar_1', 'cat', 'grass', 'pg'], ['1', 'ar_2', 'cat', 'grass', 'pg']]
> 
> I suggest to return a dictionary, e.g.
> 
> { 1 : { 'table' : 'ar_1', 'key': 'cat', 'database': 'grass', 'driver' : 'pg' },
>  2 : { 'table' : 'ar_2', 'key': 'cat', 'database': 'grass', 'driver' : 'pg' } }
> 
> If no objections I will apply this change and update all scripts in g7.

Seems reasonable, although I would suggest:

1. Remove the layer parameter from the function; you may as well use:

	fields = grass.vector_db(...)[layer]

if you want a specific layer.

Having the function return different types of data depending upon the
arguments probably wasn't a great design choice. IIRC, I assumed that
'v.connect -g ... layer=...' would work, then realised that it
doesn't, and fixed it inside the function rather than changing the
interface.

2. Keep the layer in the per-layer dictionaries, as well as using the
value as the key for the top-level dictionary, i.e.

{ 1 : { 'layer' : 1, 'table' : 'ar_1', 'key': 'cat', 'database': 'grass', 'driver' : 'pg' },
  2 : { 'layer' : 2, 'table' : 'ar_2', 'key': 'cat', 'database': 'grass', 'driver' : 'pg' } }

If nothing uses it, it's harmless, and it might make life simpler if
you need to use the dictionary outside of the loop (i.e. if you save
the dictionary for later, or pass it to a separate function, you don't
have to record the layer number separately).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list