FeatureSets from Well Known Binary

FeatureSets exist in two basic "Modes". In one mode, they are "indexed" which implies there is a single large vertex array and a series of "ShapeIndices" that let you cycle through those vertices. The second mode is to simply have multiple Features in a Feature list, and it becomes necessary to cycle through the coordinates of the geometries in order to do anything with the shapes. Opening a shapefile automatically opens it into the indexed mode, while creating a new shapefile automatically assumes that you want to work with the features list. For importing from WKB there are two strategies.


using System.Data;
using System.IO;
using System.Collections.Generic;
using MapWindow.Data;

/// <summary>
/// Testing for errors in X, Y coordinate positioning by saving using the 
/// Net Topology Suite version, while opening using the WkbFeatureReader.
/// </summary>
private void TestBinary(object sender, EventArgs e)
    // Dimension a new featureset
    FeatureSet fs = new FeatureSet();
    // Open the featureset using standard shapefile format

    // The output featureset to be created from wkb
    FeatureSet result = new FeatureSet(fs.FeatureType);

    // Store the WKB representation in a list of arrays, each shape has one array.
    List<byte[]> binaryShapes = new List<byte[]>();
    // This forces the creation of features, and uses the old WKB converter
    // which was the NTS implementation of the standard OGC WKB.
    foreach (IFeature feature in fs.Features)

    // Start by setting up a list of shapes
    List<Shape> shapes = new List<Shape>();

    // Loop through the binary arrays
    foreach (byte[] rawBytes in binaryShapes)
        // read each 
        MemoryStream ms = new MemoryStream(rawBytes);

    // As of the most recent source commit, this also works if it is false.
    result.IndexMode = true; 
    // Adds the shapes to the result in one pass, so that there is less array re-dimensioning
    // opens the result as a new layer on the map

Last edited Mar 9, 2010 at 5:55 PM by Shade1974, version 2


No comments yet.