[R-sig-Geo] Area calculation workflow

Michael Sumner mdsumner at gmail.com
Tue Jul 16 15:17:14 CEST 2013


It's probably easier to use area() on the raster in the first place,
and subset on that with your range of temperatures. You wear an
approximation with area() on longlat but probably no more than you
introduce by another route, and it's easy to test with simpler made up
objects.

(Closing polygons with lines from contours is hard)

library(raster)
## (nothing realistic about this)
r <- raster(volcano, xmn = 0, xmx = 10, ymn = 20, ymx = 40, crs =
"+proj=longlat")

## get longlat-approx cell areas, and subset on "temperatures" in the
range [110, 130]
sum(area(r)[][r[] > 110 & r[] < 130])





On Tue, Jul 16, 2013 at 10:28 PM, Mark Payne <markpayneatwork at gmail.com> wrote:
> Hi,
>
> I have a SpatialGridDataFrame with sea-surface temperatures based on
> lon/lat coordinates that I want to use to calculate the area (in
> square km) contained within an isotherm. I'm still a little unsure in
> this type of thing, so just wanted to check that the workflow is
> correct.
>
> I can get the isotherm out ok, using as.image.SpatialGridDataFrame(),
> contourLines() and then back to sp with ContourLines2SLDF. This gives
> me a set of SpatialLines in lat-lon space. But now I get a bit stuck.
>
> I guessing that are three steps
> 1. Close the lines to make polygons (but how?)
> 2. Convert to UTM e.g. using spTransform() from rgdal package
> 3. Extract the area of each individual polygon from the polygons slot
>
> Is this is the quickest and easiest approach? Or have I overlooked
> something? And how do I conver the lines to polygons?
>
> Best wishes,
>
> Mark
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list