Skip to content

Instantly share code, notes, and snippets.

@smellman
Created December 3, 2016 09:55
Show Gist options
  • Select an option

  • Save smellman/a2770f3a6c4717315cc0a4538b985a1c to your computer and use it in GitHub Desktop.

Select an option

Save smellman/a2770f3a6c4717315cc0a4538b985a1c to your computer and use it in GitHub Desktop.
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)
@smellman
Copy link
Copy Markdown
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment