1

I have 2 datasets of the same object but both obtained in different coordinate systems. One is in the coordinates obtained from an image [pixel data] so the coordinates are relative to the image. The other system is the WGS84 system.

I need to convert the points in the image pixel system by mapping them to their corresponding relative points in the WGS84 system using python.

The information I have is as follows:

The image data is in this format:

    pixIndex       X       Y    R    G    B
           1       0       0  227  227  227
           2       1       0  237  237  237
           3       2       0   0     0    0
           4       3       0  232  232  232
           5       4       0  233  233  233
...        ...     ...     ...  ...  ...  ...

The original data:

Original data XY WGS84

How can I do this conversion? equirectangular projection should be okay , I don't need it to be in Mercator coordinates.

Not very strong with python atm, I looked at this but wasn't sure how to do so in python:

Convert latitude/longitude point to a pixels (x,y) on mercator projection

Any and all help is appreciated :) thank you!

Megan Darcy
  • 530
  • 5
  • 15

1 Answers1

1

If the conversion formulas per your link are correct (especially this one in comments Convert latitude/longitude point to a pixels (x,y) on mercator projection) then:

import pandas as pd
import numpy as np
import math
from io import StringIO

df = pd.read_csv(StringIO("""    pixIndex       X       Y    R    G    B
           1       0       0  227  227  227
           2       1       0  237  237  237
           3       2       0   0     0    0
           4       3       0  232  232  232
           5       4       0  233  233  233"""), sep="\s+")

mapWidth  = df["X"].max()
mapHeight = df["Y"].max()

x = df["X"]
y = df["Y"]

df["Lon"] = ((360 * x) / mapWidth) - 180
df["Lat"] = 90 * (-1 + (4 * np.arctan(np.power(math.e, (math.pi - (2 * math.pi * y) / mapHeight)))) / math.pi)

Which outputs (Y is all 0 in sample data)

   pixIndex  X  Y    R    G    B    Lon  Lat
0         1  0  0  227  227  227 -180.0  NaN
1         2  1  0  237  237  237  -90.0  NaN
2         3  2  0    0    0    0    0.0  NaN
3         4  3  0  232  232  232   90.0  NaN
4         5  4  0  233  233  233  180.0  NaN

Not sure about validity of conversion process, just adapted the formula.

crayxt
  • 2,367
  • 2
  • 12
  • 17