Skip to content

Instantly share code, notes, and snippets.

@tkardi
Last active March 22, 2017 09:42
Show Gist options
  • Save tkardi/f241543d56dcc28e590ca2e961485f9b to your computer and use it in GitHub Desktop.
Save tkardi/f241543d56dcc28e590ca2e961485f9b to your computer and use it in GitHub Desktop.
Batch create *.prj files for files on a path
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