Roger — Setting the repositories as suggested worked well, for these and one other package I'd been having trouble with. gLength worked fine once I got them working. I was only talking about single-ring polygon objects.

Robert — The shapefiles were indeed in lat/long, so the fact that library("geosphere") converts measurements to meters is very handy. Good work!

Thanks, folks.

Sam Rabin
     Graduate student
         Princeton University
         Ecology & Evolutionary Biology



On Nov 8, 2011, at 12:35 PM, Roger Bivand wrote:

> 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@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@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@nhh.no
> 


	[[alternative HTML version deleted]]

