I have a shapefile that contains roughly 200,000 features, each with a unique Zone Code. Within each of these features I would like to randomly place n points. A separate dataset contains a list of the unique Zone Codes and the number of random points required. The end result I am after is a list of Zone Code's with a set of unique x,y coordinates for however many points are required for each feature.
I need to do this in R and have some code that does the job. However, it is not very quick and takes almost a day to complete. I am looking for any help in speeding up the process.
Here is an example of the code I am using (with a shapefile and dataset that contains 196 features):
require("rgdal")
download.file("https://dl.dropboxusercontent.com/u/27869346/Zone_ZIP.zip", "Zone_ZIP.zip")
unzip("Zone_ZIP.zip")
Zone_Shape <- readOGR(".", "ZONE_CD")
Zone_Data <- read.csv("https://dl.dropboxusercontent.com/u/27869346/ZONE_DATA.csv",header=TRUE)
Points_All <- NULL
for(i in 1:nrow(Zone_Data)){
if(Zone_Data[i,2]>0){
Zone_Shape_Single <- Zone_Shape[Zone_Shape@data$ZONE_CD %in% Zone_Data[i,1], ]
Points <- spsample(Zone_Shape_Single, Zone_Data[i,2], type="random", iter=10)
Points_DF <- cbind(Zone_Data[i,1],as.data.frame(Points))
Points_All <- rbind(Points_All, Points_DF)
}
}