[R-sig-Geo] rgeos::gArea() to all polygons within sp polygons DF

Colin Rundel rundel at gmail.com
Mon Apr 9 17:40:10 CEST 2012


When working with polygons with holes sp objects do not necessarily contain information on which holes belong to which polygons which is something that rgeos needs to know to properly calculate properties like area.

You can use the createSPComment function to use rgeos to assign holes to polygons which will create the comment attribute mentioned in the warning.

I believe the area slot of the Polygons object also ignores any holes and so it should match the result from gArea when ignoring orphaned holes as well, but this is the area of the containing polygon not the area of the containing polygon - area of any holes.

-Colin 


On Apr 9, 2012, at 11:12 AM, Agustin Lobo wrote:

> Thanks Edzer,
> 
> b2 <- gArea(BorneoLCg, byid=T)
> 
> I get many warnings such as:
> 40: In RGEOSMiscFunc(spgeom, byid, "rgeos_area") :
>  Polygons object missing comment attribute ignoring hole(s). See
> function createSPComment.
> 
> is this normal?
> 
> The result is identical to
> b <- sapply(BorneoLCg at polygons, function(x) x at area)
> 
> while it is different than the one provided by QGIS (known to be wrong for very
> large polygons only because of a format problem) and postgis (assumed
> to be correct). Please give a look to:
> http://hub.qgis.org/issues/5332
> 
> Agus
> 
> 
> El día 8 de abril de 2012 17:26, Edzer Pebesma
> <edzer.pebesma at uni-muenster.de> escribió:
>> Agus, have you tried
>> 
>> gArea(BorneoLCg, byid = TRUE)
>> 
>> ?
>> 
>> On 04/08/2012 04:52 PM, Agustin Lobo wrote:
>>> Hi!
>>> 
>>> How do I  apply gArea()) to all polygons within an spatial pol. DF?
>>> I've tried
>>> areas <- apply(BorneoLCg,gArea)
>>> and
>>> areas <- sapply(BorneoLCg,gArea)
>>> 
>>> but this is not correct.
>>> 
>>> I want to compare to
>>> areas <- sapply(BorneoLCg at polygons, function(x) x at area)
>>> 
>>> Thanks
>>> 
>>> Agus
>>> 
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
>> --
>> Edzer Pebesma
>> Institute for Geoinformatics (ifgi), University of Münster
>> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
>> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
>> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list