Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

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:

  1. 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(4326)
    
       We...