This project is read-only.

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.

/// <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 DuplicateShapes(object sender, EventArgs e)
    // Prompt the user for a shapefile.
    var layer = App.Map.AddFeatureLayer();

    // Open the featureset using standard shapefile format
    IFeatureSet fs = FeatureSet.Open(layer.DataSet.Filename);

    // 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 May 3, 2012 at 11:05 PM by mudnug, version 2