Problem finding the centroid of a polygon with get.Pcent
Dear Roger, 2008/5/23 Roger Bivand <Roger.Bivand at nhh.no>:
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.
Does it mean that the coordinates of the centroid are stored within the shapefile, or are they computed by the coordinates command ?. 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.
Thanks for your answer and for clarifying my confusion about the Map
and SpatialPolygonsDataFrame class.
I have gdal 1.5.1-3 installed in my linux system, and when I tried to
load the "rgdal" library whitin R, I got the following error:
library(rgdal)
Error in fun(...) :
GDAL Error 1: libgrass_I.so: no se puede abr?r el archivo de objeto
compartido: No existe el fichero ? directorio
Error : .onLoad failed in 'loadNamespace' for 'rgdal'
Error: package/namespace load failed for 'rgdal'
I uninstalled the rgdal package, then installed again with:
install.packages("rgdal", dependencies = TRUE)
but when I tried to load it again, I got the same error:
library(rgdal)
Loading required package: sp
Error in fun(...) :
GDAL Error 1: libgrass_I.so: no se puede abr?r el archivo de objeto
compartido: No existe el fichero ? directorio
Error : .onLoad failed in 'loadNamespace' for 'rgdal'
Error: package/namespace load failed for 'rgdal'
Do you have any idea about what could be my problem ?.
Thanks in advance
Mauricio
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