The 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 example below, we 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 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 Geospatial Analysis with Python. We'll create an image to use as a canvas in PIL, and then we'll use the PIL
ImageDraw module to render the polygon. Finally, we'll save it as a PNG image, as you can see in...