[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-geo
Subject:    Re: [R-sig-Geo] how to calculate areas of shape files using R
From:       Roman_Luštrik <roman.lustrik () gmail ! com>
Date:       2011-01-31 10:19:28
Message-ID: AANLkTi=KNfFCp_4u13BjWPkZRX+AcVVuRqY59D2bNpzm () mail ! gmail ! com
[Download RAW message or body]

Elaine, do not get frightened with the complexity of sp package and its kin.
True, everything is conceptually different for doing spatial stats (and
learning R based on spatial statistics may not be the easiest approach), but
nothing that can't be managed. I found the following references very helpful
when dealing with R and (spatial) statistics questions:

http://r-sig-geo.2731867.n2.nabble.com/ (this list but in a nice archive
form)
http://r.789695.n4.nabble.com/R-help-f789696.html (ditto, but for R help
list - huge archive!)
http://stackoverflow.com/questions/tagged/r
Applied spatial data analysis using
R<http://www.amazon.com/Applied-Spatial-Data-Analysis-Use/dp/0387781706/ref=sr_1_1?ie=UTF8&s=books&qid=1296469019&sr=8-1-spell>(authors
 of the book are readers of this list)

Cheers,
Roman




On Mon, Jan 31, 2011 at 11:10 AM, elaine kuo <elaine.kuo.tw@gmail.com>wrote:

> Dear Dr. Bivand and Roman,
> 
> Thank you for the careful instructions.
> 
> I am a beginner to use R for spatial processing,
> so I would like to learn more based on your advice.
> (I used to utilize ArcGIS for spatial processing
> but decide to learn R for the same purpose.
> It is difficult to get Roman's ideas for a person like me.)
> 
> Please kindly suggest any references or package manuals for a beginner.
> Thanks again.
> 
> Elaine
> 
> On Mon, Jan 31, 2011 at 4:59 PM, Roger Bivand <Roger.Bivand@nhh.no> wrote:
> 
> > On Mon, 31 Jan 2011, Roman Luštrik wrote:
> > 
> > When you convert your polygons to Spatial object, the area will be
> > > accessible through the slots. This can be very tedious to grasp at first
> > > (but try str()). For instance, for a SpatialPolygons of one Polygon
> > > 
> > 
> > A small caveat - if the coordinates are planar, the explanation holds, if
> > geographical (degrees), it doesn't. The naive area values have been used
> > internally to plot larger Polygon objects before smaller Polygon objects,
> to
> > avoid overplotting in earlier versions of R that did not "identify" holes
> > automatically. So first make sure that you have planar coordinates,
> > otherwise the "area" values have no metric. If need be, project with
> > spTransform() methods in rgdal. If I recall, Elaine was working with an
> area
> > covering much of the Western Pacific, hence the remark - hopefully, this
> > question is about a project with a smaller extent.
> > 
> > In addition, if the Polygons objects are simple (one Polygon object per
> > Polygons object), the "area" slot of the Polygons object is equal to that
> of
> > the member Polygon, and:
> > 
> > sapply(slot(SP, "polygons"), slot, "area")
> > 
> > will return a vector of areas. Check with:
> > 
> > sapply(slot(SP, "polygons"), function(x) length(slot(x, "Polygons")))
> > 
> > If there are non-simple Polygons objects (with more than one Polygon
> > member), we also need to check whether there are holes (or should be -
> try
> > plot() too) - see below. If there are real holes not declared as holes,
> the
> > total area will be inflated.
> > 
> > Example:
> > 
> > library(maptools)
> > fn <- system.file("shapes/sids.shp", package="maptools")[1]
> > prj <- CRS("+proj=longlat +ellps=clrk66")
> > xx <- readShapeSpatial(fn, IDvar="FIPSNO", proj4string=prj)
> library(rgdal)
> > xxx <- spTransform(xx, CRS("+init=epsg:3631"))
> > # NC State Plane latest
> > sapply(slot(xxx, "polygons"), function(x) length(slot(x, "Polygons")))
> > # some non-simple Polygons objects
> > sapply(slot(xxx, "polygons"), function(x) {
> > xi <- slot(x, "Polygons")
> > any(sapply(xi, slot, "hole"))
> > })
> > # no declared holes
> > sapply(slot(xxx, "polygons"), slot, "area")
> > # areas in square metres
> > 
> > Here the non-simple Polygons objects are counties made up of more than
> one
> > part/island, with no holes. checkPolygonsHoles() in maptools may be used
> to
> > check hole status if required.
> > 
> > Hope this helps,
> > 
> > Roger
> > 
> > 
> > 
> > > my.object
> > > > 
> > > An object of class "SpatialPolygons"
> > > Slot "polygons":
> > > [[1]]
> > > An object of class "Polygons"
> > > Slot "Polygons":
> > > [[1]]
> > > An object of class "Polygon"
> > > Slot "labpt":
> > > [1] -38.80103  29.16010
> > > 
> > > Slot "area":
> > > [1] 14371.66
> > > 
> > > Slot "hole":
> > > [1] FALSE
> > > 
> > > Slot "ringDir":
> > > [1] 1
> > > 
> > > Slot "coords":
> > > [,1]      [,2]
> > > [1,] -109.76555  61.91851
> > > [2,]   21.09385 105.52317
> > > [3,]   21.09385 -29.65128
> > > [4,] -105.85930 -25.29081
> > > [5,] -109.76555  61.91851
> > > 
> > > 
> > > 
> > > Slot "plotOrder":
> > > [1] 1
> > > 
> > > Slot "labpt":
> > > [1] -38.80103  29.16010
> > > 
> > > Slot "ID":
> > > [1] "1"
> > > 
> > > Slot "area":
> > > [1] 14371.66
> > > 
> > > 
> > > 
> > > Slot "plotOrder":
> > > [1] 1
> > > 
> > > Slot "bbox":
> > > min       max
> > > x -109.76555  21.09385
> > > y  -29.65128 105.52317
> > > 
> > > Slot "proj4string":
> > > CRS arguments: NA
> > > 
> > > And for this particular case, you can access the area slot through
> > > 
> > > 
> > > my.object@polygons[[1]]@Polygons[[1]]@area
> > > 
> > > 
> > > Cheers,
> > > Roman
> > > 
> > > 
> > > 
> > > 
> > > On Mon, Jan 31, 2011 at 12:42 AM, elaine kuo <elaine.kuo.tw@gmail.com
> > > > wrote:
> > > 
> > > Dear List,
> > > > 
> > > > I am dealing with hundreds of shape files. (generated by ArcGIS 9.3)
> > > > They are composed of multiple polygons.
> > > > The polygons are classified as 1, 2, 3, and 4 according to their
> seasonal
> > > > status.
> > > > 
> > > > I want to calculate the total areas of each shape files.
> > > > Furthermore, the areas of 1, 2, 3, and 4 are also needed to be computed
> > > > for
> > > > each shape file.
> > > > 
> > > > Please kindly advise if it is possible to use R packages and functions
> > > > are
> > > > suitable for the tasks.
> > > > (may be adehabitat)
> > > > Thank you.
> > > > 
> > > > Elaine
> > > > 
> > > > [[alternative HTML version deleted]]
> > > > 
> > > > _______________________________________________
> > > > R-sig-Geo mailing list
> > > > R-sig-Geo@r-project.org
> > > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> > > > 
> > > > 
> > > 
> > > 
> > > 
> > > 
> > --
> > Roger Bivand
> > Economic Geography Section, Department of Economics, Norwegian School of
> > Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> > Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> > e-mail: Roger.Bivand@nhh.no
> > 
> 
> [[alternative HTML version deleted]]
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 


-- 
In God we trust, all others bring data.

	[[alternative HTML version deleted]]



_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic