Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 9, 2013 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/6198263 to your computer and use it in GitHub Desktop.
Save tmcw/6198263 to your computer and use it in GitHub Desktop.

Requires:

ModestMaps-py

from ModestMaps.Geo import MercatorProjection, Location, Coordinate
m = MercatorProjection(0)
points = [[38.0, -79.0], [37.0, -79.0]]
i = float('inf')
w = 800
h = 600
tl = [min(map(lambda x: x[0], points)), min(map(lambda x: x[1], points))]
br = [max(map(lambda x: x[0], points)), max(map(lambda x: x[1], points))]
c1 = m.locationCoordinate(Location(tl[0], tl[1]))
c2 = m.locationCoordinate(Location(br[0], br[1]))
while (abs(c1.column - c2.column) * 256.0) < w and (abs(c1.row - c2.row) * 256.0) < h:
c1 = c1.zoomBy(1)
c2 = c2.zoomBy(1)
center = m.coordinateLocation(Coordinate(
(c1.row + c2.row) / 2,
(c1.column + c2.column) / 2,
c1.zoom))
print center, c1.zoom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment