Creating a projection definition for a Shapefile if it does not exist
You recently downloaded a Shapefile from an Internet resource and saw that the .prj
file was not included. You do know, however, that the data is stored in the EPSG:4326 coordinate system as stated on the website from where you downloaded the data. Now the following code will create a new .prj
file.
Getting ready
Start up your Python virtual environment with the workon pygeo_analysis_cookbook
command:
How to do it...
In the following steps, we will take you through creating a new .prj
file to accompany our Shapefile. The .prj
extension is necessary for many spatial operations performed by a desktop GIS, web service, or script:
- Create a new Python file named
ch02_04_write_prj_file.py
in your/ch02/code/working/
directory and add the following code:#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib import os def get_epsg_code(epsg): """ Get the ESRI formatted .prj definition usage get_epsg_code...