You need the image dimension in pixels (
width
and
height
), a lat/lon reference point at a specified pixel position (e.g.
lat0
and
lon0
at x = y = 0), and the lat/lon degress covered by the image (e.g. by having another reference point at max. x and y).
First step is calculating the scaling factors in pixels per degree:
double scale_x = width / lon_range;
double scale_y = height / lat_range;
Now you can get the pixel positions:
double x = (lon - lon0) * scale_x;
double y = (lat - lat0) * scaly_y;
Finally convert them to integers with rounding:
int xp = static_cast<int>((x > 0) ? x + 0.5 : x - 0.5);
int yp = static_cast<int>((y > 0) ? y + 0.5 : y - 0.5);</int></int>
Note: This is just from scratch (had not tested it).