0
votes

I have a spatialpolygonsdataframe of the state of Iowa called Iowa.sp, which contains 99 polygons. I'm trying to extract all of the labpt values from each polygon as these are the centroids of each county in Iowa and I need to work with those values as references.

I can get an individual value for labpt from one polygon within the data frame using this:

Iowa.sp@polygons[[1]]@labpt

But have not been able to figure out how to extract the entire list of labpt values and am struggling with how to work within the spatialpolygonsdataframe. Any help is much appreciated.

1
It's hard to say exactly without a reproducible example, but if that's the way you extract the labpt slot from one polygon, you should be able to use an apply- or map-family function to extract that slot from each polygoncamille

1 Answers

0
votes
temp<-data.frame(xcoord=NULL,ycoord=NULL)
for( i in 1: length(türkiye@polygons[[1]]@Polygons)){ temp<-rbind(temp,data.frame(
 xcoord=türkiye@polygons[[1]]@Polygons[[i]]@labpt[1],ycoord=türkiye@polygons[[1]]@Polygons[[i]]@labpt[2]))}
temp

adapt your data according to this example.may be there are easier ways. look at this question too Value of coordinates() for a SpatialPolygonsDataFrame object?