<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello All,<br>
    <br>
    I've been working to be able to make elevation profiles from a DEM
    along a swath, rather than just a line (thanks to Forrest Stevens
    for the help so far).  To that end, I've made a function,
    create_perp_buffers, that creates polygons perpendicular to, and
    along, a transect (see graphic below).<br>
    <br>
    Now, I would like to be able to intersect each polygon with the
    SpatialGridDataFrame DEM, and get an average elevation for each
    polygon.  I've tried using over(), but it just hangs forever (my
    actual DEM is quite large, a mosaic from SRTM).  Can anyone suggest
    a good way to do this?<br>
    <br>
    Thanks,<br>
    Allie<br>
    <br>
    <br>
    <img src="cid:part1.05030407.04080905@ufl.edu" alt=""><br>
    <br>
    <tt><br>
    </tt><tt><br>
    </tt><tt>create_perp_buffers <- function(x1, y1, x2, y2,
      grid_dist, slice_width, proj4string = "+init=epsg:28992
      +towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812")
      {</tt><tt><br>
    </tt><tt>    xdiff <- x2 - x1</tt><tt><br>
    </tt><tt>    ydiff <- y2 - y1</tt><tt><br>
    </tt><tt>    lineangle <- atan(ydiff/xdiff)</tt><tt><br>
    </tt><tt>    dx = cos(lineangle)</tt><tt><br>
    </tt><tt>    dy = sin(lineangle)</tt><tt><br>
    </tt><tt>    left_angle = lineangle - 90</tt><tt><br>
    </tt><tt>    right_angle = lineangle + 90</tt><tt><br>
    </tt><tt>    midpoints = data.frame(x = seq(from = x1, to = x2, by =
      dx*grid_dist), y = seq(from = y1, to = y2, by = dy*grid_dist))</tt><tt><br>
    </tt><tt>    begin.coord = data.frame("x" =
      cos(left_angle)*slice_width + midpoints$x, "y" =
      sin(left_angle)*slice_width + midpoints$y)</tt><tt><br>
    </tt><tt>    end.coord = data.frame("x" =
      cos(right_angle)*slice_width + midpoints$x, "y" =
      sin(right_angle)*slice_width + midpoints$y)</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    l <- vector("list", nrow(begin.coord))</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    for (i in seq_along(l)) {</tt><tt><br>
    </tt><tt>        l[[i]] <- Lines(list(Line(rbind(begin.coord[i,],
      end.coord[i,]))), as.character(i))</tt><tt><br>
    </tt><tt>    }</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    sl <- SpatialLines(l)</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    names(begin.coord) <- c("begin_x", "begin_y")</tt><tt><br>
    </tt><tt>    names(end.coord) <- c("end_x", "end_y")</tt><tt><br>
    </tt><tt>    sldf <- SpatialLinesDataFrame(sl,
      data.frame("lineID"=1:nrow(begin.coord), begin.coord, end.coord))</tt><tt><br>
    </tt><tt>    proj4string(sldf) = proj4string</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    blpi <- gBuffer(sldf, byid=TRUE, id=sldf$lineID,
      width = grid_dist/2)</tt><tt><br>
    </tt><tt>    </tt><tt><br>
    </tt><tt>    return(blpi)</tt><tt><br>
    </tt><tt>}</tt><tt><br>
    </tt><tt><br>
    </tt><tt>my_blpi <- create_perp_buffers(180000, 331500, 181000,
      332500, 100, 100)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>data(meuse.grid)</tt><tt><br>
    </tt><tt>coordinates(meuse.grid) <- ~x+y</tt><tt><br>
    </tt><tt>gridded(meuse.grid) <- TRUE</tt><tt><br>
    </tt><tt>proj4string(meuse.grid) <-
CRS(paste("+init=epsg:28992","+towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812"))</tt><tt><br>
    </tt><tt>plot(meuse.grid, axes = T)</tt><tt><br>
    </tt><tt>plot(my_blpi, col="red", add=T)</tt><tt><br>
    </tt><br>
  </body>
</html>