2

I'm creating a program using the Bing Maps API where the user inputs a bounding box with lat/long, and the program extracts a number of static images at zoom level 15 to later be mosaicked together.

If each square image is about 4100 meters wide, and the first image starts with its corner at (47.602030, -122.331572), what are the coordinates of the second image 4100 m to the east?

Here is an image to illustrate what I'm doing. The user-entered bounding box is black, the 4100 m long images are blue.

enter image description here

I'm using the RgoogleMaps package in R to access the Bing Maps API, so here is the R code used to calculate the ground distance of each image.

library(geosphere)
# bounding box coordinates (lower left , upper right lat/long)
extent1 <- c(47.602030, -122.331572, 47.619620, -122.291746) 
# size of pixel in meters for zoom level 15 at given latitude
groundres <- (cos(extent1[1] * pi/180) * 2 * pi * 6378137) / (256 * 2^15) 
# image height/width in meters for zoom level 15
img.size <- 640*groundres 
# ground distance of bounding box (top corners)
extent1.m <- distRhumb(extent1[c(2,3)], extent1[c(4,3)], r=6378137)
# optimal number of images
ceiling(extent1.m/img.size)
# find lat/long of second image?

Edit: In addition to maptastik's answer, I found that package geosphere has a function destPointRhumb() and similar functions that calculate a second point given an initial point, bearing, and distance.

  • 1
    When calculating new coordinates, make sure that you want the surveyors convention of "East of North" because, that effects what you apply the [x,y] sin/cos functions to. – Jeffrey Evans Mar 2 '18 at 19:52
2

I don't really know R very well, but what you're describing reminded me of the transformTranslate function from TurfJS. Essentially you pass it coodrinates, a distance and an angular direction, and it returns the coorinates of that new location.

There is an R wrapper for Turf called lawn which appears to include the transformTranslate function from TurfJS as tranform_translate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.