parse-wkb


Nameparse-wkb JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryPure python library to parse WKB (Well Known Binary) GIS geospatial geometry format
upload_time2024-02-19 15:37:59
maintainer
docs_urlNone
authorthehappycheese
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pure Python WKB (Well Known Binary) Converter

[![Test and Publish PyPi](https://github.com/thehappycheese/parse_wkb/actions/workflows/publish_to_pypi.yml/badge.svg)](https://github.com/thehappycheese/parse_wkb/actions/workflows/publish_to_pypi.yml)
[![PyPI - Version](https://img.shields.io/pypi/v/parse-wkb.svg)](https://pypi.org/project/parse-wkb)

- `wkb_to_geojson()` converts WKB geometry into GeoJSON
- `wkb_to_wkt()` converts WKB geometry into WKT
- `geojson_to_wkb()` converts GeoJSON into WKB
- `wkb_to_abstract()` converts WKB into an abstract representation which closely resembles the binary format (for debugging purposes)

```python
from parse_wkb import (
    wkb_to_abstract,
    wkb_to_geojson,
    wkb_to_wkt,
    geojson_to_wkb
)

import json

WKB = b"\x01\x04\x00\x00\x00\x04\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00D@\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00D@\x00\x00\x00\x00\x00\x00>@\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x004@\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00$@"

parsed_to_geojson = wkb_to_geojson(WKB)
assert json.dumps(parsed_to_geojson) == '{"type": "MultiPoint", "coordinates": [[10.0, 40.0], [40.0, 30.0], [20.0, 20.0], [30.0, 10.0]]}'

parsed_to_wkt = wkb_to_wkt(WKB)
assert parsed_to_wkt == 'MULTIPOINT (10.0 40.0, 40.0 30.0, 20.0 20.0, 30.0 10.0)'

parsed_to_abstract = wkb_to_abstract(WKB)
assert parsed_to_abstract == (
	'LEnd',
	('MultiPoint', 'XY'),
	4,
	('LEnd', ('Point', 'XY'), 10.0, 40.0),
	('LEnd', ('Point', 'XY'), 40.0, 30.0),
	('LEnd', ('Point', 'XY'), 20.0, 20.0),
	('LEnd', ('Point', 'XY'), 30.0, 10.0)
)

# the reverse operation is only implemented from GeoJSON at the moment:
encoded_to_wkb_from_geojson = geojson_to_wkb(parsed_to_geojson)
assert encoded_to_wkb_from_geojson == WKB
```

## Supported Geometry Types

Supports `POINT`, `LINESTRING`, `POLYGON`, `MULTIPOINT`, `MULTILINESTRING`, `MULTIPOLYGON`, and `GEOMETRYCOLLECTION`

Supports geometry with `XY`, `XYZ`, `XYM`, and `XYZM` dimensions

## Specification

This module is based on v1.2.1 of the **OpenGIS Implementation Standard for Geographic information - Simple feature access - Part 1: Common architecture**
(which can be found here https://www.ogc.org/standards/sfa).

## Alternate Approaches

This library is somewhat redundant because:

- MySQL, POSTGIS and SQLite (SpatiaLite extension) provide the following conversion functions:
    - `ST_AsGeoJSON()`
    - `ST_GeometryFromGeoJSON()`
    - `ST_AsWKT()`
    - `ST_GeometryFromText()`

- if you are using `geopandas`+`shapely` these libraries provide conversion to and from WKB (implemented with fast C/C++ libraries)

However this library has a limited use-case; when python is working on your system, but you can't get the confounded binaries for `geopandas` or `shapely` to compile, or if you don't care for the size of numpy and everything else that comes with a few innocent `pip/conda install` commands.

From making this script I learned that WKB is actually not a great spec...

- WKB stores a lot of redundant information by repeating the byte order and geometry type for every point.
- Only 8 byte double precision floats are permitted... seems overkill for some applications. Would be better it we could specify precision, or even use integer types.

## Planned Features?

- WKT => WKB
 
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "parse-wkb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "thehappycheese",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/5d/8a/97731d2666a9e7e4c94e7a0d4abdee3675c647cf11169c6644d55653f9fe/parse_wkb-1.0.0.tar.gz",
    "platform": null,
    "description": "# Pure Python WKB (Well Known Binary) Converter\n\n[![Test and Publish PyPi](https://github.com/thehappycheese/parse_wkb/actions/workflows/publish_to_pypi.yml/badge.svg)](https://github.com/thehappycheese/parse_wkb/actions/workflows/publish_to_pypi.yml)\n[![PyPI - Version](https://img.shields.io/pypi/v/parse-wkb.svg)](https://pypi.org/project/parse-wkb)\n\n- `wkb_to_geojson()` converts WKB geometry into GeoJSON\n- `wkb_to_wkt()` converts WKB geometry into WKT\n- `geojson_to_wkb()` converts GeoJSON into WKB\n- `wkb_to_abstract()` converts WKB into an abstract representation which closely resembles the binary format (for debugging purposes)\n\n```python\nfrom parse_wkb import (\n    wkb_to_abstract,\n    wkb_to_geojson,\n    wkb_to_wkt,\n    geojson_to_wkb\n)\n\nimport json\n\nWKB = b\"\\x01\\x04\\x00\\x00\\x00\\x04\\x00\\x00\\x00\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00$@\\x00\\x00\\x00\\x00\\x00\\x00D@\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00D@\\x00\\x00\\x00\\x00\\x00\\x00>@\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x004@\\x00\\x00\\x00\\x00\\x00\\x004@\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00>@\\x00\\x00\\x00\\x00\\x00\\x00$@\"\n\nparsed_to_geojson = wkb_to_geojson(WKB)\nassert json.dumps(parsed_to_geojson) == '{\"type\": \"MultiPoint\", \"coordinates\": [[10.0, 40.0], [40.0, 30.0], [20.0, 20.0], [30.0, 10.0]]}'\n\nparsed_to_wkt = wkb_to_wkt(WKB)\nassert parsed_to_wkt == 'MULTIPOINT (10.0 40.0, 40.0 30.0, 20.0 20.0, 30.0 10.0)'\n\nparsed_to_abstract = wkb_to_abstract(WKB)\nassert parsed_to_abstract == (\n\t'LEnd',\n\t('MultiPoint', 'XY'),\n\t4,\n\t('LEnd', ('Point', 'XY'), 10.0, 40.0),\n\t('LEnd', ('Point', 'XY'), 40.0, 30.0),\n\t('LEnd', ('Point', 'XY'), 20.0, 20.0),\n\t('LEnd', ('Point', 'XY'), 30.0, 10.0)\n)\n\n# the reverse operation is only implemented from GeoJSON at the moment:\nencoded_to_wkb_from_geojson = geojson_to_wkb(parsed_to_geojson)\nassert encoded_to_wkb_from_geojson == WKB\n```\n\n## Supported Geometry Types\n\nSupports `POINT`, `LINESTRING`, `POLYGON`, `MULTIPOINT`, `MULTILINESTRING`, `MULTIPOLYGON`, and `GEOMETRYCOLLECTION`\n\nSupports geometry with `XY`, `XYZ`, `XYM`, and `XYZM` dimensions\n\n## Specification\n\nThis module is based on v1.2.1 of the **OpenGIS Implementation Standard for Geographic information - Simple feature access - Part 1: Common architecture**\n(which can be found here https://www.ogc.org/standards/sfa).\n\n## Alternate Approaches\n\nThis library is somewhat redundant because:\n\n- MySQL, POSTGIS and SQLite (SpatiaLite extension) provide the following conversion functions:\n    - `ST_AsGeoJSON()`\n    - `ST_GeometryFromGeoJSON()`\n    - `ST_AsWKT()`\n    - `ST_GeometryFromText()`\n\n- if you are using `geopandas`+`shapely` these libraries provide conversion to and from WKB (implemented with fast C/C++ libraries)\n\nHowever this library has a limited use-case; when python is working on your system, but you can't get the confounded binaries for `geopandas` or `shapely` to compile, or if you don't care for the size of numpy and everything else that comes with a few innocent `pip/conda install` commands.\n\nFrom making this script I learned that WKB is actually not a great spec...\n\n- WKB stores a lot of redundant information by repeating the byte order and geometry type for every point.\n- Only 8 byte double precision floats are permitted... seems overkill for some applications. Would be better it we could specify precision, or even use integer types.\n\n## Planned Features?\n\n- WKT => WKB\n ",
    "bugtrack_url": null,
    "license": "",
    "summary": "Pure python library to parse WKB (Well Known Binary) GIS geospatial geometry format",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/thehappycheese/parse-wkb#readme",
        "Issues": "https://github.com/thehappycheese/parse-wkb/issues",
        "Source": "https://github.com/thehappycheese/parse-wkb"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f61a0d742151996c454d99b2fa38ed5eeecf67b213b0ebaa1ae88a3f32214a9c",
                "md5": "8081a1454019a79ab50a08aaaf435a92",
                "sha256": "421c8687dabd1156b2b288af274a9d574df685ee476d1cf8f4ba1fe0ac99a08c"
            },
            "downloads": -1,
            "filename": "parse_wkb-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8081a1454019a79ab50a08aaaf435a92",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9571,
            "upload_time": "2024-02-19T15:37:52",
            "upload_time_iso_8601": "2024-02-19T15:37:52.576935Z",
            "url": "https://files.pythonhosted.org/packages/f6/1a/0d742151996c454d99b2fa38ed5eeecf67b213b0ebaa1ae88a3f32214a9c/parse_wkb-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d8a97731d2666a9e7e4c94e7a0d4abdee3675c647cf11169c6644d55653f9fe",
                "md5": "8b14166e4f4781094fd4b1efa969c988",
                "sha256": "61995fbc5d6e49e08281e978754058690119ee2669ecd62dafe37b1d4e5fcca2"
            },
            "downloads": -1,
            "filename": "parse_wkb-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8b14166e4f4781094fd4b1efa969c988",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7836,
            "upload_time": "2024-02-19T15:37:59",
            "upload_time_iso_8601": "2024-02-19T15:37:59.562458Z",
            "url": "https://files.pythonhosted.org/packages/5d/8a/97731d2666a9e7e4c94e7a0d4abdee3675c647cf11169c6644d55653f9fe/parse_wkb-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-19 15:37:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thehappycheese",
    "github_project": "parse-wkb#readme",
    "github_not_found": true,
    "lcname": "parse-wkb"
}
        
Elapsed time: 0.38275s