EVOLUTION-MANAGER
Edit File: gridlines.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create N-S and E-W grid lines over a geographic region</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for gridlines {sp}"><tr><td>gridlines {sp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Create N-S and E-W grid lines over a geographic region </h2> <h3>Description</h3> <p> Create N-S and E-W grid lines over a geographic region; create and plot corresponding labels </p> <h3>Usage</h3> <pre> gridlines(x, easts = pretty(bbox(x)[1,]), norths = pretty(bbox(x)[2,]), ndiscr = 100) gridat(x, easts = pretty(bbox(x)[1,]), norths = pretty(bbox(x)[2,]), offset = 0.5, side = "WS") ## S3 method for class 'SpatialLines' labels(object, labelCRS, side = 1:2, ...) ## S3 method for class 'SpatialPointsDataFrame' text(x, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object deriving from class <a href="Spatial-class.html">Spatial-class</a></p> </td></tr> <tr valign="top"><td><code>easts</code></td> <td> <p>numeric; east-west values for vertical lines</p> </td></tr> <tr valign="top"><td><code>norths</code></td> <td> <p>numeric; north-south values for horizontal lines</p> </td></tr> <tr valign="top"><td><code>ndiscr</code></td> <td> <p>integer; number of points used to discretize the line, could be set to 2, unless the grid is (re)projected</p> </td></tr> <tr valign="top"><td><code>offset</code></td> <td> <p>offset value to be returned, see <a href="gridlines.html">text</a></p> </td></tr> <tr valign="top"><td><code>object</code></td> <td> <p><a href="SpatialLines-class.html">SpatialLines-class</a> object, as returned by <code>gridlines</code></p> </td></tr> <tr valign="top"><td><code>labelCRS</code></td> <td> <p>the CRS in which the grid lines were drawn and labels should be printed; if missing, the CRS from <code>object</code> is taken</p> </td></tr> <tr valign="top"><td><code>side</code></td> <td> <p>for <code>labels</code>: integer, indicating side(s) at which gridlines labels will be drawn: 1=below (S), 2=left (W), 3=above (N), and 4=right (E); for <code>gridat</code>: default “WS”, if “EN” labels placed on the top and right borders</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> for <code>labels</code>: ignored; for <code>text</code>: arguments passed on to <a href="../../graphics/html/text.html">text</a>, see below for example use of <code>adj</code></p> </td></tr> </table> <h3>Value</h3> <p><code>gridlines</code> returns an object of class <a href="SpatialLines-class.html">SpatialLines-class</a>, with lines as specified; the return object inherits the projection information of <code>x</code>; <code>gridat</code> returns a SpatialPointsDataFrame with points at the west and south ends of the grid lines created by <code>gridlines</code>, with degree labels. </p> <p>The <code>labels</code> method for <code>SpatialLines</code> objects returns a <a href="SpatialPointsDataFrame-class.html">SpatialPointsDataFrame-class</a> object with the parameters needed to print labels below and left of the gridlines. The locations for the labels are those of <code>proj4string(object)</code> the labels also unless <code>labelCRS</code> is given, in which case they are in that CRS. This object is prepared to be plotted with <code>text</code>: </p> <p>The <code>text</code> method for <code>SpatialPointsDataFrame</code> puts text labels on its coordinates, and takes care of attributes <code>pos</code>, <code>labels</code>, <code>srt</code> and <code>offset</code>; see <a href="../../graphics/html/text.html">text</a>. </p> <h3>Author(s)</h3> <p>Edzer Pebesma, <a href="mailto:edzer.pebesma@uni-muenster.de">edzer.pebesma@uni-muenster.de</a>, using example code of Roger Bivand. </p> <h3>See Also</h3> <p><a href="../../rgdal/html/spTransform.html">spTransform</a>; llgridlines in <code>rgdal</code> (recent versions) for plotting long-lat grid over projected data </p> <h3>Examples</h3> <pre> data(meuse) coordinates(meuse) = ~x+y plot(meuse) plot(gridlines(meuse), add = TRUE) text(labels(gridlines(meuse))) title("default gridlines within Meuse bounding box") proj4string(meuse) <- CRS("+init=epsg:28992") crs.longlat <- CRS("+init=epsg:4326") meuse_ll <- spTransform(meuse, crs.longlat) grd <- gridlines(meuse_ll) grd_x <- spTransform(grd, CRS("+init=epsg:28992")) # labels South and West: plot(meuse) plot(grd_x, add=TRUE, lty=2) grdat_ll <- gridat(meuse_ll) grdat_x <- spTransform(grdat_ll, CRS("+init=epsg:28992")) text(grdat_x) # labels North and East: plot(meuse) plot(grd_x, add=TRUE, lty=2) grdat_ll <- gridat(meuse_ll, side="EN") grdat_x <- spTransform(grdat_ll, CRS("+init=epsg:28992")) text(grdat_x) # now using labels: plot(meuse) plot(grd_x, add=TRUE, lty=2) text(labels(grd_x, crs.longlat)) # demonstrate axis labels with angle, both sides: sp = SpatialPoints(rbind(c(-101,9), c(-101,55), c(-19,9), c(-19,55)), crs.longlat) laea = CRS("+proj=laea +lat_0=30 +lon_0=-40") sp.l = spTransform(sp, laea) plot(sp.l, expandBB = c(0, 0.05, 0, .05)) gl = spTransform(gridlines(sp), laea) plot(gl, add = TRUE) text(labels(gl, crs.longlat)) text(labels(gl, crs.longlat, side = 3:4), col = 'red') title("curved text label demo") # polar: pts=SpatialPoints(rbind(c(-180,-70),c(0,-70),c(180,-89),c(180,-70)), crs.longlat) polar = CRS("+init=epsg:3031") gl = spTransform(gridlines(pts, easts = seq(-180,180,20), ndiscr = 100), polar) plot(spTransform(pts, polar), expandBB = c(.05,0,.05,0)) lines(gl) l = labels(gl, crs.longlat, side = 3) l$pos = NULL # pos is too simple, use adj: text(l, adj = c(0.5, -0.5)) l = labels(gl, crs.longlat, side = 4) l$srt = 0 # otherwise they end up upside-down text(l) title("grid line labels on polar projection, epsg 3031") ## Not run: if (require(maps)) demo(polar) # adds the map of the antarctic ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>sp</em> version 1.4-2 <a href="00Index.html">Index</a>]</div> </body></html>