Pure Python WKB (Well Known Binary) Converter
wkb_to_geojson()converts WKB geometry into GeoJSONwkb_to_wkt()converts WKB geometry into WKTgeojson_to_wkb()converts GeoJSON into WKBwkb_to_abstract()converts WKB into an abstract representation which closely resembles the binary format (for debugging purposes)
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+shapelythese 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
Metadata
Release files for parse-wkb 1.0.0
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 |
|---|---|---|---|---|
| parse_wkb-1.0.0.tar.gz | 7.8 kB | Without provenance | Details for parse_wkb-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| parse_wkb-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for parse_wkb-1.0.0-py3-none-any.whl |
Total release size: 17.4 kB
Release files / parse_wkb-1.0.0.tar.gz
| Download URL | parse_wkb-1.0.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61995fbc5d6e49e08281e978754058690119ee2669ecd62dafe37b1d4e5fcca2
|
|
BLAKE2b-256 checksum How to use checksums |
5d8a97731d2666a9e7e4c94e7a0d4abdee3675c647cf11169c6644d55653f9fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.8
|
Release files / parse_wkb-1.0.0-py3-none-any.whl
| Download URL | parse_wkb-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
421c8687dabd1156b2b288af274a9d574df685ee476d1cf8f4ba1fe0ac99a08c
|
|
BLAKE2b-256 checksum How to use checksums |
f61a0d742151996c454d99b2fa38ed5eeecf67b213b0ebaa1ae88a3f32214a9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.8
|
Security for parse-wkb 1.0.0
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.