Georeferencing/Mapping Latitude/Longitude coordinates to a scanned map-image (I DON'T know Lat/Long of Point 0,0)

Hello all you GIS experts!

This question has been asked serveral times: How can I convert Lat/Long data to X/Y or Left/Top values?

All answers (all but one) started with "first you need to find out the Lat/Long values corresponding to your 0,0 point of your image". That's my problem: I have the Lat/Long values of three points spread over the map. I DO NOT have the Lat/Long of the top/left or top/right or buttom/left or buttom/right pixel.

Then I found 2 postings of Mr. imarshad, outlining how to calculate the Lat/Long of Pixel 0,0 from 3 different points with known Lat/Long:

http://www.experts-exchange.com/Databases/GIS_GPS/Q_20955769.html (in short)
http://www.experts-exchange.com/Databases/GIS_GPS/Q_21213084.html (very detailed)

=========================================================
> Here is a brief extract of the first question (the short one):

To georeference Images(in BMP , TIFF and JPG) you need to know at least three points......

First step is to note the X,Y of the three points for which you have Lat/Long information. This can easily be done by using
any Image Package(Photoshop, Paint etc.).
Now take the point with the Least Longitude and name it as point 1 having (x1,y1) and (long1,lat1) .
Take the point having the Max. Longitude and name it point 2 (x2,y2) and (long2,lat2)
and the point having Min. Latitude as point3 (x3,y3) and (long3,lat3)
similarly Max. Latitude as (x4,y4) and (long4,Lat4)

Now your delx ( deg./Pixel in X direction) will be
   delX= (long2-long1)/(x2-x1)
similarly
   delY= (lat4-lat3)/(y3-y4)

Now the only thing left is to calculate the Lat/Long of any reference point. So we take the Top Left point as the Refernce point........
It will be calculated using

lat0= Lat4+y4 * delY
long0= Long1 -x1 * delX
=========================================================

I did the calcs 3 times now. The values I get, which are supposed to represent the Lat/Long of the 0,0 point on my map-image (lat0 and long0), look weired - or rather completely wrong.

I have a city map of a town in Germany. It is based on a Map & Guide map, so it should be pretty accurate. Its dimensions are 2544 x 4176 pixel.

Here is the geo-/pixel-info of the 3 points that I have:

P1:
x1=478
y1=329
Lat1=50.983069° (50°58'59.050'' N)
Long1=11.321775° (11°19'18.390'' E)

P2:
x2=247
y2=1522
Lat2=50.971017° (50°58'15.666'' N)
Long2=11.318177° (11°19'5.436'' E)

P3:
x3=1813
y3=1208
Lat3=50.973977° (50°58'26.316'' N)
Long3=11.342885° (11°20'34.386'' E)

This was my calc:

delX = (long2 - long1) / (x2 - x1)
delY = (lat4 - lat3) / (y3 - y4)
delX = (11.342885 - 11.318177) / (1813 - 247) = 0.024708 / 1566 = 1.577778 ( <- WRONG?)
delY = (50.983069 - 50.971017) / (1522 - 329) = 0.012052 / 1193 = 1.010226  ( <- WRONG?)

I assume my delta X/Y (delX / delY) is already incorrect.

lat0 = lat4 + y4 * delY
long0 = long1 - x1 * delX
lat0 = 50.983069 - (329 * 1.010226) = -281.381285 ( <- WRONG!)
long0 = 11.318177 - (247 * 1.577778) = -378,392989 ( <- WRONG!)

Someone please help! (imarshad, u there?) :/


Thank you all!

- Jessica
jessicasmithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Assuming an affine transform from x,y to lat,long

Lat = a*x + b*y + c
Long = d*x + e*y + f

where
a = ((y1-y2)*(Lat2-Lat3)-(y2-y3)*(Lat1-Lat2))/((x2-x3)*(y1-y2)-(x1-x2)*(y2-y3))
b = ((x1-x2)*(Lat2-Lat3)-(x2-x3)*(Lat1-Lat2))/((y2-y3)*(x1-x2)-(y1-y2)*(x2-x3))
c = Lat1 - (a*x1 + b*y1)

d = ((y1-y2)*(Long2-Long3)-(y2-y3)*(Long1-Long2))/((x2-x3)*(y1-y2)-(x1-x2)*(y2-y3))
e = ((x1-x2)*(Long2-Long3)-(x2-x3)*(Long1-Long2))/((y2-y3)*(x1-x2)-(y1-y2)*(x2-x3))
f = Long1 - (d*x1 + e*y1)

If
x1=478
y1=329
Lat1=50.983069
Long1=11.321775

x2=247
y2=1522
Lat2=50.971017
Long2=11.318177

x3=1813
y3=1208
Lat3=50.973977
Long3=11.342885

then
a = -1.4121e-07
b = -1.01317e-05
c = 50.9865

d = 1.57858e-05
e = 4.04847e-08
f = 11.3142

and
x=0,y=0 would correspond to
Lat = -1.4121e-07*0 + -1.01317e-05*0 + 50.9865
Long = 1.57858e-05*0 + 4.04847e-08*0 + 11.3142
jessicasmithAuthor Commented:
Hi OZO!

Thanks for your quick response!

So now I have Lat/Long corresponing to Point 0,0 on my map. Getting closer .. :D

After all I will get Lat/Long coordinates from a GPS receiver and have to display the location on a map. So I need to know how to convert from Lat/Long to X/Y rather than the other way around ...

Quote from imarshad's solution:
"Now (Lat/Long) of any point on the image can be mapped on the image using
X= (lat0-lat)/delX
Y= (long-long0)/delY"


Our lat0 is 50.986469 and long0 is 11.314216. (I used your equations to redo the lat0/long0 clac with more digits kept)

The deltaX and deltaY I calculated with imarshad's equations seems to be incorrect thou:

delX = (11.342885 - 11.318177) / (1813 - 247) = 0.024708 / 1566 = 1.577778 ( <- WRONG?)
delY = (50.983069 - 50.971017) / (1522 - 329) = 0.012052 / 1193 = 1.010226  ( <- WRONG?)

I need to have correct lat0/long0 values AS WELL AS correct delX/delY values in order to use imarshad's equation to convert Lat/Long to X/Y.


Keep going  - we're almost done here! ;)

-Jessica
ozoCommented:
X= (lat0-lat)/delX
Y= (long-long0)/delY"
assumes that lat is aligned with the X axis and long is aligned with the Y axis, which if the three points you've supplied are accurate, is not true in your example.
Lat = a*x + b*y + c
Long = d*x + e*y + f
is more general, working for any orientation, although it still assumes an affine transform, which could be a bad assumption over a large area or near the poles.  But you seem to be working with a small enough area sufficiently far from the poles that an affine transform is probably good enough and you won't need anyting more complicated
ozoCommented:
going from Lat,Long to x,y can be done by the same principle as going from x,y to Lat,Long

x = A*lat + B*long + C
y = D*lat + E*long + F
where
A = ((Long1-Long2)*(x2-x3)-(Long2-Long3)*(x1-x2))/((Lat2-Lat3)*(Long1-Long2)-(Lat1-Lat2)*(Long2-Long3));
B = ((Lat1-Lat2)*(x2-x3)-(Lat2-Lat3)*(x1-x2))/((Long2-Long3)*(Lat1-Lat2)-(Long1-Long2)*(Lat2-Lat3));
C = x1 - (a*Lat1 + b*Long1);

D = ((Long1-Long2)*(y2-y3)-(Long2-Long3)*(y1-y2))/((Lat2-Lat3)*(Long1-Long2)-(Lat1-Lat2)*(Long2-Long3));
E = ((Lat1-Lat2)*(y2-y3)-(Lat2-Lat3)*(y1-y2))/((Long2-Long3)*(Lat1-Lat2)-(Long1-Long2)*(Lat2-Lat3));
F = y1 - (d*Lat1 + e*Long1);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jessicasmithAuthor Commented:
Thanks very much! That's perfect!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
GIS/GPS Programming

From novice to tech pro — start learning today.