conscientious and compliant GeoJSON

GeoJSON is a specification for encoding geographical features in JSON. GeoJSON is simple, reasonably flexible, and can be read using any stdlib JSON package.

picogeojson is a pure-Python package that ensures that the GeoJSON you create adheres to the 2016 GeoJSON specification, taking care of details such as polygon closing, winding order, and antimeridian-cutting. For a more full-featured Python geospatial package, take a look at Karta. It also handles unmarshaling GeoJSON strings from unknown sources, allowing you to skip a lot of boilerplate and key-checking.


pip install -U picogeojson


Create and serialize a geometry:An object representing spatial information. Available geometries are Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, and GeometryCollection.

pt = picogeojson.Point((1.0, 3.0))
json_str = picogeojson.tostring(pt)

Or, load from a JSON string:

pt_from_json = picogeojson.fromstring('{"type": "Point", "coordinates": [1.0, 3.0]}')

Skip boilerplate error-checking using GeoJSONResult and extractor methods:

result = picogeojson.result_fromstring(api_response.decode("utf-8"))

# Expecting one or more points or multipoints
for geom in result.points:
    # do something with points
    # ...

for geom in result.multilinestrings:
    # do something with multilinestrings
    # ...

Extractors also work with feature objectsA feature is an object containing a geometry and associated non-spatial metadata in a .properties dictionary. and can filter by .properties

result = picogeojson.result_fromstring(api_response.decode("utf-8"))

for feature in result.features("Polygon", {"type": "Lake", "state": "Oregon"}):
    # do something with lakes in Oregon
    # ...

Compose and deconstruct GeoJSON objects with merge() and burst():

points = [picogeojson.Point((1, 2)),
          picogeojson.Point((3, 4)),
          picogeojson.Point((5, 6))]

merged_points = picogeojson.merge(points)
original_points = picogeojson.burst(merged_points)

Source code