/// <summary> /// Testing for errors in X, Y coordinate positioning by saving using the Net Topology Suite version, while opening using the WkbFeatureReader. /// /// 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> public static FeatureSet DuplicateShapes(string shapefilePath) { // Open the featureset using standard shapefile format IFeatureSet fs = FeatureSet.Open(shapefilePath); // 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) { binaryShapes.Add(feature.ToBinary()); } // 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); shapes.Add(WkbFeatureReader.ReadShape(ms)); } // 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 result.AddShapes(shapes); return(result); }