PythonScripts: convert_georef.py

File convert_georef.py, 864 bytes (added by Uriel, 7 years ago)

This script reads in all the maperitive georef files in a folder and converts them to GDAL-compatible world files ex: image.tif.georef to image.tifw

Line 
1'''This script reads in all the maperitive georef files
2in a folder and converts them to GDAL-compatible world files
3ex: image.tif.georef to image.tifw
4'''
5
6import os
7import xml.etree.ElementTree as ET
8
9#This is the folder that will get converted.
10convert_dir = r"G:\Images"
11
12def 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
30refs = sorted([f for f in os.listdir(convert_dir) if f.endswith('.georef')])
31for ref in refs:
32        convert(convert_dir, ref)