VEImagery Service Pixel to LatLong calculations


The VEImagery service gives us the ability to render static versions of Virtual Earth Maps. As handy as this is it would also be handy to be able to georeference the image that is returned. The article found here:!E7DBA9A4BFD458C5!488.entry

explains how to convert from LatLong to Pixel so that custom icons could be added to the map, however the conversion from Pixel to LatLong was not needed at that time. Building on top of the code that was provided in that article the following method can be used to calculate a LatLong value based on the pixel coordinate of a static image. The following formula can be used to perform this calculation.

        /// <summary>
        /// Convert Pixel coordinates to LatLong coordinates
        /// Based on code found here:
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        public LatLong PixelToLatLong(Point offset)
            int x = TopLeftCorner.X + offset.X;
            int y = TopLeftCorner.Y + offset.Y;

            double Longitude = (((double)x * 360) / (256 * Math.Pow(2, view.zoom))) – 180;

            double efactor = Math.Exp((0.5 – (double)y / 256 / Math.Pow(2, view.zoom)) * 4 * Math.PI);

            double Latitude = Math.Asin((efactor – 1) / (efactor + 1)) * 180 / Math.PI;

            LatLong latlong = new LatLong();
            latlong.Latitude = Latitude;
            latlong.Longitude = Longitude;

            return latlong;


The complete source code can be downloaded here:

Here is a screen shot of this application in action.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s