How extract the names of ID in SpatialPolygons object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How extract the names of ID in SpatialPolygons object

fernando espindola
Hi dear user,

Anybody can tell me how extract the names of ID in  SpatialPolygons  
object,  I am try to link a data frame attributes with spatial polygons,
but the row names of data frame is not the same that ID poligons.

Thank for all

Fernando

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How extract the names of ID in SpatialPolygons object

Roger Bivand
On Fri, 30 Dec 2005, fernando espindola wrote:

> Hi dear user,
>
> Anybody can tell me how extract the names of ID in  SpatialPolygons  
> object,  I am try to link a data frame attributes with spatial polygons,
> but the row names of data frame is not the same that ID poligons.

The most generic way is to extract the "polygons" slot from your object
and then the "ID" from each member "Polygons" in turn - using sapply
because you want a character vector returned, one ID for each list member:

sapply(slot(mySpatialPolygons, "polygons"), function(x) slot(x, "ID"))

but there is an access function too:

getSpPPolygonsIDSlots()

which is just the above with a name.

Roger


>
> Thank for all
>
> Fernando
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
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: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway