[R-sig-Geo] Problem finding the centroid of a polygon with get.Pcent
Roger Bivand
Roger.Bivand at nhh.no
Tue May 27 17:11:27 CEST 2008
On Tue, 27 May 2008, Mauricio Zambrano wrote:
> 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 ?.
The shapefile is a collection of files in your file-system. It is not
present in the R workspace. It is read into a Spatial*DataFrame object,
which in the case of SpatialPolygonsDataFrame objects, does return the
precomputed label point of the largest constituent polygon for each
observation when the coordinates() method is used.
>
> 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
I already replied that you have a stale GRASS OGR plugin on your system,
that GDAL can see, but where its dependency on libgrass_I.so is not
fulfilled. I'm sure that no other GDAL programmes work. Make GDAL work
first (even just gdalinfo --version) and rgdal will work. As I suggested
before, you need to tread carefully when using binary versions of
QGIS/GDAL etc.
Roger
>
> 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
>>
>>
>
--
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
More information about the R-sig-Geo
mailing list