gridlines: Create N-S and E-W grid lines over a geographic region

Description Usage Arguments Value Author(s) See Also Examples

Description

Create N-S and E-W grid lines over a geographic region; gridat permits the construction of points and labels for non-projected grid annotation

Usage

1
2
3
4
gridlines(x, easts = pretty(bbox(x)[1,]), norths = pretty(bbox(x)[2,]),
 ndiscr = 20) 
gridat(x, easts = pretty(bbox(x)[1,]), norths = pretty(bbox(x)[2,]),
 offset=0.5, side="WS")

Arguments

x

object deriving from class Spatial-class

easts

numeric; east-west values for vertical lines

norths

numeric; north-south values for horizontal lines

ndiscr

integer; number of points used to discretize the line, could be set to 2, unless the grid is (re)projected

offset

offset value to be returned, see text

side

default “WS”, if “EN” labels placed on the top and right borders

Value

gridlines returns an object of class SpatialLines-class, with lines as specified; the return object inherits the projection information of x; gridat returns a SpatialPointsDataFrame with points at the west and south ends of the grid lines created by gridlines, with degree labels

Author(s)

Edzer Pebesma, edzer.pebesma@uni-muenster.de, using example code of Roger Bivand.

See Also

spTransform; llgridlines in rgdal (recent versions) for plotting long-lat grid over projected data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
data(meuse)
coordinates(meuse) = ~x+y
plot(meuse)
plot(gridlines(meuse), add=TRUE)
title("default gridlines within Meuse bounding box")

if (require(rgdal)) {
proj4string(meuse) <- CRS("+init=epsg:28992")
meuse_ll <- spTransform(meuse, CRS("+proj=longlat +datum=WGS84"))
grd <- gridlines(meuse_ll)
grd_x <- spTransform(grd, CRS("+init=epsg:28992"))
plot(meuse)
plot(grd_x, add=TRUE, lty=2)
grdat_ll <- gridat(meuse_ll)
grdat_x <- spTransform(grdat_ll, CRS("+init=epsg:28992"))
text(coordinates(grdat_x), labels=parse(text=grdat_x$labels),
  pos=grdat_x$pos, offset=grdat_x$offset)
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(coordinates(grdat_x), labels=parse(text=grdat_x$labels),
  pos=grdat_x$pos, offset=grdat_x$offset)
}

dis-organization/sp_dplyrexpt documentation built on May 15, 2019, 8:52 a.m.