public static void Write(string shpFileName, IShapeCollection shapes, bool createDbf = false, bool overwrite = false) { if (shapes == null || shapes.Count < 1) { return; } var directory = System.IO.Path.GetDirectoryName(shpFileName); if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } ShapeType shapeType = shapes.First().Type; using (System.IO.MemoryStream featureWriter = new System.IO.MemoryStream()) { int recordNumber = 0; foreach (IShape item in shapes) { featureWriter.Write(WriteHeaderToByte(++recordNumber, item), 0, 2 * ShapeConstants.IntegerSize); featureWriter.Write(item.WriteContentsToByte(), 0, 2 * item.ContentLength); } using (System.IO.MemoryStream shpWriter = new System.IO.MemoryStream()) { int fileLength = (int)featureWriter.Length / 2 + 50; shpWriter.Write(WriteMainHeader(shapes, fileLength, shapeType), 0, 100); shpWriter.Write(featureWriter.ToArray(), 0, (int)featureWriter.Length); //var mode = overwrite ? System.IO.FileMode.Create : System.IO.FileMode.CreateNew; var mode = Shapefile.GetMode(shpFileName, overwrite); System.IO.FileStream stream = new System.IO.FileStream(shpFileName, mode); shpWriter.WriteTo(stream); stream.Close(); shpWriter.Close(); featureWriter.Close(); } } ShxWriter.Write(Shapefile.GetShxFileName(shpFileName), shapes, shapeType, overwrite); if (createDbf) { Dbf.DbfFile.Write(Shapefile.GetDbfFileName(shpFileName), shapes.Count, overwrite); } }
public static IShapeCollection Process(IShapeCollection shapes, double threshold, Func <EsriPoint[], double, EsriPoint[]> method) { if (shapes.First().Type == ShapeType.Polygon || shapes.First().Type == ShapeType.PolygonZ) { var result = new List <Polygon>(); foreach (ISimplePoints feature in shapes) { var temp = feature.Parts.Select((i, index) => method(feature.GetPart(index), threshold)).Where(i => i != null && i.Length > 3).ToArray(); if (temp == null || temp.Length == 0 || temp.Sum(i => i.Length) == 0) { continue; } result.Add(new Polygon(temp)); } return(new ShapeCollection <Polygon>(result)); } else if (shapes.First().Type == ShapeType.PolyLine || shapes.First().Type == ShapeType.PolyLineZ || shapes.First().Type == ShapeType.PolyLineM) { var result = new List <PolyLine>(); foreach (ISimplePoints feature in shapes) { var temp = feature.Parts.Select((i, index) => method(feature.GetPart(index), threshold)).Where(i => i != null && i.Length > 1).ToArray(); if (temp == null || temp.Length == 0 || temp.Sum(i => i.Length) == 0) { continue; } result.Add(new PolyLine(temp)); } return(new ShapeCollection <PolyLine>(result)); } else { throw new NotImplementedException(); } }