PNGCanvas

Sometimes, you may find that PIL is overkill for your purposes, or you are not allowed to install PIL because you do not have administrative rights to the machine that you're using to install Python modules created and compiled in C. In those cases, you can usually get away with the lightweight pure Python PNGCanvas module. You can install it using easy_install or pip.

Using this module, we can repeat the raster shapefile example we performed using PIL but in pure Python, as you can see here:

>>> import shapefile >>> import pngcanvas >>> r = shapefile.Reader("hancock.shp") >>> xdist = r.bbox[2] - r.bbox[0] >>> ydist = r.bbox[3] - r.bbox[1] >>> iwidth = 400 >>> iheight = 600 >>> xratio = iwidth/xdist >>> yratio = iheight/ydist >>> pixels ...

Get Learning Geospatial Analysis with Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.