[GRASS-user] grass vector model, cats and layers concept

Markus Metz markus.metz.giswork at gmail.com
Wed Jun 5 00:34:46 PDT 2013


On Wed, Jun 5, 2013 at 12:08 AM, Nikos Alexandris
<nik at nikosalexandris.net> wrote:
>
> [..]
>
>
> Nikos A:
>
>> > Also, there is a single reference on (how to create a new?) vector
>> > attribute table layer(s) in the "Intro: "Using v.db.connect
>> > connections between layers and attribute tables can be listed or
>> > maintained.".
>
> Markus N:
>
>> ... I don't fully understand where to add what...
>
> Maybe I was wrong -- perhaps it is better to add a clear instructive example
> in the "v.db.connect" manual itself (where, also, nothing is mentioned
> regarding new layers).
>
>> > Maybe we can add in the manual of "v.db.connect" the word "layer" as a
>> > Keyword
>
>> Yes, done so:
>> http://grass.osgeo.org/grass70/manuals/keywords.html
>
>> Layer
>>     v.category, v.db.connect
>
>> > and an example on how to create/connect to a *new* (empty) layer?

A new layer is created by adding categories in the new layer to vector
features. This has nothing to do with database connections. Therefore
you can by definition not create an empty layer.

In short,
create a new layer with v.category
connect an existing table to a vector layer with db.connect (the layer
does not need to exist, a new layer will not be created)
create a new table for an existing layer with v.db.addtable

>
>> Could you provide one for me to add it?
>
> It works (also) for example by
>
> # check existing connections first
> v.db.connect -p wrs2_tiles_of_interest_testing
>
> Vector map <wrs2_tiles_of_interest_testing> is connected by:
> layer <1/wrs2_tiles_of_interest_testing> table
> <wrs2_tiles_of_interest_testing> in database
> </geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db> through driver
> <sqlite> with key <cat>
>
> # add new layer by... !
> v.db.addtable wrs2_tiles_of_interest_testing layer=2

This does not add a new layer, it adds only a new connection. The
newly added table would be empty if there are no categories in the
given vector layer.

>
> The other way, using "v.db.connect" (in G7) gives me the WARNING(s):
>
> v.db.connect wrs2_tiles_of_interest_testing driver=sqlite
> database=/geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db
> table=wrs2_tiles_of_interest_testing_3 key=cat layer=3
> WARNING: Table <wrs2_tiles_of_interest_testing_3> does not exist in
>          database </geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db>
> The table <wrs2_tiles_of_interest_testing_3> is now part of vector map
> <wrs2_tiles_of_interest_testing> and may be deleted or overwritten by GRASS
> modules
> DBMI-SQLite driver error:
> Unable to create index:
> create unique index wrs2_tiles_of_interest_testing_3_cat on
> wrs2_tiles_of_interest_testing_3 ( cat )
> no such table: main.wrs2_tiles_of_interest_testing_3

v.db.connect connects an existing table. If the specified table does
not exist, you get this warning, nothing wrong with that.
>
> Though, it creates the layer=3:
>
> v.db.connect -p wrs2_tiles_of_interest_testing
> Vector map <wrs2_tiles_of_interest_testing> is connected by:
> layer <1/wrs2_tiles_of_interest_testing> table
> <wrs2_tiles_of_interest_testing> in database
> </geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db> through driver
> <sqlite> with key <cat>
> layer <2/wrs2_tiles_of_interest_testing_2> table
> <wrs2_tiles_of_interest_testing_2> in database
> </geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db> through driver
> <sqlite> with key <cat>
> layer <3/wrs2_tiles_of_interest_testing_3> table
> <wrs2_tiles_of_interest_testing_3> in database
> </geo/grassdb/global/mangroves/wgs84/PERMANENT/sqlite.db> through driver
> <sqlite> with key <cat>

No, v.db.connect does not create a new layer, only a new connection.
You need to check with v.category if a layer exists. You can, however,
connect a table to a nonexisting layer with v.db.connect.

This is all illustrated in the picture mentioned earlier in this thread [0].

Markus M

[0] http://grasswiki.osgeo.org/wiki/Vector_Database_Management#Grass_vector_management_model


More information about the grass-user mailing list