Hello list,
I have two vectors (A and B), both of which are polygons of different sizes. They overlap each other, but not fully. I wish to calculate the area of each polygon (in meters) and perform the following:
(A - B) / A
Currently I think I can do this with the following:
-
Create a difference polygon with v.overlay
.
-
Calculate the area of the difference polygon with v.to.db
.
-
Calculate the area of polygon A with v.to.db
.
-
Access attribute tables of both polygons to perform the calculation with ???
I have two questions:
-
Is there a more efficient way to do this? Is there some sort of vector algebra available in GRASS.
-
Do the area values have to be stored in an attribute table? Can they be written to a text file alongside an ID of the vector?
Any help would be much appreciated.
Thank you
James
On 17/05/17 17:32, James Duffy wrote:
Hello list,
I have two vectors (A and B), both of which are polygons of different
sizes. They overlap each other, but not fully. I wish to calculate the
area of each polygon (in meters) and perform the following:
(A - B) / A
Currently I think I can do this with the following:
1) Create a difference polygon with `v.overlay`.
2) Calculate the area of the difference polygon with `v.to.db`.
3) Calculate the area of polygon A with `v.to.db`.
4) Access attribute tables of both polygons to perform the calculation
with ???
I have two questions:
1) Is there a more efficient way to do this? Is there some sort of
vector algebra available in GRASS.
2) Do the area values have to be stored in an attribute table? Can they
be written to a text file alongside an ID of the vector?
First of all the approach depends a bit on whether one polygon in A always corresponds to one polygon in B, or whether you might have several polygons in one map corresponding to one polygon in the other.
If its one-to-one, and you know which polygon id in A corresponds to which polygon id in B, you can simply use v.to.db with '-p' to print the results to standard output which you can redirect to file, e.g.
v.to.db -p A op=area sep=comma > areaA.csv
You can also load the areas to the respective attribute tables and then use v.db.join to join the area column of one to the table of the other, if you have a common id for corresponding polygons in each map.
In that case, you could also directly interact with the database in SQL using db.select, e.g. something like this:
db.select sql="SELECT A.id, (A.area-B.area)/A.area FROM A JOIN B ON A.id=B.id"
Moritz
On Wed, May 17, 2017 at 11:32 AM, James Duffy <james.philip.duffy@gmail.com>
wrote:
Is there some sort of vector algebra available in GRASS.
Speaking just about the vector algebra, some basic experimental
functionality is available in an experimental addon module v.mapcalc.
https://grass.osgeo.org/grass72/manuals/addons/v.mapcalc.html