3

I have a task to create a map of a specified section of the world. In particular, I need to map everything between the 120E and 100W longitudes and everything between the 60S and 30N latitudes mapped (I am making a map of the Pacific). I will be using the Mercator projection (since I do not have to map areas of extreme latitude).

Suppose that my map will be A cm wide and B cm high.

Trivially, I can calculate the longitude from the x-axis coordinates by using the following formula:

Longlitude = ((x/map_width) * 220 ) - 120

(x=0 is at the far left of the map, corresponding to the 120E longitude, which is why I take away 120 at the end)

Now, I require a similar formula for calculating latitude from the y-axis coordinates, with y=0 corresponding to the 30N latitude

So far, I have used Xarinko's answer from https://stackoverflow.com/questions/2103924/mercator-longitude-and-latitude-calculations-to-x-and-y-on-a-cropped-map-of-the to create this function in Python:

map_width = 1000 #in mm
map_height = 700 #in mm

map_long_left = -120
map_long_right = 100
map_long_delta = map_long_right - map_long_left

map_lat_bottom = -60
map_lat_bottom_rad = map_lat_bottom * math.pi / 180

map_lat_top = 30
map_lat_top_rad = map_lat_top * math.pi / 180


def xy_to_longlat(x: float, y: float) -> tuple():
    world_map_radius = (map_width / map_long_delta) * (360/(2 * math.pi))
    map_offset_y = ( world_map_radius / 2 * math.log( (1 + math.sin(map_lat_bottom_rad) ) /     
                                                    (1 - math.sin(map_lat_bottom_rad))))
    equator_y = map_height + map_offset_y
    a = (equator_y - y) / world_map_radius

    lat = 180 / math.pi * (2 * math.atan(math.exp(a)) - math.pi/2)
    long = map_long_left + (x / map_width) * map_long_delta
    return (long, lat)

This function assumes that the map is from the 60S to 60N latitudes. But I only want to map between the 60S and 30N latitudes. It also does not accurately calculate latitude. It produces a close value, but it can be significantly off in some instances.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.