projectPoints: Project lat-lon points

Description Usage Arguments Value Author(s) See Also Examples

View source: R/projectPoints.R

Description

Project long lat points to e.g. UTM projection. Basics copied from OpenStreetMap::projectMercator

Usage

1
2
projectPoints(lat, long, data, from = pll(), to = putm(long = long),
  spout = FALSE, dfout = TRUE, drop = FALSE, quiet = FALSE)

Arguments

lat, long

Latitude (North/South) and longitude (East/West) coordinates in decimal degrees

data

Optional: data.frame with the columns lat and long

from

Original Projection CRS (do not change for latlong-coordinates). DEFAULT: pll() = sp::CRS("+proj=longlat +datum=WGS84")

to

target projection CRS (Coordinate Reference System) Object. Other projections can be specified as sp::CRS("your_proj4_character_string"). DEFAULT: putm(long=long)

spout

Return the original spTransform output instead of coordinates only? DEFAULT: FALSE

dfout

Convert output to data.frame to allow easier indexing? DEFAULT: TRUE

drop

Drop to lowest dimension? DEFAULT: FALSE (unlike projectMercator)

quiet

Suppress warning about NA coordinates? DEFAULT: FALSE

Value

data.frame (or matrix, if dfout=FALSE) with points in new projection

Author(s)

Berry Boessenkool, [email protected], Jun 2016

See Also

scaleBar, OpenStreetMap::projectMercator, http://gis.stackexchange.com/a/74723, http://spatialreference.org on proj4strings

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library("OpenStreetMap")
lat <- runif(100, 6, 12)
lon <- runif(100, 48, 58)
plot(lat,lon)
plot(projectMercator(lat,lon), main="Mercator")
plot(projectPoints(lat,lon), main="UTM32")
stopifnot(all( projectPoints(lat,lon, to=posm()) == projectMercator(lat,lon) ))

projectPoints(c(52.4,NA),      c(13.6,12.9))
projectPoints(c(52.4,NA),      c(13.6,12.9), quiet=TRUE)
projectPoints(c(52.4,52.3,NA), c(13.6,12.9,13.1))
projectPoints(c(52.4,52.3,NA), c(13.6,NA  ,13.1))
projectPoints(c(52.4,52.3,NA), c(NA  ,12.9,13.1))

# Reference system ETRS89 with GRS80-Ellipsoid (common in Germany)
set.seed(42)
d <- data.frame(N=runif(50,5734000,6115000), E=runif(50, 33189000,33458000))
d$VALUES <- berryFunctions::rescale(d$N, 20,40) + rnorm(50, sd=5)
head(d)
c1 <- projectPoints(lat=d$N, long=d$E-33e6, to=pll(),
          from=sp::CRS("+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs") )
c2 <- projectPoints(y, x, data=c1, to=posm() )
head(c1)
head(c2)

## Not run:  # not checked on CRAN because of file opening
map <- pointsMap(y,x, c1, plot=FALSE)
pdf("ETRS89.pdf")
par(mar=c(0,0,0,0))
plot(map)
rect(par("usr")[1], par("usr")[3], par("usr")[2], par("usr")[4],
     col=berryFunctions::addAlpha("white", 0.7))
scaleBar(map, y=0.2, abslen=100)
points(c2)
berryFunctions::colPoints(c2$x, c2$y, d$VALUE )
dev.off()
system2("open", "ETRS89.pdf")  # on Linux, try "xdg-open"
#unlink("ETRS89.pdf")

## End(Not run)

brry/OSMscale documentation built on April 18, 2018, 8:23 p.m.