Python library for FlatGeobuf
Project description
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 = await 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flatgeobuf-0.3.0.tar.gz
(23.5 kB
view hashes)
Built Distribution
flatgeobuf-0.3.0-py3-none-any.whl
(36.5 kB
view hashes)
Close
Hashes for flatgeobuf-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897cfc004b39b982182c6b551b50cebcd64641aa01dba24d4572bfe2e018cf63 |
|
MD5 | fa2934aa577e446332867d38d5ef51ab |
|
BLAKE2b-256 | b9c8890f7c52be321b33597d0b460daea799694dffa18d55b9f17293404945e2 |