[GIS] Get lat/lon points from image pixels

geolocationimagevector

I need to build an application with the following requirement:

  1. shows a map .png picture to user.
  2. then, users select several points around the map (I can get the x/y pixels from each point)
  3. based on these points I want to convert x/y pixels to latitude/longitude values.

The question is: how can I do this? what do I need to consider?

I think that I can relate a point (x,y) with a predefined lat/lon and then calculate the other points based on the first one. But I'm not sure how can I achieve this.

This picture shows more or less what I need.

  • green point: point with predefined lat/lon
  • red points: points I need to determinate

image example from where I will take the points

Best Answer

I find the simplest way that it can be done is from a georeferenced image by origin and cell size, if you can determine the Cell (row,column) on the image:

X = origin X + (Column * Cell Width) Y = origin Y + (Row * Cell height)

Usually.. the world file for a png (pgw) will give the top left cell and cell size in a 6 parameter transformation, be aware the Y cell size (height) is usually negative so it's a plus not a minus. Check out this site for a brief explanation of the format.

Basically it's: Cell Width 0 0 Cell height (usually negative) Upper left X Upper left Y

I'm sure that there are other ways to do this and inbuilt functions but the maths on this one are so easy! If the image isn't georeferenced then try to do so, it's not hard here is a link on how to do it in QGIS.