Skip to content

Instantly share code, notes, and snippets.

@fajran fajran/gist:3088859
Created Jul 11, 2012

Embed
What would you like to do?
import sys
import pyproj
extents = 122115.0, 485775.0 # lower left coordinate of science park map
cellsize = 5, 5 # cell size of science park map
src = pyproj.Proj(proj='latlong',datum='WGS84') # regular GPS coordinate system (used in google maps)
dst = pyproj.Proj(init='EPSG:28992') # coordinate system of NL/science park map
reverse = False
if sys.argv[1] == '--reverse':
reverse = True
del sys.argv[1]
if not reverse:
lat = float(sys.argv[1])
lng = float(sys.argv[2])
mx, my = pyproj.transform(src, dst, lng, lat)
x = int((mx - extents[0]) / cellsize[0])
y = int((extents[1] - my) / cellsize[1])
print 'Lat/Lng:', lat, lng
print 'Map X, Y:', mx, my
print 'X, Y:', x, y
else:
x = float(sys.argv[1])
y = float(sys.argv[2])
mx = (x * cellsize[0]) + extents[0]
my = (y * cellsize[1]) + extents[1]
lng, lat = pyproj.transform(dst, src, mx, my)
print 'X, Y:', x, y
print 'Map X, Y:', mx, y
print 'Lat/Lng:', lat, lng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.