GE_SpatialGrid           package:maptools           R Documentation

_C_r_e_a_t_e _S_p_a_t_i_a_l_G_r_i_d _f_o_r _P_N_G _o_u_t_p_u_t _t_o _G_E

_D_e_s_c_r_i_p_t_i_o_n:

     The function sets up metadata in the form of a SpatialGrid object
     for defining the size and placing of a PNG image overlay in Google
     Earth. The internal function 'Sobj_SpatialGrid' can also be called
     to build a grid for arbitrary Spatial* objects.

_U_s_a_g_e:

     GE_SpatialGrid(obj, asp = NA, maxPixels = 600)
     Sobj_SpatialGrid(obj, asp=1, maxDim=100, n=NULL)

_A_r_g_u_m_e_n_t_s:

     obj: a Spatial* object

     asp: if NA, will be set to the latitude corrected value

maxPixels: the maximum dimension of the output PNG

  maxDim: the maximum dimension of the output grid; ignored if 'n' not
          NULL

       n: if not NULL, the minimum number of cells in the returned grid

_D_e_t_a_i_l_s:

     The function is used together with 'kmlOverlay' to wrap around the
     opening of a PNG graphics device, plotting code, and the closing
     of the device. The computed values take account of the adjustment
     of the actual data bounding box to an integer number of rows and
     columns in the image file. 

     The approach may be used as an alternative to writing PNG files
     from SpatialGrid and SpatialPixel objects in 'rgdal' using
     'writeGDAL', and to writing KML files using 'writeOGR' for vector
     data objects. The output PNG files are likely to be very much
     smaller than large vector data KML files, and hinder the retrieval
     of exact positional information.

_V_a_l_u_e:

     returns an S3 object of class '\dQuote{GE_SG}' with components: 

  height: Integer raster height for png call

   width: Integer raster width for png call

      SG: a SpatialGrid object with the grid topology of the output PNG

     asp: the aspect value used

    xlim: xlim taken from SG

    ylim: ylim taken from SG

_A_u_t_h_o_r(_s):

     Duncan Golicher, David Forrest and Roger Bivand

_S_e_e _A_l_s_o:

     'kmlOverlay'

_E_x_a_m_p_l_e_s:

     opt_exask <- options(example.ask=FALSE)
     qk <- SpatialPointsDataFrame(quakes[, c(2:1)], quakes)
     summary(Sobj_SpatialGrid(qk)$SG)
     t2 <- Sobj_SpatialGrid(qk, n=10000)$SG
     summary(t2)
     prod(slot(slot(t2, "grid"), "cells.dim"))
     proj4string(qk) <- CRS("+proj=longlat")
     tf <- tempfile()
     SGqk <- GE_SpatialGrid(qk)
     png(file=paste(tf, ".png", sep=""), width=SGqk$width, height=SGqk$height,
       bg="transparent")
     par(mar=c(0,0,0,0), xaxs="i", yaxs="i")
     plot(qk, xlim=SGqk$xlim, ylim=SGqk$ylim, setParUsrBB=TRUE)
     dev.off()
     kmlOverlay(SGqk, paste(tf, ".kml", sep=""), paste(tf, ".png", sep=""))
     ## Not run: 
     qk0 <- quakes
     qk0$long <- ifelse(qk0$long <= 180, qk0$long, qk0$long-360)
     qk0a <- SpatialPointsDataFrame(qk0[, c(2:1)], qk0)
     proj4string(qk0a) <- CRS("+proj=longlat")
     writeOGR(qk0a, paste(tf, "v.kml", sep=""), "Quakes", "KML")
     system(paste("googleearth ", tf, ".kml", sep=""))
     ## End(Not run)
     options(example.ask=opt_exask)

