All of the following functions, except the functions related to time, have been used in previous chapters in some form. Let's see how to use utility functions in our example:
- First, the ll2m() function converts latitude and longitude to meters:
def ll2m(lat, lon): """Lat/lon to meters""" x = lon * 20037508.34 / 180.0 y = math.log(math.tan((90.0 + lat) * math.pi / 360.0)) / (math.pi / 180.0) y = y * 20037508.34 / 180 return (x, y)
- The world2pixel() function converts geospatial coordinates to pixel coordinates on our output map image:
def world2pixel(x, y, w, h, bbox): """Converts world coordinates to image pixel coordinates""" # Bounding box of the map minx, miny, maxx, maxy = bbox # world x distance xdist ...