1 | '''This script reads in all the maperitive georef files
|
---|
2 | in a folder and converts them to GDAL-compatible world files
|
---|
3 | ex: image.tif.georef to image.tifw
|
---|
4 | '''
|
---|
5 |
|
---|
6 | import os
|
---|
7 | import xml.etree.ElementTree as ET
|
---|
8 |
|
---|
9 | #This is the folder that will get converted.
|
---|
10 | convert_dir = r"G:\Images"
|
---|
11 |
|
---|
12 | def convert(path, file):
|
---|
13 | doc = ET.parse(os.path.join(path, file)).getroot()
|
---|
14 | origin = doc.find('origin')
|
---|
15 | x = origin.find('x').text
|
---|
16 | y = origin.find('y').text
|
---|
17 | w = doc.find('cell-width').text
|
---|
18 | h = doc.find('cell-height').text
|
---|
19 |
|
---|
20 | base = os.path.splitext(file)[0]
|
---|
21 | outfile = os.path.join(path,base + 'w')
|
---|
22 |
|
---|
23 | with open(outfile, 'w') as F:
|
---|
24 | F.write(w + "\n")
|
---|
25 | F.write("0\n0\n")
|
---|
26 | F.write(h + "\n")
|
---|
27 | F.write(x + "\n")
|
---|
28 | F.write(y + "\n")
|
---|
29 |
|
---|
30 | refs = sorted([f for f in os.listdir(convert_dir) if f.endswith('.georef')])
|
---|
31 | for ref in refs:
|
---|
32 | convert(convert_dir, ref) |
---|