I used image classification technique in GRASS GIS v7 and generated the image mask below in which white area has NULL value and red area contains 1.

enter image description here

I am going to clip those red color areas in a LiDAR file so I need to convert those to a polygon shapefile. I know that I need to use a combination of image analysis techniques to achieve this but don't know whether GRASS has similar functionality to generate polygon shapefile from a mask.


Did you check the r.to.vect module? You find the documentation here: http://grass.osgeo.org/grass70/manuals/r.to.vect.html

  • This isn't useful as I need only polygon shapes not points or lines. my sesong question is: let's say I have an ASCII file including rows of X Y Z coordinates. Is there any command in GRASS that I could use to add another column attribute to the ASCII file (let's call it "H") and get its values from the mask (as shown above in raster format). Thanks – user2148425 Jun 4 '14 at 5:52
  • Ok, I see. What about a GDAL alternative? gdal.org/gdal_polygonize.html – webrian Jun 4 '14 at 6:37
  • Werbrian,I used that command and that worked. However, I ended up with large number of polygons so I decided to solve the problem in another way, which is what I posted yesterday. – user2148425 Jun 7 '14 at 0:43

Regarding webrian's answer, the "feat=area" option to r.to.vect will create only polygons.

As for adding a column to your ASCII file, you'll need to import it into grass as a vector, then using v.what.rast you will upload raster values to each point. Something like:

v.db.addcolumn <your_vector_layer> column="h double precision"
v.what.rast <your_vector_points> raster=<your_raster_layer> column="h"

Now, if you need the data as an ASCII file, export back out. (v.out.ascii)

  • Is the "feat=area" option the same as the "type=area"? I'm just asking since I can't find the "feat" option in the documentation. – webrian Jun 4 '14 at 7:31
  • Yes, in v7.0 the syntax is now "type=area". (In the previous v6.4 it was "feature=area") – Micha Jun 4 '14 at 7:40
  • Hi Micha,I tried to run v.db.addcolumn but I got the message "ERROR: There is no table connected to this map. Run v.db.connect or v.db.addtable first." I thought when I import an ASCII with X Y Z structure, GRASS generates a table and attached it to the resulting vector map. Then in the v.db.addtable, I have to define "columns". My question is after defining columns (let's say X Y Z) in v.db.addtable, how do I assign the actual x, y and z values to the table? – user2148425 Jun 6 '14 at 6:40
  • The v.in.ascii import creates a table only when it is "necessary", that is, only when there are additional data columns, other than x-y. If you have defined the x-y-z columns then do v.to.db with the parameters: option=coor columns="x,y,z". – Micha Jun 6 '14 at 10:01
  • Hi, I am confused. As I said in my previous posts, I want to import a text file, add another column (to get the structure of x y z status) and populate the “status” attribute from a raster map. The data type of “status” will be int. I followed the following steps. First I ran: v.in.ascii -n input= pts.txt output=pts_vecorMap separator=’space’. File is read Ok. Then I run the following command: v.to.db map=pts_vecorMap@PERMANENT type=point option=coor columns='x,y,z' but I got ERROR: Unable to open database <D:\Astron\Grass\TextFileTest\PERMANENT\sqlite\sqlite.db> by driver <dbf> – user2148425 Jun 6 '14 at 14:45

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.