Giter VIP home page Giter VIP logo

nettopologysuite.io.tinywkb's Introduction

NetTopologySuite.IO.TinyWKB

An IO module for NTS to read and write geometries in the Tiny Well-Known-Binary format.

License GitHub Actions NuGet
License Build Status NuGet

Usage

Reading

Read a geometry like this. A TinyWkbReader is reusable.

/*
 bytes ... Array of bytes (byte[]) with twkb data from somewhere.
           You can also pass a Stream or a BinaryReader
 */
var geometryReader = new TinyWkbReader();
var geometry = geometryReader.Read(bytes);

Reading id-lists

For MULTI-geometries or GEOMETRYCOLLECTIONs the TWKB specification supports storing an identifier (System.Int64) for each contained geometry. There are 3 possible ways to obtain or handle these:

  • The identifier is stored in the Geometry.UserData object (default).
  • The caller subscribes to the TinyWkbReader.IdentifiersProvided event.
    The event's arguments provide access to the geometry that has been read along with the list of identifiers.
  • Call the TinyWkbReader.Read(byte[], out IList<long> idList) overload.
var geometryReader = new TinyWkbReader();
var geometry = geometryReader.Read(bytes, out var idList);

Writing

Write geometries like this. A TinyWkbWriter is reusable.

/*
 Create the writer. All constructor arguments are optional, the
 default values are displayed.
 */
var geometryWriter = new TinyWkbWriter(
    precisionXY: 7,    // Number of decimal places for x- and y-ordinate values.
    emitZ: true,       // Emit z-ordinate values if geometry has them
    precisionZ: 7,     // number of decimal digits for z-ordinates
    emitM: true,       // Emit m-ordinate values if geometry has them
    precisionM: 7,     // number of decimal digits for m-ordinates
    emitSize: false,   // Emit the size of the geometry definition 
    emitBoundingBox: true, 
                       // Emit the bounding box of the geometry for all dimensions 
    emitIdList: false  // Emit a list of identifiers, one for every geometry in a
                       //   MULTI-geometry or GEOMETRYCOLLECTION
);

/*
 geometry ... Geometry from somewhere.

 There are overloads for Write that take a Stream or
 BinaryWriter as argument.
 */
var bytes = geometryWriter.Write(geometry);

Writing id-lists

As noted in [Reading id-lists] TWKB has the concept of identifiers for MULTI-geometries or GEOMETRYCOLLECTIONs. Writing identifiers is supported analogous to the reading mechanism:

  • The identifier is taken from Geometry.UserData. If that does not work, a new System.Int64 value is created and used.
  • The caller subscribes to the TinyWkbWriter.IdentifiersRequested event, and fills adds the identifiers to the event's arguments.
  • Call one of the TinyWkbWriter.Write overloads that takes an IList<System.Int64> idList argument.

nettopologysuite.io.tinywkb's People

Contributors

airbreather avatar fobermaier avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

qq1530667

nettopologysuite.io.tinywkb's Issues

'idlist': give the caller a chance to tell us how to store the values.

Currently, TinyWkbWriter only supports two ways of writing out idlist values: either all included Geometry values must have UserData be convertible to long, or we'll just fall back to using auto-generated values fed from a static field.

TinyWkbReader automatically sets the UserData values to make a round-trip work in simple cases.

This has a few problems:

  1. If the GeometryFactory is a subclass that already sets something application-specific in the UserData, then TinyWkbReader will clobber what they did. An example might be if the factory translates the results to some other coordinate system and caches them in UserData.
  2. Related to the previous one, if the user does anything with UserData (other than, of course, exactly what we do), then they'll clobber this ID, perhaps unknowingly.
  3. This behavior is not very discoverable. Core NTS very rarely touches UserData except to copy the object reference around (by design).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.