I'm currently developing a small piece of (Java) software that should be able to display maps and the current GPS position within that map. I'm absolutely new to this, but it is pretty obvious that I'll have to do some kind of coordinate transformation. I've found "Proj4J", which seems to be able to do a lot for me. Now, what I have and what I want to do:
- I have a bitmap of a map. The projection of this map can be any "well-defined" one, like Lambert or Mercator. I cannot fix this to one projection.
- I have GPS coordinates from a "standard" GPS receiver. I believe they are lat/lon in WGS84, is that correct?
Now my questions: I must map the GPS position to basically "screen coordinates" in my map bitmap. And for that, I assume, reference points are needed for which I know their lat/lon and corresponding pixel positions. Since my map can easily cover a couple of hundred kilometers in range, a linear interpolation between the known points and an arbitrary position is probably not correct for all types of projections, am I right on that? I've read "Convert long/lat to pixel x/y on a given picure" so far, but this deals with a Mercator projection and I believe a linear approximation will work better than for a Lambert map. I imagine the whole process is as follows:
- "Calibrate" the map, i. e. identify two positions of known lat/lon in the bitmap and thus get their pixel position.
- Use the Proj.4-transformation from "lat/lon WGS84" to "map projection" to map those reference points from (1.) into map coordinates.
- Take the points from (2.) and map them again to a projection that will allow linear interpolation of the pixel positions, I'll call that the "pixel projection".
- Now I have two reference points with coordinates in the "pixel projection" and their corresponding pixel positions.
For a lat/lon value from the GPS receiver do the following:
- Convert the position to a map position using the "map projection".
- Take the map position from (1.) and convert it to a coordinate using the "pixel projection" from above.
- Since all distances in the "pixel projection" are maintained (that is the condition of the pixel projection!), an interpolation of the resulting coordinates from (2.) with the known position of the reference points from above can be made.
Here the big questions:
- Is this the way to go, using a final "pixel projection" to allow linear interpolation?
- What type of projection would that be and can that be done with Proj.4?
- Can the "way back" - I have a pixel position and want lat/lon be accomplished (like "pixel position" -> "pixel projection" -> "map projection" -> "lat/lon")?
Thank you very much, Jens.