Skip to content
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

Closed
pablojimpas opened this issue Jun 6, 2022 · 3 comments
Closed

Add WKB encoding/decoding support #115

pablojimpas opened this issue Jun 6, 2022 · 3 comments
Labels
enhancement New feature or request 🌐 geobase Related to the code package "geobase" 🌐 geocore Related to the code package "geocore"

Comments

@pablojimpas
Copy link

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

@navispatial navispatial added enhancement New feature or request 🌐 geocore Related to the code package "geocore" 🌐 geobase Related to the code package "geobase" labels Jun 7, 2022
@navispatial
Copy link
Member

Yes, supporting WKB might be good fit to geobase and geocore libraries, as there is already some support for non-binary WKT format.

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...).

navispatial added a commit that referenced this issue Jul 31, 2022
@navispatial
Copy link
Member

Currently available on pre-release of geobase package since version 0.3.0-dev.1.

WKB Format accessible via WKB class.

Readme of the geobase package has an example:

  // 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...

@navispatial
Copy link
Member

Implemented in release published at 2022-08-21

See readme about WKB of the geobase package, latest version 0.3.0.

Easier to use sample, as also new model object classes for geometries and features landed on geobase:

  // 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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🌐 geobase Related to the code package "geobase" 🌐 geocore Related to the code package "geocore"
Projects
None yet
Development

No branches or pull requests

2 participants