Problem finding the centroid of a polygon with get.Pcent
On Fri, 23 May 2008, Mauricio Zambrano wrote:
Dear List, For finding the centroid of a catchment, I tried with the function: get.Pcent(gallego_catchment) but I got the following error: Error en get.Pcent(gallego_catchment) : not a Map object However, I checked the class:
class(gallego_catchment)
[1] "SpatialPolygonsDataFrame" attr(,"package") [1] "sp"
Just say coordinates(gallego_catchment) to extract the "centroid" - labelpoint - for each Polygons object - the coordinates() method retrieves the label points. Note that a "Map" object is not a "SpatialPolygonsDataFrame" object, and indeed "Map" objects are only used internally in some limited settings. You are muddling up classes. Installing rgdal properly would make sure you only saw the "SpatialPolygonsDataFrame" object, which is all you need. Roger
and I read the catchment boundary with:
p4s <- CRS("+proj=utm +zone=30 +ellps=intl +units=m +no_defs")
# reading the boundary of the gallego catchment
library(maptools)
gallego_catchment <- readShapePoly("only_gallego_catchment.shp",
proj4string=p4s)
Could somebody tell me if I'm doing something wrong?
Thanks in advance
Mauricio
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 at nhh.no