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?

user1234
  • 27
  • 6
  • 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 https://i.stack.imgur.com/6bXwv.png – user1234 Oct 27 '16 at 16:24
  • Refer to this image https://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 is empty ..WARNING: Unable to copy table for layer 1... WARNING: 874 features without category skipped) – user1234 Oct 27 '16 at 16:33

3 Answers3

2

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

obrl_soil
  • 3,752
  • 15
  • 34
  • Thanks @obrl_soil .. I've tried however it's not working. – user1234 Oct 27 '16 at 02:30
  • What do you mean with "It is not working"? – Stefan B. Oct 27 '16 at 08: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 https://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 01 '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
Stefan B.
  • 286
  • 1
  • 7
  • 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 07: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) : https://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
  • OK, are you sure that "contour_f_10316_10344" contains areas? What does:

    v.info -t contour_f_10316_10344

    return?

    – Stefan B. Oct 31 '16 at 22:25
  • v.info -t contour_f_10316_10344
    nodes=2 points=0 lines=2 boundaries=0 centroids=0 areas=0 islands=0 primitives=2 map3d=0
    – user1234 Oct 31 '16 at 22:31
  • converted to line : v.info -t contour_f_10316_10344_boundary
    nodes=2 points=0 lines=0 boundaries=2 centroids=0 areas=2 islands=2 primitives=2 map3d=0 ======================================================== converted to polygon : v.info -t contour_f_10316_10344_boundary_polygon
    nodes=2 points=0 lines=0 boundaries=2 centroids=2 areas=2 islands=2 primitives=4 map3d=0
    – user1234 Oct 31 '16 at 22:41
  • v.distance -p from=DEM_exp_point from_type=point,area to=contour_f_10316_10344_boundary_polygon to_type=area upload=to_attr column=pointInArea to_column=cat ========================================== from_cat|pointInArea 1|null 2|null 3|null 4|null ......... 792|null Finding nearest features... 792 categories - no nearest feature found – user1234 Oct 31 '16 at 23:11
  • Thank you very much @dmci . It works and I need the information of those points (elevation/DEM value with the corresponding ndvi value). I'm new in GRASS .. I would like to share my working procedure with you for your valuable comments or suggestions. – user1234 Nov 01 '16 at 18:08
  • @dmci : I have two rasters (DEM and satellite image having NDVI) .. I would like to find the raster information from the corresponding DEM (contour).. steps: 1. creating contour from DEM using gdal_contour with elev attribute (contour_DEM.shp) 2. Selecting portion of DEM/contour i.e elev value less or equal 300 (contour_DEM_some) 3. Selecting small portion from contour_DEM_some that form polygon/contour (contour_DEM_some_few_Cat) 4. Apply mask on raster (DEM) and contour_DEM_some_few_Cat 5. Convert raster (DEM) to point vector (DEM_point) and add column ndvi_value..... – user1234 Nov 02 '16 at 00:26
  • Apply v.what.rast on DEM_point and ndvi (raster) 7. I can see (cat, elev, ndvi) in attribute table for all masked area.
  • Now I would like to get the similar attribute table value for each cat value (elev, ndvi value inside each cat or each polygon)

    – user1234 Nov 02 '16 at 00:26
  • r.mapcalc expression="contour_areas=round(DEM/5.0)*5" .............................................. Is this command same as gdal_contour -a elev DEM_exp.tif dem_contour_5.shp -i 5 @dmci – user1234 Nov 02 '16 at 20:37