An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070326/665bd3b9/attachment.pl>
function contourLines2SLDF
5 messages · Karl.Sommer at dpi.vic.gov.au, Roger Bivand, Michael Sumner
Karl.Sommer at dpi.vic.gov.au wrote:
Hello list, I used to be able to apply the function contourLines2SLDF for the following operation on a SpatialGridDataFrame object.
CL <- contourLines2SLDF(contourLines(as.image.SpatialGridDataFrame
+ (as(ht.idw["var1.pred"],"SpatialGridDataFrame"))))
Gee I'd never noticed that function. I just checked and it's now in the
"maptools" package.
BTW, here's an example I used just the other day, in case that's helpful
to see what's going on. It depends on how your lines need to be
organized whether this will match your case.
Cheers, Mike.
"d" is a SpatialGridDataFrame
"tab" is a SpatialPolygonsDataFrame (I'm looping over each polygon using
"kk", this is one iteration)
## contour it
l <- contourLines(as.image.SpatialGridDataFrame(d), levels = seq(0,
2000, by = 10))
## create empty list to hold lines
ll <- vector("list", length(l))
## loop over list of contours to create Lines object
for (i in 1:length(l)) ll[[i]] <- Lines(list(Line(cbind(l[[i]]$x,
l[[i]]$y))), as.character(i))
## make those lines Spatial, and fill out SpatialLinesDataFrame
ll <- SpatialLines(ll, CRS(proj4string(d)))
nm <- as.character(tab[kk,][["MAP_NAME"]])
num <-as.character(tab[kk,][["MAP_NO"]])
nn <- length(l)
ll <- SpatialLinesDataFrame(ll, data.frame(level = unlist(lapply(l,
function(x) x$level)),
MAP_NAME = rep(nm, nn),
MAP_NO = rep(num, nn)))
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070326/6067bb87/attachment.pl>
On Mon, 26 Mar 2007 Karl.Sommer at dpi.vic.gov.au wrote:
Thanks for the hint Michael there must have been a change in spelling the function name. The maptool function is spelt "ContourLines2SLDF" rather than "contourLines2SLDF" as it was spelt before. Anyway I am happy it is still there and it works.
Yes, that's right. The function was in sp, and got moved to maptools in a tidying up round, because sp is supposed to contain class definitions and methods, especially subsetting and visualisation methods. The maptools package is supposed to contain (some of) the tools for getting data into and out of sp class objects, as well as stand-alone functions for reading and writing shapefiles and Arc ASCII grid files. I should have been more careful to use the Deprecated/Defunct mechanisms here, I'll try harder in future! Roger
Cheers Karl Michael Sumner <mdsumner at utas.edu.au> Sent by: r-sig-geo-bounces at stat.math.ethz.ch 26/03/2007 10:43 To Karl.Sommer at dpi.vic.gov.au, r-sig-geo at stat.math.ethz.ch cc Subject Re: [R-sig-Geo] function contourLines2SLDF Karl.Sommer at dpi.vic.gov.au wrote:
Hello list, I used to be able to apply the function contourLines2SLDF for the following operation on a SpatialGridDataFrame object.
CL <- contourLines2SLDF(contourLines(as.image.SpatialGridDataFrame
+ (as(ht.idw["var1.pred"],"SpatialGridDataFrame"))))
Gee I'd never noticed that function. I just checked and it's now in the
"maptools" package.
BTW, here's an example I used just the other day, in case that's helpful
to see what's going on. It depends on how your lines need to be
organized whether this will match your case.
Cheers, Mike.
"d" is a SpatialGridDataFrame
"tab" is a SpatialPolygonsDataFrame (I'm looping over each polygon using
"kk", this is one iteration)
## contour it
l <- contourLines(as.image.SpatialGridDataFrame(d), levels = seq(0,
2000, by = 10))
## create empty list to hold lines
ll <- vector("list", length(l))
## loop over list of contours to create Lines object
for (i in 1:length(l)) ll[[i]] <- Lines(list(Line(cbind(l[[i]]$x,
l[[i]]$y))), as.character(i))
## make those lines Spatial, and fill out SpatialLinesDataFrame
ll <- SpatialLines(ll, CRS(proj4string(d)))
nm <- as.character(tab[kk,][["MAP_NAME"]])
num <-as.character(tab[kk,][["MAP_NO"]])
nn <- length(l)
ll <- SpatialLinesDataFrame(ll, data.frame(level = unlist(lapply(l,
function(x) x$level)),
MAP_NAME = rep(nm, nn),
MAP_NO = rep(num, nn)))
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
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: Roger.Bivand at nhh.no
Hello, I have a fairly convoluted set of functions (using GridTopology, rgdal and some pretty ad-hoc conditionals . . .) that allow me to easily read Pacific-centred regions from longlat-gridded datasets that are Atlantic-centric. I basically revert to SpatialPixels and let it sort out the indexing after adding 360 to western-hemisphere coordinates. I I'd like to ask for suggestions as to the best way to approach this. I've not found neat way to do it, and it seems the most efficient would be to read the two sections as SGDF, then convert those with as.image.SpatialGridDataFrame, re-binding the western portion to the eastern and resolving the grid topology and recreating the SGDF. I've not actually tried this for multi- datasets, but it would involve a loop in the above workflow for each band. If there's nothing obvious that I'm missing I'll follow this post up with a real example and go from there. Cheers, Mike.