[GRASS-dev] In G7, v.category with option=transfer layer=1, 2 doesn't seem to be effective

Nikos Alexandris nik at nikosalexandris.net
Fri May 17 07:18:05 PDT 2013


Nikos wrote:

> > In G7
> > # transfer cats to new layers, as the manual describes [1]
> > v.category polygons option=transfer layer=1,2 out=polygons_tmp

Martin wrote:
 
> `v.category` just transfer categories, the module do not reconnect
> attribute tables.
> Check `v.category opt=report`.

> > # checking
> > v.db.select polygons_tmp
> > cat|id|cat_
> > 1|1|

> > v.db.select polygons_tmp layer=2
> > cat

> You need to connect attribute table using `v.db.connect` to the layer '2'.

I think I am confused so I'll take it from the beginning:

# import
v.in.ogr dsn=test_polygones.shp out=polygons

# checking connection
v.db.connect polygons -p

Vector map <polygons> is connected by:
layer <1/test_polygones> table <polygons> in database 
</geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db> 
through driver <sqlite> with key <cat>

# ...cats
v.category polygons option=report
Layer/table: 1/polygons
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid       2          1          1
area           2          1          1
face           0          0          0
kernel         0          0          0
all            2          1          1

# so far so good, now... which is the "preferred" way to add a new layer?
v.db.addtable polygons layer=2

Reading features...
 100%
Updating database...
 100%
0 categories read from vector map (layer 2)
0 records updated/inserted (layer 2)

# re-checking connections
v.db.connect polygons -p

Vector map <polygons> is connected by:
layer <1/test_polygones> table <polygons> in database 
</geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db> 
through driver <sqlite> with key <cat>
layer <2/polygons_2> table <polygons_2> in database 
</geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db> 
through driver <sqlite> with key <cat>

# and layers
v.category polygons option=report

Layer/table: 1/polygons
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid       2          1          1
area           2          1          1
face           0          0          0
kernel         0          0          0
all            2          1          1

# hm? ok... let's "transfer" the layer 1 to layer 2, 3
## ...to "polygons_tmp" -- why is this required?
v.category polygons option=transfer layer=1,2,3 out=polygons_tmp

Processing features...
Copying attribute table(s)...
Building topology for vector map <polygons_tmp at PERMANENT>...
Registering primitives...
5 primitives registered
22 vertices registered
Building areas...
 100%
3 areas built
3 isles built
Attaching islands...
 100%
Attaching centroids...
 100%
Number of nodes: 3
Number of primitives: 5
Number of points: 0
Number of lines: 0
Number of boundaries: 3
Number of centroids: 2
Number of areas: 3
Number of isles: 3
Categories copied from layer 1 to layer 1
Categories copied from layer 1 to layer 2
Categories copied from layer 1 to layer 3
v.category complete. 5 features modified.

# re-checking for connections
v.db.connect polygons_tmp -p

Vector map <polygons_tmp> is connected by:
layer <1/test_polygones> table <polygons_tmp_test_polygones> in database 
</geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db> 
through driver <sqlite> with key <cat>
layer <2/polygons_2> table <polygons_tmp_polygons_2> in database 
</geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db> 
through driver <sqlite> with key <cat>

# and cats/layers
v.category polygons_tmp option=report

Layer/table: 2/polygons_tmp_polygons_2
type       count        min        max
point          0          0          0
line           0          0          0
boundary       3 1944966201 1944966201
centroid       2          1          1
area           2          1          1
face           0          0          0
kernel         0          0          0
all            5          1 1944966201
Layer: 3
type       count        min        max
point          0          0          0
line           0          0          0
boundary       3 1944966201 1944966201
centroid       2          1          1
area           2          1          1
face           0          0          0
kernel         0          0          0
all            5          1 1944966201
Layer/table: 1/polygons_tmp_test_polygones
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid       2          1          1
area           2          1          1
face           0          0          0
kernel         0          0          0
all            2          1          1

# layer 1
v.db.select polygons_tmp
cat|id|cat_
1|1|

# layer 2
v.db.select polygons_tmp layer=2
cat

# ok... then? re-connect? what to what?
db.tables -p

polygons
polygons_2
polygons_tmp_polygons_2
polygons_tmp_test_polygones


# I still need to find the correct "v.db.connect" instruction (?)
v.db.connect polygons_tmp layer=2 driver=sqlite 
database=/geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db 
table=polygons -o

The table <polygons> is now part of vector map <polygons_tmp> and may be
deleted or overwritten by GRASS modules

# and...
v.db.select polygons_tmp layer=2
cat|id|cat_
1|1|

O-K, here it is!

Summarising:

# import
v.in.ogr dsn=test_polygones.shp out=polygons

# transfer/add layers
v.category polygons option=transfer layer=1,2,3 out=polygons_tmp

# (re-)connect -- 1st attempt fails!
v.db.connect polygons_tmp layer=2 driver=sqlite 
database=/geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db 
table=polygons -o

The table <polygons> is now part of vector map <polygons_tmp> and may be
deleted or overwritten by GRASS modules
DBMI-SQLite driver error:
Unable to create index:
create unique index polygons_cat on polygons ( cat )
index polygons_cat already exists

DBMI-SQLite driver error:
Unable to create index:
create unique index polygons_cat on polygons ( cat )
index polygons_cat already exists

WARNING: Cannot create index
Select privileges were granted on the table

# again, the same command
v.db.connect polygons_tmp layer=2 driver=sqlite 
database=/geo/grassdb/tests/vector_stats_for_multiple_cats/wgs84/PERMANENT/sqlite/sqlite.db 
table=polygons -o

The table <polygons> is now part of vector map <polygons_tmp> and may be
deleted or overwritten by GRASS modules

# checking...
v.db.select polygons_tmp layer=2

cat|id|cat_
1|1|

Thanks, N


More information about the grass-dev mailing list