Wednesday, August 6, 2014

Filter SpatialPolygonsDataFrame

  • by id
> subset(sp.data.frame, id %in% myIDs)
  • by coordinates
> range <- cbind(c(long1,long2), c(lat1,lat2))
> centroids <- coordinates(sp.data.frame)
> spdf.subset <- sp.data.frame[centroids[,1] > range[1,1] &
                    centroids[,1] < range[2,1] &
                    centroids[,2] > range[1,2] &
                    centroids[,2] < range[2,2],]

No comments :

Post a Comment