-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WKB encoding/decoding support #115
Comments
Yes, supporting WKB might be good fit to Other links: https://libgeos.org/specifications/wkb/ And wikipedia for WKT with some info about WKB too: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry Currently only Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon and GeometryCollection of geometry types supported (for WKT), maybe those would be also the first step for WKB (whenever to be implemented...). |
Currently available on pre-release of WKB Format accessible via WKB class. Readme of the // geometry binary format encoder for WKB
final encoder = WKB.geometry.encoder();
// write geometries (here only point) to content writer of the encoder
encoder.writer.point(
[10.123, 20.25, -30.95, -1.999],
type: Coords.xyzm,
);
// get encoded bytes (Uint8List) and Base64 encoded text (String)
final wkbBytes = encoder.toBytes();
final wkbBytesAsBase64 = encoder.toText();
// prints (point encoded to WKB binary data, formatted as Base64 text):
// AAAAC7lAJD752yLQ5UA0QAAAAAAAwD7zMzMzMzO///vnbItDlg==
print(wkbBytesAsBase64);
// next decode this WKB binary data and use WKT text format encoder as target
// geometry text format encoder for WKT
final wktEncoder = WKT.geometry.encoder();
// geometry binary format decoder for WKB
// (with content writer of the WKT encoder set as a target for decoding)
final decoder = WKB.geometry.decoder(wktEncoder.writer);
// now decode those WKB bytes created already at the start
decoder.decodeBytes(wkbBytes.buffer);
// finally print WKT text:
// POINT ZM(10.123 20.25 -30.95 -1.999)
print(wktEncoder.toText()); There has been quite large changes (geobase 0.2.1 => 0.3.0-dev.1) on text and binary data formats, encodings and content interfaces etc. Mostly not related to WKB, but many changes relates also to it. Still coming some new improvements and changes before prod release... |
Implemented in release published at 2022-08-21 See readme about WKB of the Easier to use sample, as also new model object classes for geometries and features landed on // create a Point object
final point = Point(XYZM(10.123, 20.25, -30.95, -1.999));
// get encoded bytes (Uint8List)
final wkbBytes = point.toBytes(format: WKB.geometry);
// at this point our WKB bytes could be sent to another system...
// then create a Point object, but now decoding it from WKB bytes
final pointDecoded = Point.decode(wkbBytes, format: WKB.geometry);
// finally print WKT text:
// POINT ZM(10.123 20.25 -30.95 -1.999)
print(pointDecoded.toText(format: WKT.geometry)); |
I've a use case for this and I haven't found an implementation in Dart, so I think it'll be a good addition to this package.
Don't know how hard could it be, here is a Go implementation that it's relatively small https://github.com/twpayne/go-geom/tree/master/encoding/wkb
The text was updated successfully, but these errors were encountered: