Search code examples
python-2.7geolocationmap-projections

Convert geolocation Lat and Long to pixel coordinates on custom image


I'm making a weather program for myself in Python using images of the local rain radar (png) which have been modified to a custom size of (496, 480) pixels. I need advice on drawing my location (from latitude and longitude) on the image given that I know each pixel represents 250m, and a given point p's both image coordinate and corresponding real world coordinate.


Solution

  • For a small scale like that, the map projection does not really matter. You can first make the latitude and longitude relative to the map by subtracting from them the latitude and longitude of the top-left-hand corner pixel of the image.

    To convert the resulting angles to distances, convert them to radians and then multiply them by the average radius of the Earth (about 6371000 m), or if you want to be more precise, multiply them by the radius of the Earth in the area (ranging from 6356752 m at the poles to 6378137 m at the Equator).

    To convert these distance offsets to points on the map image in pixel coordinates, simply divide them by 250.