python-flatgeobuf
A Python library for reading FlatGeobuf. Ported from the official TypeScript implementation.
Features
- Minimal dependencies
- Simple API
- Supports cloud-optimized bounding box filtering
- Works on JupyterLite (Pyodide)
Installation
pip install flatgeobuf
Usage
Loaders
load()
import flatgeobuf as fgb
# All features
with open("example.fgb", "rb") as f:
data = fgb.load(f)
# ...or features within a bounding box
with open("example.fgb", "rb") as f:
data = fgb.load(f, bbox=(-26.5699, 63.1191, -12.1087, 67.0137))
print(data)
# { "type": "FeatureCollection", "features": [...] }
load_http()
import flatgeobuf as fgb
# All features
data = fgb.load_http("https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb")
# ...or features within a bounding box
data = fgb.load_http(
"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb",
bbox=(-26.5699, 63.1191, -12.1087, 67.0137)
)
print(data)
# { "type": "FeatureCollection", "features": [...] }
load_http_async()
NOTE: At the moment, load_http_async() is not truly asynchronous.
import flatgeobuf as fgb
# All features
data = await fgb.load_http_async("https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb")
# ...or features within a bounding box
data = await fgb.load_http_async(
"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb",
bbox=(-26.5699, 63.1191, -12.1087, 67.0137)
)
print(data)
# { "type": "FeatureCollection", "features": [...] }
Readers
Reader
import flatgeobuf as fgb
# All features
with open("example.fgb", "rb") as f:
reader = fgb.Reader(f)
for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
# ...or features within a bounding box
with open("example.fgb", "rb") as f:
reader = fgb.Reader(f, bbox=(-26.5699, 63.1191, -12.1087, 67.0137))
for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
HTTPReader
import flatgeobuf as fgb
# All features
reader = fgb.HTTPReader("https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb")
for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
# ...or features within a bounding box
reader = fgb.HTTPReader(
"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb",
bbox=(-26.5699, 63.1191, -12.1087, 67.0137)
)
for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
HTTPReader (Async)
NOTE: At the moment, HTTPReader is not truly asynchronous.
import flatgeobuf as fgb
# All features
reader = fgb.HTTPReader("https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb")
async for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
# ...or features within a bounding box
reader = fgb.HTTPReader(
"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb",
bbox=(-26.5699, 63.1191, -12.1087, 67.0137)
)
async for feature in reader:
print(feature)
# { "type": "Feature", "properties": {...}, "geometry": {...} }
Running on JuptyerLite
1. Install flatgeobuf on JupyterLite:
%pip install flatgeobuf
# ...or
import micropip
await micropip.install("flatgeobuf")
2. Enable HTTP requests in Pyodide via pyodide_http
import pyodide_http
pyodide_http.patch_all()
3. Run as usual!
import flatgeobuf as fgb
data = fgb.load_http(
"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb",
bbox=(-26.5699, 63.1191, -12.1087, 67.0137)
)
print(data)
# { "type": "FeatureCollection", "features": [...] }
Roadmap
- Read FlatGeobuf
- Read top-level (
FeatureCollection) properties
- Read top-level (
- Write FlatGeobuf
- Deploy JuptyerLite examples
- Rewrite some parts in Rust? (parcked R-tree, geometry intersection)
License
MIT
Metadata
Release files for flatgeobuf 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flatgeobuf-0.3.1.tar.gz | 23.5 kB | Without provenance | Details for flatgeobuf-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flatgeobuf-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for flatgeobuf-0.3.1-py3-none-any.whl |
Total release size: 60.0 kB
Release files / flatgeobuf-0.3.1.tar.gz
| Download URL | flatgeobuf-0.3.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a510f7700dbe8b3f9ba19fb26d6e34679af5e92aec1c832de1e54fc944a9261
|
|
BLAKE2b-256 checksum How to use checksums |
8f8b0b3b37a702fc05308d1e31355af325f04b22f835b078cb4cee87c5c75603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Darwin/21.6.0
|
Release files / flatgeobuf-0.3.1-py3-none-any.whl
| Download URL | flatgeobuf-0.3.1-py3-none-any.whl |
|---|---|
| Size | 36.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
139ca924376e34170dbee64cd1af7cdc5072e1055c9f227c197a09f07bca9f66
|
|
BLAKE2b-256 checksum How to use checksums |
4c2fc2a522218a050cbd849b9d3b7b2426a9e9639970f4d039cf8508a3ce3dd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.4 Darwin/21.6.0
|
Security for flatgeobuf 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.