Well-Known Text (WKT)
The WKT format has been around for years and is a simple text-based format for representing geometries and spatial reference systems. It is primarily used as a data exchange format by systems that implement the OGC Simple Features for SQL specification. Take a look at the following example WKT representation of a polygon:
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))
Currently, the best way to read and write WKT is by using the Shapely
library. Shapely
provides a very Python-oriented or Pythonic interface to the Geometry Engine, Open Source (GEOS) library we described in Chapter 3, The Geospatial Technology Landscape.
You can install Shapely
using Conda in your virtual environment. You can also use the wheel from the site we mentioned in the previous section. Shapely has a WKT
module that can load and export this data. Let’s use Shapely
to load the previous polygon example and then verify that it has been loaded as a polygon object by...