0

Suppose I have a map with 10,000 polygons with categories 1 to 10,000 in layer 1. I would like to create a second layer with only the features in layer 1 with categories 1 to 5,000. From the online documentation, it seems I can do it with a combination of v.category, v.to.db and v.db.connect. But v.category does not provide a filtering mechanism when creating a new layer. It seems doable from this link, specifically:

If a vector object has zero categories in a layer, then it does not appear in that layer. In this fashion some vector objects may appear in some layers but not in others. Taking the example of the fields and paths, only some boundaries, but not all, might have a category value in layer 2.

I googled very hard but did not find a single example so far.

2
  • Do you think we have to expand this section: grasswiki.osgeo.org/wiki/… ?
    – markusN
    Commented Nov 27, 2016 at 8:18
  • @markusN: yes, please. It will be of great help to newbies like myself. Thanks!
    – Fei Meng
    Commented Nov 27, 2016 at 19:38

1 Answer 1

0

Maybe this will help:

# First get the id's of the polygon map with categories 1-5000
ids=$(v.edit polys tool=select cats=1-5000)
Selecting features...
5000 of 30091 features selected from vector map <polys@Arava>
v.edit complete.
# Now use v.category and filter by ids
v.category polys ids=$ids option=add layer=2 output=polys2
# and check:
v.category polys2 option=report
Layer/table: 1/polys2
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid    8123          1       8123
area           0          0          0
face           0          0          0
kernel         0          0          0
all         8123          1       8123
Layer: 2
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid    5000          1       5000
area           0          0          0
face           0          0          0
kernel         0          0          0
all         5000          1       5000

Note that there's no database connection for layer 2 now.

v.db.connect -p polys2
Vector map <polys2> is connected by:
layer <1/polys2> table <polys2> in database </home/micha/GIS/grass/ITM/Arava/sqlite.db> through driver <sqlite> with key <cat>
3
  • Hi Micha, it worked for me! Thanks a lot! Just a quick question: The upper limit on argument length on my system is 2091142, which can hold about 300k ids. If there are more than 300k features, and the ids are not continuous meaning that I can't use ranges, how can I make a layer like this?
    – Fei Meng
    Commented Nov 27, 2016 at 16:33
  • Please write up a note then in the GRASS GIS wiki once working, thanks
    – markusN
    Commented Nov 27, 2016 at 20:34
  • @Micha, I did some experiments and found a way to insert the features in batches. Suppose I would like to add another 1000 features whose feature ids are saved in $ids2 into layer 2, I just need to set the initial value of the "cat" parameter to N+1, where N is the max category id in the current layer, i.e. v.category polys2 ids=$ids2 option=add layer=2 cat=5001 output=polys3. polys3 will contain 6000 features after the command is done.
    – Fei Meng
    Commented Nov 28, 2016 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.