OverviewTeaching: 10 min Exercises: 0 minQuestions
What are common ways to encode vector geospatial data in Python, and how do they relate to broader encoding standards?Objectives
Learn about common community standards (broader than Python) for vector data encoding, and how they’re implemented in core Python libraries.
Learn to transform from one encoding type to another. Learn the
GeoJSONformat and exchange encoding interface, including the
__geo_interface__method implemented across libraries.
Standards exist for text (and binary) encoding of the geometry and feature types we saw. These include OGC/ISO Well-Known Text (WKT) and Well-Known Binary (WKB), OGC Geography Markup Language (GML), and GeoJSON (based on JSON, and now an ISO standard). GML is a complex XML-based encoding that we won’t discuss much here. We also won’t touch on WKB in much detail. In this tutorial we’ll focus on WKT and specially GeoJSON.
WKT text representations of geometric entities are fairly intuitive. Here are some examples of the basic geometric entities we saw earlier (where coordinates are ordered as X Y):
LINESTRING(0 0, 1 1, 1 2)
POLYGON((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))
MULTIPOINT((0 0), (1 2))
__geo_interface__method: Passing feature data around between code packages, as GeoJSON-like objects
geojsonis a light-weight package for converting to and from convenient, Pythonic, GeoJSON-like objects.
Python vector packages implement community standards for vector encoding. While these can seem complex, tools exist for conversion into various forms, and many of the tools include common interfaces for seamles exchange of data across tools.
Packages exist for easily reading data from file-based and other serialized data formats.
Most of these packages involve a series of steps to handle data, such as stepping through features via a loop, etc. Most tools do one or a couple of things only.
GeoPandasaddresses these challenges by enabling operations on feature collections in one step and bundling multiple tools via a coherent interface that builds on