# How to calculate position in a picture based on latitude/longitude

I have got a picture on which a user manually marks some points. Let's say for simplicity's sake these points always create a 4 point convex polygon. For each one of these points I know latitude and longitude.

Now the user enters latitude/ longitude for the 5th point and I have to show it on the same picture. What is the best way to calculate its screen position?

I have tried the following algorithm:

``````1) to calculate a geometrical center of the polygon on screen

2) to find an average longitude for the leftmost and  the rightmost
points and an average latitude for the topmost and the lowest points

3) to place a point at the same relation to the geometrical center
as its' geocoordinates are to this average point.
``````

I have a test image, where I know exact geocoordinates for each point on the 10px grid, and I can say that this algorithm doesn't work.

What would be the better way?

• Do you know the lat/lon of the camera position? Jan 22, 2014 at 20:17
• @Loxodrome No. I probably can ask for it, how can it help? Jan 22, 2014 at 20:20
• Almost exactly the same question is asked at gis.stackexchange.com/questions/53217/…. The only difference is that the other question notes the importance of having elevation data at your four points, so the answer describes how to use that additional information effectively. Incidentally, I believe you meant to write "convex" instead of "concave"--although convexity makes little difference here. Jan 22, 2014 at 21:19
• Just to clarify, your lat-long grid in your picture is a plane heading off to the horizon? In which case I think its impossible without knowing the field of view of the lens, and possibly other lens/view parameters too. Jan 22, 2014 at 23:50
• Simply impossible without also knowing altitude at each point. Nov 23, 2014 at 20:41

## 2 Answers

I don't think this will be possible in general, because of vertical displacement of the objects in the scene. Consider the rock (at number four). The highest point of the rock is at a certain latitude / longitude. The pixel just below that is probably at the same latitude / longitude, or is very close (within a few centimetres). The pixel just above the highest point of the rock (some blade of grass perhaps) will be quite different though - perhaps some metres away.

If the ground was completely flat, your algorithm should work. Otherwise, a single photograph that combined vertical extent of the objects with perspective doesn't allow you to georeference.

I finally found not perfect but good enough solution.

• Create a convex hull of the polygon
• Triangulate this convex polygon
• Find a triangle in which the point in question is located.
• Using barycentric interpolation find a value (in my case X and Y screen coordinates) for this point