[GRASS-user] Resetting vector cats and/or a quick exchange between numpy and vector tables

Hi list,
I have some (basic) vector related questions:

···

After cleaning a vector map, it doesnt have continuous (i.e. no gaps in numbering) categories, how do I efficiently reset these to so that they have regular increments (i.e. 1) again? r.clump does something very similar with vectors. I have tried dropping and adding a new table, deleting and adding categories with v.category. I thought v.reclass may do the trick but I’d first need a column with continuous numbers for that.

Somewhat related to this, what is the best/most efficient way of updating an entire column of a vector table from a numpy array. v.update does do it for one entry only, i.e. looping would be possible, but that takes ages. Would I have to go back to using basic sqlite3 packages for that?

Thanks,

On Fri, Feb 21, 2014 at 3:06 PM, Michel Wortmann
<wortmann@pik-potsdam.de> wrote:

Hi list,
I have some (basic) vector related questions:

After cleaning a vector map, it doesnt have continuous (i.e. no gaps in
numbering) categories, how do I efficiently reset these to so that they have
regular increments (i.e. 1) again? r.clump does something very similar with
vectors. I have tried dropping and adding a new table, deleting and adding
categories with v.category. I thought v.reclass may do the trick but I'd
first need a column with continuous numbers for that.

Hi Michel,

perhaps using v.category on layer=2 would to the trick to add new categories?

Somewhat related to this, what is the best/most efficient way of updating an
entire column of a vector table from a numpy array. v.update does do it for
one entry only, i.e. looping would be possible, but that takes ages. Would I
have to go back to using basic sqlite3 packages for that?

If you only want to work on a table, then db.execute:
http://grass.osgeo.org/grass70/manuals/db.execute.html

might be the best. To speed up, put the statements into an SQL transaction.

best,
Markus

--
http://courses.neteler.org/
http://gis.cri.fmach.it/neteler/

Thanks for your help Markus, see below.

On 02/23/2014 11:32 PM, Markus Neteler wrote:

On Fri, Feb 21, 2014 at 3:06 PM, Michel Wortmann
<wortmann@pik-potsdam.de> wrote:

Hi list,
I have some (basic) vector related questions:

After cleaning a vector map, it doesnt have continuous (i.e. no gaps in
numbering) categories, how do I efficiently reset these to so that they have
regular increments (i.e. 1) again? r.clump does something very similar with
vectors. I have tried dropping and adding a new table, deleting and adding
categories with v.category. I thought v.reclass may do the trick but I'd
first need a column with continuous numbers for that.

Hi Michel,

perhaps using v.category on layer=2 would to the trick to add new categories?

This doesnt seem to do the trick for me. I've resorted to the somewhat ungraceful quickfix of converting it to raster and back to vector again until I come across a better solution.

Somewhat related to this, what is the best/most efficient way of updating an
entire column of a vector table from a numpy array. v.update does do it for
one entry only, i.e. looping would be possible, but that takes ages. Would I
have to go back to using basic sqlite3 packages for that?

If you only want to work on a table, then db.execute:
http://grass.osgeo.org/grass70/manuals/db.execute.html

might be the best. To speed up, put the statements into an SQL transaction.

Yes this is indeed quicker, although this is probably not the most convenient method.

best,
Markus

On 24/02/14 18:58, Michel Wortmann wrote:

Thanks for your help Markus, see below.

On 02/23/2014 11:32 PM, Markus Neteler wrote:

On Fri, Feb 21, 2014 at 3:06 PM, Michel Wortmann
<wortmann@pik-potsdam.de> wrote:

Hi list,
I have some (basic) vector related questions:

After cleaning a vector map, it doesnt have continuous (i.e. no gaps in
numbering) categories, how do I efficiently reset these to so that
they have
regular increments (i.e. 1) again? r.clump does something very
similar with
vectors. I have tried dropping and adding a new table, deleting and
adding
categories with v.category. I thought v.reclass may do the trick but I'd
first need a column with continuous numbers for that.

Hi Michel,

perhaps using v.category on layer=2 would to the trick to add new
categories?

This doesnt seem to do the trick for me. I've resorted to the somewhat
ungraceful quickfix of converting it to raster and back to vector again
until I come across a better solution.

What exactly is the problem with the result of v.category ?

Note that v.category does not update the table, it just updates the category values of your vector features, with the danger of losing the connection to the attributes.

One way to go to keep the same attributes would be to add a column to your attribute table with continuous numbers and then use v.reclass to create a new vector map with these numbers as category values.

If you don't care about the attribute table, you could do this:

v.category YourMap op=del out=tempmap type=TheFeatureTypeYouWantoToUse
v.category tempmap op=add out=finalmap type=idem

Then if you want to create a new attribute table for that map:

v.db.addtable finalmap

Moritz

Moritz