[GRASS-user] get vector table with unique feature id

Moritz Lennert mlennert at club.worldonline.be
Fri Apr 3 06:11:40 PDT 2015


On 03/04/15 14:42, Paulo van Breugel wrote:
> I have a shapefile with overlapping polygons. After importing I thus
> end up with a vector layer with for each unique polygon (feature) one
> or more category values (i.e., one to many relationship).
>
> Now I want to create a second attribute table linked to layer 2 with
> a cat column with for each polygon (for each internal feature id) an
>  unique category.
>
> Next, I want to use this to count the number of categories linked to
>  each unique feature id.

If you have overlapping polygons, after running v.in.ogr your map
already has layer 2 categories which represent for each feature where
there is overlap the number of overlapping polygons in that space. IIUC,
this is what you are looking for, or ?

>
> I know this has been asked and answered before, but the solutions
> (copied below) do not work for me.
>
> This worked, I think, in GRASS 6, but it doesn't in G7 because a new
>  vector map needs to be defined
>> /v.category op=add layer=2 type=centroid/ /v.to.db type=centroid
>> option=cat/

And what is the problem with defining a new vector map. This new vector
map will contain all existing layers plus the new layer. But in this
case it should be:

v.category map op=add layer=3 type=centroid out=map2

You can then create a table for layer 3 with v.db.addtable:

v.db.addtable map2 layer=3 columns="cat2 integer"

and should be able to load the cat values of layer 2 into the table of 
layer 3 with v.to.db, but this does not seem to work at the moment:

v.to.db map22 layer=3 query_layer=2 op=cat columns=cat2

(there seems to be confusion between map layers, but I don't have time 
to check. Definitely worth a bug report.)


> The below does not create an attribute table with unique attributes
> for each unique feature. /> v.in.ogr dsn=test_polygones.shp
> out=polygons
> v.db.addtable polygons layer=2
 > v.category polygons option=add
>> layer=2 type=centroid out=polygons_tmp
> v.to.db polygons_tmp
>> type=centroid option=cat layer=2 col=cat/

For those features where there is overlap, this will not create new 
categories, but upload to the table the existing category which is the 
number of overlapping features.



Moritz


More information about the grass-user mailing list