geojson

3.2.0 · active · verified Thu Apr 09

Python bindings and utilities for GeoJSON. This library provides functions for encoding and decoding GeoJSON formatted data, classes for all GeoJSON Objects as defined by the GeoJSON Format Specification, and implements the Python `__geo_interface__` Specification. It is currently at version 3.2.0 and is actively maintained by the Jazzband community, compatible with Python 3.7 and above.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create common GeoJSON objects like `Point`, `Feature`, and `FeatureCollection`, and then serialize them into a GeoJSON formatted string using `geojson.dumps`.

from geojson import Point, Feature, FeatureCollection, dumps

# Create a Point geometry
point = Point((-115.81, 37.24))

# Create a Feature with the Point geometry and properties
feature = Feature(geometry=point, properties={"name": "Area 51"})

# Create a FeatureCollection containing the feature
feature_collection = FeatureCollection([feature])

# Serialize the FeatureCollection to a GeoJSON string with indentation
geojson_str = dumps(feature_collection, indent=2)
print(geojson_str)

view raw JSON →