Add geometry values to vector layer in GRASS GIS

In my previous post I explained how to add geometry values to the attribute table of a vector map in QGIS. You can do the same in GRASS GIS. It is slightly more complicated (don’t worry, it is still easy enough), but also more powerful. Below I will briefly explain how to use this tool using the GUI or command line.

You’ll need the function. You can type this in the console or through the menu (menu | vector | update attribute), which both will give you the following screen:

Figure 1

As you can see, you are presented with quite a few option. But before we go into these options, it is important to realize that can write values to existing columns only. It means you first need to create a column in the attribute table which will hold your geometry value. Type v.db.addcolumn on the command line or use the menu Database | vector database connection | add column.

Figure 2

Give the name of the vector layer and the name of the new column and data type. For example, create a column ‘Area’ to hold the surface area of the polygons. The data type should be double precision. Or, type on the command line

v.db.addcolumn map=yourmap@VECEA layer=1 columns='Area DOUBLE PRECISION'

Having done that we can go back to In the first tab on the screen (Figure 1), fill in the vector layer and the value to be uploaded. There are various values that can be uploaded. Check the manual to see what these different values are. You normally should not be concerned with the ‘Layer numbers’ and ‘Query layer number’ options, but check the manual if you want to know more about these option.

You can skip the ‘Query’ tab, that is if you want to update the values of a column based on other columns in the attribute table. The ‘Print’ tab is there is you want to print the results to the console instead of uploading the values to the attribute table.

In the ‘Optional’ tab (Figure 3), you can mark for which feature types you want to calculate the values. Furthermore you can indicate in which units you want these values (e.g., surface areas can be in acres, hectares or square meters, kilometers, feet, or miles). The last thing to fill in is the name of the attribute column(s).

Figure 3

Of course, you can use the command line, which is only two lines if you include the command to create the column:

v.db.addcolumn map=yourmap@VECEA layer=1 columns='Area DOUBLE PRECISION' map=veg_vecea_pnv@VECEA layer=1 qlayer=1 option=area units=hectares columns=Area

That’s all, and remember, the GRASS manual pages are generally pretty clear and often give some good examples.


6 thoughts on “Add geometry values to vector layer in GRASS GIS

  1. Pingback: Adding geometry columns to attribute table of vector map | Ecostudies

    1. I am using GRASS 7.3 (master) on Linux, and yes, I can use it. If you cannot, perhaps best to send an email to the GRASS email list. Make sure to include details about operating system, etc.

      1. Thank you for your response.

        I am using Windows 8. I followed the steps to use the GRASS 7.2 cmd as bash, which was to delete REM from env.bat. I’m going to install GRASS 7.3 and run a test.

        By the way, congratulations on the blog.

      2. Not sure GRASS 7.3 is going to be the solution, but I see you already have send an email to the email list, so hopefully it gets solved there.

    2. geosabio

      This loop worked well in Grass7.2 for adding 74 columns named “img1, img2…img74”. Where “plots” is the name of the vector point map.

      for i in {1..74};do v.db.addcolumn plots columns=”img$i double precision”;done


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s