Skip to content

function contourLines2SLDF

5 messages · Karl.Sommer at dpi.vic.gov.au, Roger Bivand, Michael Sumner

#
Karl.Sommer at dpi.vic.gov.au wrote:
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)))
#
On Mon, 26 Mar 2007 Karl.Sommer at dpi.vic.gov.au wrote:

            
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

  
    
#
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.