9

I have a map from here. I want to be able to simply convert arbitrary lon/lat pair to pixels on the map (also the ability to do reverse conversion). The maps come with .tfw file and projection info, here it is:

0.02222222222222 
0.00000000000000 
0.00000000000000 
-0.02222222222222 
-180.00000000000000 
90.00000000000000

and projection info:

Projection: Plate Carree aka Geographic or "LatLong"
Earth ellipsoid: Sphere, radius 6370997 m
Datum: WGS84
Extent: 180 West to 180 East, 90 North to 90 South
Size: 16,200 height samples wide x 8,100 high
Resolution: 2.47 km/pixel

I am completely new to cartography-related stuff, and as far as I figured out I should first do the transformation from WGS84 (lon/lat pair) to Geographic projection (aren't they the same?). It seems to me that they are the same, actually, but sphere radius in projection info above is 6370997 and is different from spatialreference.com page I found for Plate Carree projection. Anyway, I found DotSpatial.Projections library can do this for me, with the following code:

    var kievCoordinates = new[] { 50.4546600, 30.5238000 };
    var z = new[] { 1.0 };

    var wgs84 = KnownCoordinateSystems.Geographic.World.WGS1984;
    var dest = new ProjectionInfo();
    dest.ParseEsriString(
        "PROJCS[\"WGS 84 / Plate Carree (deprecated)\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Equidistant_Cylindrical\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]");

    Reproject.ReprojectPoints(kievCoordinates, z, wgs84, dest, 0, 1);

And then I must translate resulting coordinates to pixels on the map using world file. I am aware of the following formula:

wikipedia image

But it seems that there are degrees not meters in the world file and I don't know what to do with them. Generally, am I doing right things? Or there is more easy way, given my data?

  • 1
    Based on the world file, the raster is using latitude-longitude and degrees as the units. The cell size is 0.0222 degrees. This is sometimes known as pseudo-Plate Carree. Plate Carree would scale and convert the values to meters. There's also a mix of datum is called WGS84, but a sphere with radius=6370997 is mentioned. Trying using WKID:4326. – mkennedy Mar 10 '16 at 17:21
  • @mkennedy I think that the formula above applied to the world file would not result in anything meaningful because it was designed for meters? I also don't know and googled without any result what WKID:4326 means. – Dmitry Marchuk Mar 16 '16 at 14:18
6
+100

There is no transformation between coordinates but to/from pixel positions, like this: we assume px, py is a pixel position in your map, while geox and geoy are real world coordinates. We also have xOff, yOff taken from the tfw, with -180, 90 plus xsize and ysize, with 0.02222222222222, -0.02222222222222

pix2coord(px,py)
    geox = xOff + (px * xsize)
    geoy = yOff + (py * ysize)

coord2pix(geox, geoy)
    px = (geox - xOff) / xsize 
    py = (geoy - yOff) / ysize

the above two pseudo functions tell us the geolocation (geox, geoy) for a given pixel position, and, I think that's what you asked for, the pixel position for a given geolocation. This is only possible, because the "plate carree" treats geographic degrees with longitude and latitude as metric coordinates on a plane (within a rectangular coordinate system). If you would draw the graticule of the earth, you would get equally sized squares (And that's what your map picture loooks like to). After editing my errors, now I get with lon/lat (50.4546600, 30.5238000) I get (10370.459803704598, 2676.42902676429). Cast it to integer, if you need pixel indizes.

  • px = (geox + xOff) / xsize, for your example would be (50.4546600 + (-180)) / 0.02222222222222 which is negative and roughly equals 5830. Which is not 2113.3936363636362. Please, explain further, or correct the answer. – Dmitry Marchuk Mar 22 '16 at 16:00
  • Original code was in javascript with some dependencies, i'll check... – Andreas Müller Mar 22 '16 at 17:08
  • I changed code and Text above, because I had an error copying it from a JavaScript. – Andreas Müller Mar 22 '16 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.