Reader small image

You're reading from  Learning Geospatial Analysis with Python - Fourth Edition

Product typeBook
Published inNov 2023
PublisherPackt
ISBN-139781837639175
Edition4th Edition
Right arrow
Author (1)
Joel Lawhead
Joel Lawhead
author image
Joel Lawhead

Joel Lawhead is a PMI-certified Project Management Professional (PMP), a certified GIS Professional (GISP), and vice president of NVision Solutions, Inc., an award-winning firm specializing in geospatial technology integration and sensor engineering for NASA, FEMA, NOAA, the US Navy, and many other commercial and non-profit organizations. Joel began using Python in 1997 and started combining it with geospatial software development in 2000. He has authored multiple editions of Learning Geospatial Analysis with Python and QGIS Python Programming Cookbook, both from Packt. He is also the developer of the open source Python Shapefile Library (PyShp) and maintains a geospatial technical blog.
Read more about Joel Lawhead

Right arrow

Converting the route to a shapefile

The raster version of the least cost path route is useful for visualization, but it isn’t very good for analysis because it is embedded in the raster, and it is, therefore, difficult to relate to other datasets as we have done so many other times in this book. Our next goal will be to use the path data that we saved when creating the route to create a shapefile since the saved data is in the proper order. The following code will convert our raster path to a shapefile that is easier to use in a GIS for analysis:

  1. First, let’s import the necessary modules. We’ll need pickle to load the previously saved path, getline from linecache to read the header information from a file, and shapefile to write shapefiles:
    import pickle
    from linecache import getline
    import shapefile
  2. Next, we define a function named pix2coord to convert pixel coordinates to real-world coordinates. This function takes in three parameters: gt for geotransform...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Geospatial Analysis with Python - Fourth Edition
Published in: Nov 2023Publisher: PacktISBN-13: 9781837639175

Author (1)

author image
Joel Lawhead

Joel Lawhead is a PMI-certified Project Management Professional (PMP), a certified GIS Professional (GISP), and vice president of NVision Solutions, Inc., an award-winning firm specializing in geospatial technology integration and sensor engineering for NASA, FEMA, NOAA, the US Navy, and many other commercial and non-profit organizations. Joel began using Python in 1997 and started combining it with geospatial software development in 2000. He has authored multiple editions of Learning Geospatial Analysis with Python and QGIS Python Programming Cookbook, both from Packt. He is also the developer of the open source Python Shapefile Library (PyShp) and maintains a geospatial technical blog.
Read more about Joel Lawhead