4

How do I get for each v.to.points point an ID in the database (DB).

So far I splited the line (each 10m) but it returns only one DB entry for each original line.

v.db.select line
cat|Id|Name
1|1|Line 1
2|2|Line 2

# split the lines every 10m
v.to.points in=line out=line_points dmax=10

# check the result
v.db.select line_points
cat|Id|Name
1|1|Line 1
2|2|Line 2

Each point should have its own DB entry. The result should be:

v.db.select line_points
cat|Id|Name
1|1|Line 1
2|1|Line 1
3|2|Line 2
4|2|Line 2

Workaround: So far my workaround is, to export (v.out.ogr) the points as shape and import (v.in.ogr) it again. Then each point has his own ID. But there must be a smarter way to do that!

3
  • Not much of a GRASS user but what about v.category.add which is described as: "...attaches, deletes or reports vector categories to map geometry. These categories (IDs) are used to link geometry object(s) to attribute records (from attribute table linked to vector map)."
    – Joseph
    Jan 22, 2016 at 15:18
  • I tried that before in GRASS 7 the function calls v.category. What I tried is the following command v.category in=line_points option=add out=line_points2. I posted the question 'cuz I have it already for quite a while and work since ever with my workaround, but I felt alway its not the best method to do it.
    – wittich
    Jan 23, 2016 at 21:42
  • Have you looked at grass.osgeo.org/grass70/manuals/v.segment.html? It looks like it performs a similar function and might work better for creating separate segments rather than vertices.
    – TDavis
    Jan 27, 2016 at 18:37

1 Answer 1

2

v.to.points creates a vector with 2 layers. With the second layer you should have unique ID.

You should thus simply specify the second layer with v.db.select or write into a new feature with v.category.

# return unique IDs
v.db.select line_points layer=2

# change layer 2 to 1
v.category input=line_points output=line_points2 option=chlayer layer=2,1

For more details see v.to.points description:

v.to.points creates points along input lines. The output is a vector with 2 layers. Layer 1 holds the category and attributes of the input lines; all points created along the same line have the same category, equal to the category of that line. In layer 2 each point has it's unique category; other attributes stored in layer 2 are lcat - the category of the input line and along - the distance from line's start.

1
  • One more time I should have read the manual more carefully. Thx @radouxju that's where I was looking for.
    – wittich
    Jan 30, 2016 at 23:55

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.