var factory = new GeometryFactory(); var reader = new ShapeDataReader(options.InputFile); var mbr = reader.ShapefileBounds; var result = reader.ReadByMBRFilter(mbr); var coll = result.GetEnumerator(); var processed = 0;
while (coll.MoveNext()) { var feature = coll.Current; var attributevalue = (string)feature.Attributes[options.AttributeName];
Console.WriteLine($"Processing {attributevalue}");
using (var outputfile = File.CreateText(Path.Combine(options.OutputDirectory, attributevalue + ".geojson")))
using (var jsonwriter = new JsonTextWriter(outputfile)) { var serializer = new GeoJsonSerializer(); jsonwriter.Formatting = Formatting.Indented; serializer.Serialize(jsonwriter, feature); jsonwriter.Flush(); processed++; Console.WriteLine($"Processed {processed}"); } }
{ "Geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 71.8344427, -5.2482257 ], [ 71.8351122, -5.2488923 ], [ 71.8347861, -5.2492513 ], [ 71.8344427, -5.2482257 ] ] ], [ 72.430013765845871, -7.3384866 ] ] ] ] }, "Attributes": { "ISO": "IO", "COMMENTS": "", "ISO2": "IO", "PARENT_OSM": "**********", "OSMNAME": "British Indian Ocean Territory", "LASTCHANGE": "2014-11-05T12:06:26Z", "SUBREGION": "Southern Asia", "NAME": "British Indian Ocean Territory", "CODE": 1202.0, "FCLASS": "national", "OSM_ID": 1993867.0, "GID": 303642.0, "REGION": "Asia & the Pacific" }, "FeatureId": 86}
Yes that seems to have done it thank you! Only issue now is the ring order is not per the spec which at least suggests the right-hand rule for ordering. Is there something I can do on the geometry to re-order
var reader = new ShapeDataReader(options.InputFile, new OgcCompliantGeometryFactory());