Create a gist now

Instantly share code, notes, and snippets.

Get BBOX value from poly file
import re
def parse(input_file):
f = open(input_file)
lines = f.readlines()
f.close()
longitudes = []
latitudes = []
for line in lines:
r = re.match("\s+([\w\.\+]+)\s+([\w\.\+]+)", line)
if r:
longitudes.append(float(r.groups()[0]))
latitudes.append(float(r.groups()[1]))
print "BBOX=" + str(min(longitudes)) + "," + str(min(latitudes)) + "," + str(max(longitudes)) + "," + str(max(latitudes))
if __name__ == '__main__':
import argparse
import os
p = argparse.ArgumentParser(description='Get BBOX value from poly file')
p.add_argument("input_file", metavar="input_file", help="Input file")
args = p.parse_args()
input_file = os.path.abspath(args.input_file)
parse(input_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment