0

If I have a map image where:

  • The latitude and longitude of the upper left corner (x=0, y=0) are known
  • The width and height of the image is known
  • Zoom (z-axis) is known.

Can we compute the latitude and longitude for other coordinates in the image? For example, in the following image if I want to compute the lat/lon values for the white ploygon (where the coordinates (x,y) are known)

enter image description here

Adham Enaya
  • 780
  • 1
  • 11
  • 29
  • I'm not sure what you mean, Do you have any other data than the 0,0? Could you provide some background? For instance if you have a polygon and you find inner polygon I may suggest other approaches. –  May 16 '20 at 10:04
  • @yovelcohen I have lats and lons for the 4 corners – Adham Enaya May 16 '20 at 10:05
  • Ok, So you need either one of the points of the polygon to get to the rest or a condition that a point in the bound has to meet, Do you get what I mean by a condition? It would be easier to formulate such a condition if I knew the end goal –  May 16 '20 at 10:09
  • I would calculate a pixel size as `lat/image height` and `long\image width`, multiply by the coordinates and subtract the known point to create a reference frame. – Paddy Harrison May 16 '20 at 10:20
  • It may be easier to show if you could provide some numbers. – Paddy Harrison May 16 '20 at 10:22
  • @PaddyHarrison I have edited the question ith some info, do you think I can achive it with this given info? – Adham Enaya May 16 '20 at 12:29

1 Answers1

0

So given the information and the shape of the image, (see previous question):

import numpy as np

top_left = np.array((32.0055597, 35.9265418))
bottom_right = np.array((33.0055597, 36.9265418))

delta = bottom_right - top_left

shape = (454, 394)[::-1] # convert from ij to xy coords

pixel_sizes = delta / shape

pixel_sizes * (80, 200) + top_left
>>> array([32.20860539, 36.36707043])

Gives the (x, y) or (longtiude, latitude) of your given point.

This approach can be generalised given a set of points using numpy as:

coords * pixel_sizes + top_left # coords is (N, 2) array

If coords is a tuple of arrays it can be converted to an (N,2) array using np.column_stack.

Paddy Harrison
  • 1,808
  • 1
  • 8
  • 21