OGR

We touched on OGR as a way to handle WKT strings but its real power is as a universal vector library. This book strives for pure Python solutions but no single library even comes close to the variety of formats OGR can process.

Let's read a sample point shapefile using the OGR Python API. The sample shapefile can be downloaded as a zip file here: https://geospatialpython.googlecode.com/files/point.zip

This point shapefile has five points with single digit, positive coordinates. The attributes list the order in which the points were created, making it useful for testing. This simple example will read in the point shapefile, loop through each feature, and then print the x and y value of each point plus the value of the first attribute field: ...

Get Learning Geospatial Analysis with Python 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.