Skip to content

Instantly share code, notes, and snippets.

@eresonance
Created February 12, 2022 14:23
Show Gist options
  • Save eresonance/3cd8840bd62db9159bd82eccd2e8a084 to your computer and use it in GitHub Desktop.
Save eresonance/3cd8840bd62db9159bd82eccd2e8a084 to your computer and use it in GitHub Desktop.
#!/bin/env python
import re
class Coordinate(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "({:.7},{:.7})".format(self.x, self.y)
def main(filename):
geo_regex = re.compile('/GPTS *\[(.*?)]')
with open(filename, 'rb') as f:
for l in f.readlines():
m = geo_regex.search(str(l))
if m:
geo_str = m.group(1)
break
else:
raise Exception("Coult not find /GPTS flag in data")
geo_str = geo_str.strip()
#print(geo_str)
geo = [float(x) for x in geo_str.split(" ")]
#viewport = [float(x) for x in viewport_str.split(" ")]
#box = [float(x) for x in box_str.split(" ")]
print(geo)
print("\n\n")
#width = box[2]
#height = box[3]
#topLeftPct = PercentCoordinate(viewport[0] / width, 1 - viewport[1] / height)
#bottomRightPct = PercentCoordinate(viewport[2] / width, 1 - viewport[3] / height)
topLeft = Coordinate(geo[0], geo[1])
bottomRight = Coordinate(geo[6], geo[7])
print("top left", topLeft)
print("")
print("bottom right", bottomRight)
#MapCalibrationPoint(topLeft, topLeftPct)
#MapCalibrationPoint(bottomRight, bottomRightPct)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Get cal data from geoPDF')
parser.add_argument('file', type=str,
help='filename')
args = parser.parse_args()
main(filename=args.file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment