flatgeobuf


Nameflatgeobuf JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/ozekik/python-flatgeobuf
SummaryPython library for FlatGeobuf
upload_time2024-08-13 09:09:31
maintainerNone
docs_urlNone
authorKentaro Ozeki
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-flatgeobuf

[![PyPI](https://img.shields.io/pypi/v/flatgeobuf.svg)](https://pypi.org/project/flatgeobuf/)
[![build](https://github.com/ozekik/python-flatgeobuf/actions/workflows/ci.yaml/badge.svg)](https://github.com/ozekik/python-flatgeobuf/actions/workflows/ci.yaml)
[![Coverage Status](https://codecov.io/gh/ozekik/python-flatgeobuf/branch/master/graph/badge.svg)](https://codecov.io/gh/ozekik/python-flatgeobuf)

A Python library for reading [FlatGeobuf](https://flatgeobuf.org/).
Ported from the official [TypeScript implementation](https://github.com/flatgeobuf/flatgeobuf/tree/master/src/ts).

## Features

- Minimal dependencies
- Simple API
- Supports cloud-optimized bounding box filtering
- Works on [JupyterLite](https://github.com/jupyterlite/jupyterlite) ([Pyodide](https://pyodide.org/))

## Installation

```bash
pip install flatgeobuf
```

## Usage

- [Loaders](#loaders)
    - [`load()`](#load)
    - [`load_http()`](#load_http)
    - [`load_http_async()`](#load_http_async)
- [Readers](#readers)
    - [`Reader`](#reader)
    - [`HTTPReader`](#httpreader)
    - [`HTTPReader` (Async)](#httpreader-async)

### Loaders

#### `load()`

```python
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()`

```python
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.

```python
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`

```python
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`

```python
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.

```python
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:

```python
%pip install flatgeobuf

# ...or
import micropip
await micropip.install("flatgeobuf")
```

2\. Enable HTTP requests in Pyodide via [`pyodide_http`](https://github.com/koenvo/pyodide-http)

```python
import pyodide_http
pyodide_http.patch_all()
```

3\. Run as usual!

```python
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

- [x] Read FlatGeobuf
  - [ ] Read top-level (`FeatureCollection`) properties
- [ ] Write FlatGeobuf
- [ ] Deploy JuptyerLite examples
- [ ] Rewrite some parts in Rust? (parcked R-tree, geometry intersection)

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ozekik/python-flatgeobuf",
    "name": "flatgeobuf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Kentaro Ozeki",
    "author_email": "kentaro.ozeki+dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8f/8b/0b3b37a702fc05308d1e31355af325f04b22f835b078cb4cee87c5c75603/flatgeobuf-0.3.1.tar.gz",
    "platform": null,
    "description": "# python-flatgeobuf\n\n[![PyPI](https://img.shields.io/pypi/v/flatgeobuf.svg)](https://pypi.org/project/flatgeobuf/)\n[![build](https://github.com/ozekik/python-flatgeobuf/actions/workflows/ci.yaml/badge.svg)](https://github.com/ozekik/python-flatgeobuf/actions/workflows/ci.yaml)\n[![Coverage Status](https://codecov.io/gh/ozekik/python-flatgeobuf/branch/master/graph/badge.svg)](https://codecov.io/gh/ozekik/python-flatgeobuf)\n\nA Python library for reading [FlatGeobuf](https://flatgeobuf.org/).\nPorted from the official [TypeScript implementation](https://github.com/flatgeobuf/flatgeobuf/tree/master/src/ts).\n\n## Features\n\n- Minimal dependencies\n- Simple API\n- Supports cloud-optimized bounding box filtering\n- Works on [JupyterLite](https://github.com/jupyterlite/jupyterlite) ([Pyodide](https://pyodide.org/))\n\n## Installation\n\n```bash\npip install flatgeobuf\n```\n\n## Usage\n\n- [Loaders](#loaders)\n    - [`load()`](#load)\n    - [`load_http()`](#load_http)\n    - [`load_http_async()`](#load_http_async)\n- [Readers](#readers)\n    - [`Reader`](#reader)\n    - [`HTTPReader`](#httpreader)\n    - [`HTTPReader` (Async)](#httpreader-async)\n\n### Loaders\n\n#### `load()`\n\n```python\nimport flatgeobuf as fgb\n\n# All features\nwith open(\"example.fgb\", \"rb\") as f:\n    data = fgb.load(f)\n\n# ...or features within a bounding box\nwith open(\"example.fgb\", \"rb\") as f:\n    data = fgb.load(f, bbox=(-26.5699, 63.1191, -12.1087, 67.0137))\n\nprint(data)\n# { \"type\": \"FeatureCollection\", \"features\": [...] }\n```\n\n#### `load_http()`\n\n```python\nimport flatgeobuf as fgb\n\n# All features\ndata = fgb.load_http(\"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\")\n\n# ...or features within a bounding box\ndata = fgb.load_http(\n    \"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\",\n    bbox=(-26.5699, 63.1191, -12.1087, 67.0137)\n)\n\nprint(data)\n# { \"type\": \"FeatureCollection\", \"features\": [...] }\n```\n\n#### `load_http_async()`\n\n**NOTE:** At the moment, `load_http_async()` is not truly asynchronous.\n\n```python\nimport flatgeobuf as fgb\n\n# All features\ndata = await fgb.load_http_async(\"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\")\n\n# ...or features within a bounding box\ndata = await fgb.load_http_async(\n    \"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\",\n    bbox=(-26.5699, 63.1191, -12.1087, 67.0137)\n)\n\nprint(data)\n# { \"type\": \"FeatureCollection\", \"features\": [...] }\n```\n\n### Readers\n\n#### `Reader`\n\n```python\nimport flatgeobuf as fgb\n\n# All features\nwith open(\"example.fgb\", \"rb\") as f:\n    reader = fgb.Reader(f)\n    for feature in reader:\n        print(feature)\n        # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n\n# ...or features within a bounding box\nwith open(\"example.fgb\", \"rb\") as f:\n    reader = fgb.Reader(f, bbox=(-26.5699, 63.1191, -12.1087, 67.0137))\n    for feature in reader:\n        print(feature)\n        # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n```\n\n#### `HTTPReader`\n\n```python\nimport flatgeobuf as fgb\n\n# All features\nreader = fgb.HTTPReader(\"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\")\nfor feature in reader:\n    print(feature)\n    # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n\n# ...or features within a bounding box\nreader = fgb.HTTPReader(\n    \"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\",\n    bbox=(-26.5699, 63.1191, -12.1087, 67.0137)\n)\nfor feature in reader:\n    print(feature)\n    # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n```\n\n#### `HTTPReader` (Async)\n\n**NOTE:** At the moment, `HTTPReader` is not truly asynchronous.\n\n```python\nimport flatgeobuf as fgb\n\n# All features\nreader = fgb.HTTPReader(\"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\")\nasync for feature in reader:\n    print(feature)\n    # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n\n# ...or features within a bounding box\nreader = fgb.HTTPReader(\n    \"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\",\n    bbox=(-26.5699, 63.1191, -12.1087, 67.0137)\n)\nasync for feature in reader:\n    print(feature)\n    # { \"type\": \"Feature\", \"properties\": {...}, \"geometry\": {...} }\n```\n\n### Running on JuptyerLite\n\n1\\. Install `flatgeobuf` on JupyterLite:\n\n```python\n%pip install flatgeobuf\n\n# ...or\nimport micropip\nawait micropip.install(\"flatgeobuf\")\n```\n\n2\\. Enable HTTP requests in Pyodide via [`pyodide_http`](https://github.com/koenvo/pyodide-http)\n\n```python\nimport pyodide_http\npyodide_http.patch_all()\n```\n\n3\\. Run as usual!\n\n```python\nimport flatgeobuf as fgb\n\ndata = fgb.load_http(\n    \"https://raw.githubusercontent.com/flatgeobuf/flatgeobuf/master/test/data/countries.fgb\",\n    bbox=(-26.5699, 63.1191, -12.1087, 67.0137)\n)\n\nprint(data)\n# { \"type\": \"FeatureCollection\", \"features\": [...] }\n```\n\n## Roadmap\n\n- [x] Read FlatGeobuf\n  - [ ] Read top-level (`FeatureCollection`) properties\n- [ ] Write FlatGeobuf\n- [ ] Deploy JuptyerLite examples\n- [ ] Rewrite some parts in Rust? (parcked R-tree, geometry intersection)\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for FlatGeobuf",
    "version": "0.3.1",
    "project_urls": {
        "Homepage": "https://github.com/ozekik/python-flatgeobuf",
        "Repository": "https://github.com/ozekik/python-flatgeobuf"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c2fc2a522218a050cbd849b9d3b7b2426a9e9639970f4d039cf8508a3ce3dd4",
                "md5": "549476c8bba56774d2ecbff5477131ab",
                "sha256": "139ca924376e34170dbee64cd1af7cdc5072e1055c9f227c197a09f07bca9f66"
            },
            "downloads": -1,
            "filename": "flatgeobuf-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "549476c8bba56774d2ecbff5477131ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 36493,
            "upload_time": "2024-08-13T09:09:30",
            "upload_time_iso_8601": "2024-08-13T09:09:30.063662Z",
            "url": "https://files.pythonhosted.org/packages/4c/2f/c2a522218a050cbd849b9d3b7b2426a9e9639970f4d039cf8508a3ce3dd4/flatgeobuf-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f8b0b3b37a702fc05308d1e31355af325f04b22f835b078cb4cee87c5c75603",
                "md5": "78fed759870050c5c6dbfea8eff4e799",
                "sha256": "4a510f7700dbe8b3f9ba19fb26d6e34679af5e92aec1c832de1e54fc944a9261"
            },
            "downloads": -1,
            "filename": "flatgeobuf-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "78fed759870050c5c6dbfea8eff4e799",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 23538,
            "upload_time": "2024-08-13T09:09:31",
            "upload_time_iso_8601": "2024-08-13T09:09:31.744209Z",
            "url": "https://files.pythonhosted.org/packages/8f/8b/0b3b37a702fc05308d1e31355af325f04b22f835b078cb4cee87c5c75603/flatgeobuf-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-13 09:09:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ozekik",
    "github_project": "python-flatgeobuf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flatgeobuf"
}
        
Elapsed time: 0.69570s