[GIS] How to convert image pixel to latitude and longitude

convertcoordinate system

We are developing an android application for showing an image with geo referened with .jgw and .prj file as below. we want to identify the geo location coordinate of image coordinate(in pixel) that user touched on the image. How we can use image cordinate to find ts relative latitude and longitude using java in android.

We tried proj4 java library for android but it seems incorrect when we find the distance of two point and we couldn't trace where is the issue.

Below are our .jgw and .prj file

JGW File

0.00000180562999999
0
0
-0.00000180562999999
76.882389 (dummy location due to NDA)
8.572607 (dummy location due to NDA)

PRJ File

GEOGCS["GCS_WGS_1984",DATUM["D_WGS84",SPHEROID["WGS84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

Best Answer

You have world files (.jgw) and projection definition files (.prj).

World file values:

Line 1: A: pixel size in the x-direction in map units/pixel
Line 2: D: rotation about y-axis
Line 3: B: rotation about x-axis
Line 4: E: pixel size in the y-direction in map units, almost always negative
Line 5: C: x-coordinate of the center of the upper left pixel
Line 6: F: y-coordinate of the center of the upper left pixel

You can convert pixel coordinates to map coordinates (longitude, latitude assuming the projection is always WGS84 / EPSG 4326) using some simple maths:

mx = C + px * A + py * B
my = F + px * D + py * E

Where mx, my = map coordinates and px, py = pixel coordinates.

In your case, as the rotation terms are zero, the equation becomes:

mx = C + px * A
my = F + py * E

Which means x or y coordinate of top left corner + image coordinate * pixel size.