views:

283

answers:

2

I have x,y data coming in from a [coordinates1] database (GIS - but this could be any database). I have my application with it's own coordinate system, referencing THE SAME MAP.

I have established that a linear relationship exists between coordinates1(x,y) and coordinates2(x,y) as I have subtracted two different coordinates1 and coordinates2 [dividing x1 with x2 and y1 with y2] and in all cases I get them both showing 0.724 or 0.141 or 0.825 respectively i.e coordinates1 + coordinates2.

what I now need to figure out - or you help - is that if coordinates1(100000,200000) and coordinates2(0.125,0.255) how do I calculate coordinates2(x,y) from the data in coordinates1(x,y)?

+2  A: 

To do the conversion, you need to know the coordinates of one point O in your two coordinates systems .

Let's suppose O has coordinates x1O,y1O in coordinate system 1, and x2O,y2O in coordinate system 2.

Then a point with coordinates x1,y1 in system 1, and x2,y2 in system 2 will satisfy:

(x1O - x1) = Kx * (x2O - x2)
(y1O - y1) = Ky * (y2O - y2)

where Kx and Ky are the scale factor. If you know the coordinates of an other point M in both systems, than you will have Kx and Ky with

Kx = (x1O - x1M) / (x2O - x2M)
Ky = (y1O - y1M) / (y2O - y2M)

Then, you just need to apply the first relationship to go from one system to another system, with

x1 = x1O - Kx * (x2O - x2)
y1 = y10 - Ky * (y2O - y2)

or

x2 = x2O - (x1O - x1) / Kx
y2 = y2O - (y1O - y1) / Ky

Do you also need the code ?

ThibThib
+4  A: 

For the sake of clarity, I'm going to call coordinates in your base (xn, yn), and coordinates in your target (un, vn).

Now, if we assume:

  1. The origins of the two coordinate systems are the same.
  2. The orientation of the two coordinate systems are the same (i.e. one is not rotated with respect to the other).

In this case you only need one set of points {(x1, y1), (u1, v1)} to determine the location of (un, vn):

  • un = u1/x1 * xn
  • vn = v1/y1 * yn

Note: we must have x1 ≠ 0, y1 ≠ 0


On the other hand, if the two coordinate systems have different origins (but they are still not rotated with respect to one another), we will need two sets of points {(x1, y1), (u1, v1)} and {(x2, y2), (u2, v2)}:

  • un = (u2 - u1)/(x2 - x1) * (xn - x1) + u1
  • vn = (v2 - v1)/(y2 - y1) * (yn - y1) + v1

Note: we must have x1x2, y1y2


Now, if the two coordinate systems are rotated with respect to one another, you need (I believe) one more set of matching coordinates. But it doesn't sound like you need that (unless one of your maps has north pointing in a direction other than straight up), so I'm not going to work out the math now. :)

Kip
+1. Pretty much what I was going to write. This gets rids of the ambiguity he had and of the other answers.
Erich Mirabal
This is seeming to make sense but I am still a little lost. coodinates (538129.75, 169167.5) start at (0,0)the identical coordinates on my map are (-4.166675 , 53.816227) that start at (-4.5, 54.5)If I had new coodinates (537353.5, 179877) or (538051.4174927.5) I'm still strugging as U1 is zero and youd get a divide by zero exception
@Vault: I've added a note about divide by zero possibilities. Here is what the values of the variables would be for your data: x1=538129.75, y1=169167.5, x2=0, y2=0, u1=-4.166675, v1=53.816227, u2=-4.5, v2=54.5
Kip
A very big thank you Kip (and all that posted solutions)
@Vault: Given those values, for (X,Y)=(537353.5, 179877), I get: U = (-4.5 + 4.166675)/(0 - 538129.75)*(537353.5 - 538129.75) - 4.166675 = -4.167156; V = (54.5 - 53.816227)/(0 - 169167.5)*(179877 - 169167.5) - 53.816227 = -53.859515
Kip