The quest for a tool to rotate a point grid …

While writing the Aerial Survey Manual for WCS last year, we decided to do the transect layout in ArcView since UWA was using that application – and rotating a grid of points was fairly straightforward during an edit session. Being able to use this set of points to lay out transects at any arbitrary angle is quite important for sample design; regular-point generation tools always \ use E-W or N-S grids only.

However …

For the next version of the manual (either 1.5 or 2.0 depending on how much we decide to modify it), it would be best to find an open-source toolset to do the job that is relatively accessible to everyone.

I do have a script in R for the job (below, using spatstat), but accessing R is not that straightforward – using a GUI like QGIS, with plugins and tools that are part of the default installation, would be ideal. I’ve posted questions about this on GIS.Stackexchange here and here but no-one has come forward with a solution yet.

It might be that I have to dive into Python plugin writing, at long last, but let’s see!

rotatePoints <- function(shfile, rotation){
  rotshape <- readShapePoints(shfile)
  SP <- methods/html/as.html">as(rotshape, "SpatialPoints")
  rotobj <- methods/html/as.html">as(SP, "ppp")

  xvec <- rotobj$x
  yvec <- rotobj$y
    xmin <- min(xvec)
    ymin <- min(yvec)
  xmax <- max(xvec)
  ymax <- max(yvec)
    xvec <- xvec - xmin - (ymax - ymin) / 2
    yvec <- yvec - ymin - (xmax - xmin) / 2
    rotR <- (rotation * pi) / 180
    curr.ppp <- ppp(xvec, yvec, window = owin(c(min(xvec), max(xvec)), c(min(yvec), max(yvec))))
    curr.ppp <- rotate.ppp(curr.ppp, rotR)

    return(data.frame(cbind(curr.ppp$x + xmin + (xmax - xmin)/2, curr.ppp$y + ymin + (ymax - ymin) / 2)))