0

I have a point vector with attributes (cat, dem_value, ndvi_value).

I have a another vector/polygon (converted from contour) with attributes (cat, ID, dem_value). I need to extract points (points with corresponding ndvi_value and dem_value) that are inside the polygon. I've tried using v.extract, v.select and v.vect.stats. However, I could not get the results.

I used following command in GRASS (wanted to delete the all attributes that are not within the polygon): v.edit -r map=DEM_exp_point tool=delete polygon=688577.298919,5087607.23962, 688576.065972,5087617.45547, 688582.406842,5087621.33044, 688551.232139,5087597.13671, 688550.880526,5087597.13671, 688562.659564,5087604.69639, 688575.493441,5087606.80606 Selecting features... 619 of 792 features selected from vector map 619 features deleted Building topology for vector map ... Registering primitives... 173 primitives registered 173 vertices registered Building areas... 0 areas built 0 isles built Attaching islands... Attaching centroids... Number of nodes: 0 Number of primitives: 173 Number of points: 173 Number of lines: 0 Number of boundaries: 0 Number of centroids: 0 Number of areas: 0 Number of isles: 0

v.edit complete.

seems it works .. I can see the points (graphical Map display) that lie inside the polygon but no change in the point vector (attribute table). How can I distinguish and extract those points from the Attribute table?

  • Based on your question, it seems that v.select should be the right tool. What command did you run, and what results did you get? What did not work? – Micha Oct 27 '16 at 13:12
  • Refer to this image i.stack.imgur.com/6bXwv.png – user1234 Oct 27 '16 at 16:24
  • Refer to this image i.stack.imgur.com/6bXwv.png Left one is the attribute table of vector(polygon) converted from contour to polygon. Right one is the attribute table of vector (point). Middle one is the graphical illustration of both point and polygon vectors. .. however it's not working and got warnings as follows (WARNING: Array of values to select from column <cat> is empty ..WARNING: Unable to copy table for layer 1... WARNING: 874 features without category skipped) – user1234 Oct 27 '16 at 16:33
2

I think you're looking for either v.vect.stats or v.what.vect for your task.

  • Thanks @obrl_soil .. I've tried however it's not working. – user1234 Oct 27 '16 at 2:30
  • What do you mean with "It is not working"? – Stefan B. Oct 27 '16 at 8:47
  • for v.vect.stats .. I've added a column to store the point count in the attribute table of point vector. however 0 records updated... for v.what.vect output like that "850 categories - no nearest feature found" .. I think problem may be both attribute tables has disjoint cat value. please have a look at the image i.stack.imgur.com/6bXwv.png – 1st one is the attribute table of vector(polygon) converted from contour to polygon. Right one is the attribute table of vector (point). Middle one is the graphical illustration of both point and polygon vectors. – user1234 Oct 27 '16 at 16:58
  • You could accept the answer of @obrl_soil as it provides the correct answer to your question. Please consider also editing your question, so it becomes more clear that you just want to count points in polygons. – Stefan B. Nov 1 '16 at 22:02
2

It is not perfectly clear what you are up to, but from what you are describing v.what.vect could be indeed an option, alternatively, I would suggest having a look at v.distance:

See: "Point-in-polygon" example in the manual...

Edit based on the comments below:

As you can see from the output of v.info your vector map "contour_f_10316_10344" does not contain any areas. Thus, v.distance does not find any.

What you could do is e.g. (assuming you want lets say 5m "contour areas" and your elevation model is named DEM):

g.region -p raster=DEM align=DEM

r.mapcalc expression="contour_areas=round(DEM/5.0)*5"

r.to.vect input=contour_areas output=contour_areas type=area

v.db.addcolumn contour_areas columns="num_points integer"

v.vect.stats points=DEM_exp_point area=contour_areas count_column=num_points
  • Thanks @Stefan B. .. Yap, v.what.vect could be an option however it's not working here .. please see my earlier comments. About the manual of v.distance you have provided seems clear to me " point-in-polygon" but it's not working as well [output: Finding nearest features... Update vector attributes... 850 categories - no nearest feature found v.distance complete. 850 records updated.] – user1234 Oct 27 '16 at 17:31
  • Could you please add the full command you are using for v.what.vect and v.distance. Otherwise it is difficult to help... – Stefan B. Oct 28 '16 at 7:49
  • [DEM_point is a point vector and contour_10316_10344 is a vector of contour contains two polygon/contour cat value 10316 and 10344 ] v.what.vect map=DEM_point column=pointInArea qmap=contour_10316_10344 qcolumn=elev [output: 792 categories - no nearest feature found] .. I've added pointInArea column in the DEM_point vector to hold the value. The problem here I'm facing qcolumn (Name of attribute column to be queried) .. I've used elev (elevation value).. in the contour .. I don't know how it will identify the points that are inside the polygon/contour. – user1234 Oct 31 '16 at 18:50
  • Attribute table of both vectors (image) : i.stack.imgur.com/AQ2xm.png – user1234 Oct 31 '16 at 19:42
  • v.distance from=DEM_exp_point from_type=point to=contour_f_10316_10344 to_type=area dmax=0 upload=to_attr column=pointInArea to_column=cat [For values describing the relation between two nearest feature:(upload,String) .. I've used/checked the last option "attribute of nearest feature given by to_column option] .... output: ERROR: No features of selected type found in <contour_f_10316_10344> – user1234 Oct 31 '16 at 20:14
0

If you have QGIS installed on your machine, then you can use Join Attribute by Locations from Vector -> Data management tools -> Join Attribute by Locations in (QGIS 2.14.7) OR from Processing Toolbox -> QGIS Algorithms -> Vector General Tools -> Join Attribute by Locations in (QGIS 2.16.3), as you can see below:

enter image description here

Following up my comments: here is an image that shows GRASS and QGIS from inside QGIS software:

enter image description here

  • Thanks @ahmadhanb .. I don't have QGIS installed .. however, I've to do it in GRASS. – user1234 Oct 27 '16 at 2:33
  • But you can use GRASS from inside QGIS as plugin and also keep working with GRASS as standalone software. You can refer to this answer on how to install QGIS with GRASS. It is free. gis.stackexchange.com/a/202073/63384 – ahmadhanb Oct 27 '16 at 2:39
  • I'm trying to find similar one like join attribute by locations in GRASS but I can't find. @ahmadhanb – user1234 Oct 27 '16 at 2:41
  • Installing QGIS will give you extra functions/Geoprocessing tools that is not available in GRASS, since both are integrated together. I have both GRASS and QGIS installed in my machine, and work with them both. – ahmadhanb Oct 27 '16 at 2:52
  • @ahmadhanb Please note that you do not get the full functionality of GRASS through QGIS. Furthermore, when using GRASS through QGIS-Processing you do not get the same performance either... – Stefan B. Nov 1 '16 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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