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.

About these ads

Published by


I am a tropical forest ecologist with a focus on spatial and temporal patterns and processes at population and ecosystem level. I am furthermore very interested in issues related to conservation and sustainable use of biodiversity and natural resources under current and future climates. I have worked in the Middle East (Syria and Lebanon) and South America (Brazil) and in Eastern Africa (Kenya).

One thought on “Add geometry values to vector layer in GRASS GIS”

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