XY2LatLon: computes the centered coordinate transformation from lat/lon...

Description Usage Arguments Value Author(s) See Also Examples

Description

The function XY2LatLon(MyMap, X,Y,zoom) computes the coordinate transformation from map tile coordinates to lat/lon given a map object.

Usage

1
XY2LatLon(MyMap, X, Y, zoom)

Arguments

MyMap

map object

X

latitude values to transform

Y

longitude values to transform

zoom

optional zoom level. If missing, taken from MyMap

Value

properly scaled and centered (with respect to the center of MyMap ) coordinates

lon

longitude

lat

latitude

Author(s)

Markus Loecher

See Also

LatLon2XY Tile2R

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
41
42
43
44
45
46
47
48
49
#quick test:





  zoom=12;MyMap <- list(40,-120,zoom, url="google");


  LatLon <- c(lat = 40.0123, lon = -120.0123);


  Rcoords <- LatLon2XY.centered(MyMap,LatLon["lat"],LatLon["lon"])


  newLatLon <- XY2LatLon(MyMap, Rcoords$newX, Rcoords$newY)


  max(abs(newLatLon - LatLon));





#more systematic:


 for (zoom in 2:10){


   cat("zoom: ", zoom, "\n");


   MyMap <- list(40,-120,zoom, url="google");


   LatLon <- c(lat = runif(1,-80,80), lon = runif(1,-170,170));


   Rcoords <- LatLon2XY.centered(MyMap,LatLon["lat"],LatLon["lon"])


   newLatLon <- XY2LatLon(MyMap, Rcoords$newX, Rcoords$newY)


   if(max(abs(newLatLon - LatLon)) > 0.0001) print(rbind(LatLon, newLatLon));


 }

iNZightVIT/RgoogleMaps documentation built on May 17, 2019, 10:09 p.m.