I am new to QGIS. I am creating a shapefile that will have several polygons. I need to have a column in the attribute table that will show the acres of each polygon. I have successfully done this but when I draw new polygons they don't get their acres calculated. What is the simplest way to overcome this? I am under the impression that this could perhaps be accomplished through GRASS or Python. I don't know anything about these programs though. Ultimately, I need to have a simple system for drawing new polygons labeling them with a field ID and having the ares calculated and labeled. This needs to be simple enough that interns who have never used gis can pick it up relatively quickly.
-
What projection do you use? You have to create the column by yourself, but that is easy if you use a meter-based projection– CurlewCommented Feb 13, 2014 at 21:58
-
Regarding the automatic-update part of this question, you can use the AutoFields plugin from the QGIS plugin repository.– Germán CarrilloCommented Feb 20, 2017 at 2:44
2 Answers
Activate edit mode, and open field calculator. There, use the Geometry -> $area function on existing field, or create a new field. Note that the units are the same as your CRS, so if it's in square meters, multiply by 0.00024711
-
2Just a word about the conversion factor: I guess it refers to the international acre. Be careful if your data should be in a different definition of acre. Commented Feb 13, 2014 at 22:14
-
1@Spießbürger +1. The international acre is based on the British Imperial acre which uses a standardised conversion from feet/yards to meters. However another very common variant in the US is the 'Survey Acre' which has the same definition as the international acre but is based on 'survey feet' and 'survey yards' which are very slightly different (conversion factor: 0.0002471044 as opposed to 0.0002471054 for the international acre). I don't know if there are any other definitions of acre (anybody know any out of curiosity?) Commented Feb 14, 2014 at 8:47
-
As is typical for all non-SI units there are many historical ones. The concept/word has been around for a long time. There is even a Roman acre: en.wikipedia.org/wiki/Acre#Other_acres Commented Feb 14, 2014 at 8:54
-
You should use spatial database for this. Using database you will be able to create triggers that will automatically populate or refresh columns in your table. Here is an example of two triggers that I use for the goal that you described in one of my spatialite
databases.
Trigger for creation a new polygon:
CREATE TRIGGER calculate_area -- calculate_area is the trigger name
AFTER
INSERT ON my_table -- my_table is the table name
BEGIN
UPDATE my_table
SET AREA = Area(Geometry) -- AREA is the name of column that stores area data and Area is the name of function to calculate it
WHERE Geometry = new.Geometry; -- Geometry is the name of column where geometry is stored
END
Trigger for modification of existing polygon:
CREATE TRIGGER calculate_area_on_update
AFTER
UPDATE OF Geometry ON my_table
BEGIN
UPDATE my_table
SET AREA = Area(Geometry)
WHERE Geometry = new.Geometry;
END
You should adjust calculation of the area (Area(Geometry)
) for your needs to get acres or whatever.
-
To enter that trigger do I need to be using spatialite-gui or can I simply do it through my qgis software?– Caleb ACommented Feb 14, 2014 at 16:58
-
@CalebA, no, you may use DBmanager plugin for QGIS to execute these sql-commands. But I do prefer spatialite-gui for such management operations. Commented Feb 16, 2014 at 3:12
-
I'm struggling to us the DBmanager plugin and I cannot find a helpful online tutorial. Do you know of a good tutorial? Otherwise, once I open the DBManager, do I simply use the SQL Window button at the top of the window. Then type in these commands?– Caleb ACommented Feb 20, 2014 at 20:01
-
@CalebA, I'm unaware about DBManager tutorials. It is pretty much a tool for connecting your DB to QGIS and executing queryes using SQL Window. Commented Feb 24, 2014 at 10:47
-
Still struggling. I am trying to get this acres trigger for a shapefile. Will the code you provided work for a shapefile? It was suggested to me by another user that maybe your code was meant for a GDB.– Caleb ACommented Feb 26, 2014 at 15:53