PIL was originally developed for remote sensing but has evolved as a general image editing library for Python. Like NumPy, it is written in C for speed but is designed specifically for Python. In addition to image creation and processing, it also has a useful raster drawing module. PIL is also available via PyPI; however, in Python 3, you may want to use the Pillow module, which is an upgraded version of PIL. As you'll see in the following example, we can use a Python try statement to import PIL using two possible variations, depending on how you installed it.
In this example, we'll combine PyShp and PIL to rasterize the hancock shapefile from the previous examples and save it as an image. We'll use a world to pixel coordinate transformation similar to our SimpleGIS from Chapter 1, Learning about Geospatial Analysis with Python. We'll create an image to...