-------------------------------------------------- corners.py -------------------------------------------------- import sys # Remember kids: x is lon and y is lat! southwest_lat = float(sys.argv[1]) southwest_lon = float(sys.argv[2]) northeast_lat = float(sys.argv[3]) northeast_lon = float(sys.argv[4]) margin = float(sys.argv[5]) x_width = northeast_lon - southwest_lon y_width = northeast_lat - southwest_lat if x_width/y_width == 2.0: new_x_width = x_width*(1 + margin) new_y_width = y_width*(1 + margin) if x_width/y_width > 2.0: # make y bigger new_x_width = x_width*(1 + margin) new_y_width = new_x_width/2.0 if x_width/y_width < 2.0: # make x bigger new_y_width = y_width*(1 + margin) new_x_width = 2.0*new_y_width # Finally compute center of original extents: xc = (northeast_lon + southwest_lon)/2.0 yc = (northeast_lat + southwest_lat)/2.0 # Compute final extents: new_northeast_lon = xc + new_x_width/2.0 new_southwest_lon = xc - new_x_width/2.0 new_northeast_lat = yc + new_y_width/2.0 new_southwest_lat = yc - new_y_width/2.0 print "Latitude,Longitude,Name,IconColor,Icon" # print "%s,%s,%s,orange,111" % (new_southwest_lat,new_southwest_lon,"new SW corner") print "%s,%s,%s,orange,111" % (new_northeast_lat,new_southwest_lon,"new NW corner") print "%s,%s,%s,orange,111" % (new_northeast_lat,new_northeast_lon,"new NE corner") print "%s,%s,%s,orange,111" % (new_southwest_lat,new_northeast_lon,"new SE corner") print "%s,%s,%s,red,111" % (southwest_lat,southwest_lon,"old SW corner") print "%s,%s,%s,red,111" % (northeast_lat,southwest_lon,"old NW corner") print "%s,%s,%s,red,111" % (northeast_lat,northeast_lon,"old NE corner") print "%s,%s,%s,red,111" % (southwest_lat,northeast_lon,"old SE corner") -------------------------------------------------- Test -------------------------------------------------- # # El Segundo 4/2/14 # python ./corners.py 33.905266155474649 -118.39714482432021 33.907727245282345 -118.38229948451819 0.1 > error_corners.csv -------------------------------------------------- error_corners.csv -------------------------------------------------- Latitude,Longitude,Name,IconColor,Icon 33.9024142319,-118.397887091,new SW corner,orange,111 33.9105791688,-118.397887091,new NW corner,orange,111 33.9105791688,-118.381557218,new NE corner,orange,111 33.9024142319,-118.381557218,new SE corner,orange,111 33.9052661555,-118.397144824,old SW corner,red,111 33.9077272453,-118.397144824,old NW corner,red,111 33.9077272453,-118.382299485,old NE corner,red,111 33.9052661555,-118.382299485,old SE corner,red,111 --------------------------------------------------