Batch setting the projection definition of a folder full of Shapefiles
Working with one Shapefile is fine but working with tens or hundreds of files is something else. In such a scenario, we'll need automation to get a job done fast.
We have a folder that contains several Shapefiles that are all in the same coordinate system but do not have a .prj
file. We want to create a .prj
file for each Shapefile in the current directory.
This script is a modified version of the previous code example that could write a .prj
file for a single Shapefile into a batch process that can run over several Shapefiles.
How to do it...
We have a folder with many Shapefiles and we would like to create a new .prj
file for each Shapefile in this folder, so let's get started:
- Create a new Python file named
ch02_05_batch_shp_prj.py
in your/ch02/code/working/
directory and add the following code:#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib import os from osgeo import osr def create_epsg_wkt_esri...