Working with utility functions

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:

  1. 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)
  1. 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 ...

Get Learning Geospatial Analysis with Python - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.