Last active
March 22, 2017 09:42
-
-
Save tkardi/f241543d56dcc28e590ca2e961485f9b to your computer and use it in GitHub Desktop.
Batch create *.prj files for files on a path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
import requests | |
def get_prj_wkt(srid): | |
url = 'http://epsg.io/%s.wkt' % srid | |
r = requests.get(url) | |
r.raise_for_status() | |
return r.text | |
def generate_prj(path, ext, srid): | |
wkt = get_prj_wkt(srid) | |
files = glob.glob('%s/*.%s' % (path, ext)) | |
for _file in files: | |
filepath, _ = os.path.splitext(_file) | |
prj = '%s.%s' % (filepath, 'prj') | |
with open(prj, 'w') as f: | |
f.write(wkt) | |
if __name__ == '__main__': | |
generate_prj( | |
'/path/to/files/without/trailing/slash', | |
'tif', | |
3301) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment