|
This is very ad hoc, and untested, and won't help with the NW/NE thing: #R #R library(rgdal) ## read as shapefile d <- readOGR("ExternalNumbers.shp", "ExternalNumbers") ## use a list to append each result (we should pre-parse NumExt to find out the total number of points) res <- list(ID = integer(0), NumExt = character(0), x = numeric(0), y = numeric(0)) d$NumExt <-as.character(d$NumExt) ## loop over each line segment (assuming single branches) for (i in 1:length(d$NumExt)) { ## split the tokens blknums <- unlist(strsplit(d$NumExt[i], ",")) ## obtain the coordinates coords <- d@lines[[i]]@Lines[[1]]@coords ## generate intermediates (assuming straight line segment) ## (generate nn + 2 and remove the first and last) nn <- length(blknums) xx <- seq(min(coords[,1]), max(coords[,1]), length = nn + 2)[-c(1, nn+2)] yy <- seq(min(coords[,2]), max(coords[,2]), length = nn + 2)[-c(1, nn+2)] ## append to result res$ID <- c(res$ID, rep(d$ID2[i], nn)) res$NumExt <- c(res$NumExt, blknums) res$x <- c(res$x, xx) res$y <- c(res$y, yy) } ## turn into a SpatialPointsDataFrame and write to shapefile (attached) res <- as.data.frame(res) coordinates(res) <- ~x+y writeOGR(res, "ExternalNumbersPoints.shp", "ExternalNumbersPoints", "ESRI Shapefile")
cuda shuda wuda |