[R-sig-Geo] Calculating perimeter

Roger Bivand Roger.Bivand at nhh.no
Tue Nov 8 18:35:33 CET 2011


On Tue, 8 Nov 2011, Sam Rabin wrote:

> Hello all. I feel like this is a very easy thing that I have made difficult, but such is learning. I am trying to calculate the perimeter of every polygon in a shapefile, and I am running into all kinds of problems. I have looked into PBSmapping's calcLength, but I get the following error:
>
>> data = readShapePoly("shapefile.shp")
>> data.polydata = as.PolyData(data at data)
>> calcLength(data.polydata)
> Error in calcLength(data.polydata) : Invalid PolySet 'polys'.
> Unexpected class (PolyData).
>
> I'm running Mac OS X 10.7 and cannot seem to get rgeos or rgdal to load, 
> which is compounding the difficulty. I was wondering if somebody might 
> fix my code above, or point me towards a package that can do this 
> easily.

setRepositories(ind=1:2)
install.packages(c("rgdal", "rgeos"))

unless 10.7 raises issues. You also need to disambiguate what you mean by 
polygons in a shapefile - do you mean Polygons objects - which may contain 
multiple external and internal rings, or Polygon objects, which are single 
rings (may be external or internal)? You also need to establish whether 
your coordinates are projected (planar) or not. The easiest way may be to 
use a topological GIS, like GRASS - see ?vect2neigh() in spgrass6.

Roger

>
> Thanks very much!
>
> Sam Rabin
>     Graduate student
>         Princeton University
>         Ecology & Evolutionary Biology
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list