Coordinates to pixels

98 Views Asked by At

Let's say I have two geographical points $P_1=(512401.72N,0032120.17W)$ and $P_2=(512332.83N,0031948.64W)$. What would be the easiest way to scale line between the two so that it fit on a 800x800(pixel) interface.

1

There are 1 best solutions below

0
On

One way to do this is by interpreting the geographical points as points in 2D (which only works approximately for small areas). We let $P_1=(x_1,y_1)$ and $P_2=(x_2,y_2)$. Note that West is considered as a negative direction (e.g. $y_1=-32120.17$). If you want $P_1$ to land on the point $(0,800)$ and $P_2$ on the point $(800,0)$, then the following conversion is suitable: $$ \phi(x,y)=\left(\frac{x-x_1}{x_2-x_1}\cdot 800 \ \ ,\ \ \frac{y-y_2}{y_1-y_2} \cdot 800\right) $$ Note that depending on the relative position of your two points, this formula may need adaption. If you want a pixel output, you will also need to round the result to the nearest integer.