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.


Imports System.Data;
Imports System.IO;
Imports System.Collections.Generic;
Imports 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 Sub TestBinary(ByVal sender As Object, ByVal e As EventArgs)
    ' Dimension a new featureset
    Dim fs As New FeatureSet()
    ' Open the featureset using standard shapefile format
    ' The output featureset to be created from wkb
    Dim result As New FeatureSet(fs.FeatureType)
    ' Store the WKB representation in a list of arrays, each shape has one array.
    Dim binaryShapes As New List(Of Byte())()
    ' This forces the creation of features, and uses the old WKB converter
    ' which was the NTS implementation of the standard OGC WKB.
    For Each feature As IFeature In fs.Features
    ' Start by setting up a list of shapes
    Dim shapes As New List(Of Shape)()
    ' Loop through the binary arrays
    For Each rawBytes As Byte() In binaryShapes
        ' read each 
        Dim ms As 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
End Sub

Last edited Mar 15, 2010 at 4:38 PM by Shade1974, version 1


No comments yet.