public static void interBoundaryOuput(IList <IFeature> features) { IList <IGeometry> interBoundarys = new List <IGeometry>(); IList <IGeometry> interBoundary = new List <IGeometry>(); for (int i = 0; i < features.Count; i++) { // intPolygon intP = new Algorithm.Utils.Public.intPolygon(); //intP.getOutPolygons(features[i]); interBoundarys = intPolygon.getInterBoundaryPolygons(features[i]); foreach (var polygon in interBoundarys) { interBoundary.Add(polygon); } } string path1 = @"H:\test\结果\interBoundary1.shp"; var shapefileWriter = new ShapefileWriter(path1, ShapeGeometryType.LineString); foreach (var p in interBoundary) { shapefileWriter.Write(p); } string path2 = @"H:\test\结果\interBoundary1.dbf"; ShapefileWriter.WriteDummyDbf(path2, interBoundary.Count); shapefileWriter.Close(); Console.WriteLine("生成成功"); Console.ReadKey(); }
public static void minCircleOutput(IList <IFeature> features) { IList <ILineString> circles = new List <ILineString>(); for (int i = 0; i < features.Count; i++) { ILineString minLine = MinPoints.getMinVector(features[i]); ILineString circle = Circles.getCircle(minLine.Coordinates[0], minLine.Coordinates[1]); circles.Add(circle); } string path1 = @"H:\test\结果\MinCircle1.shp"; var shapefileWriter = new ShapefileWriter(path1, ShapeGeometryType.LineString); foreach (var circle in circles) { shapefileWriter.Write(circle); } string path2 = @"H:\test\结果\MinCircle1.dbf"; ShapefileWriter.WriteDummyDbf(path2, features.Count); shapefileWriter.Close(); Console.WriteLine("生成成功"); Console.ReadKey(); }
/// <summary> /// 线与外圆相交的多边形 /// </summary> /// <param name="features"></param> public static void outPolygonOuput(IList <IFeature> features) { IList <IGeometry> outPolygons = new List <IGeometry>(); IList <IGeometry> outPolygon = new List <IGeometry>(); for (int i = 0; i < features.Count; i++) { // intPolygon intP = new Algorithm.Utils.Public.intPolygon(); //intP.getOutPolygons(features[i]); outPolygons = intPolygon.getOutPolygons(features[i]); foreach (var polygon in outPolygons) { outPolygon.Add(polygon); } } string path1 = @"H:\test\结果\outpolygon实验测试1.shp"; var shapefileWriter = new ShapefileWriter(path1, ShapeGeometryType.Polygon); foreach (var p in outPolygon) { shapefileWriter.Write(p); } string path2 = @"H:\test\结果\outpolygon实验测试1.dbf"; ShapefileWriter.WriteDummyDbf(path2, outPolygon.Count); shapefileWriter.Close(); Console.WriteLine("生成成功"); Console.ReadKey(); }
public static void linesOuput(IList <IFeature> features) { IList <ILineString> lines = new List <ILineString>(); for (int i = 0; i < features.Count; i++) { foreach (var line in new AngleProperty(features[i]).Lines) { lines.Add(line); } } string path1 = @"H:\test\结果\lines实验.shp"; var shapefileWriter = new ShapefileWriter(path1, ShapeGeometryType.LineString); foreach (var line in lines) { shapefileWriter.Write(line); } string path2 = @"H:\test\结果\lines实验.dbf"; ShapefileWriter.WriteDummyDbf(path2, lines.Count); shapefileWriter.Close(); Console.WriteLine("生成成功"); Console.ReadKey(); }
public void TestRoundTrip(string filename) { // // can't round trip since I added the ToExternal/ ToInternal to the shapefile readers and writers. // PrecisionModel pm = new PrecisionModel(); GeometryFactory geometryFactory = new GeometryFactory(pm, -1); int differenceCount = 0; string testName = ""; string srcShpFilename = Global.GetUnitTestRootDirectory() + @"\IO\Shapefile\Testfiles\" + filename; string destShpFilename = Global.GetUnitTestRootDirectory() + @"\IO\Shapefile\Testfiles\testroundtrip" + filename; // do the round trip ShapefileReader shpReader = new ShapefileReader(srcShpFilename + ".shp", geometryFactory); GeometryCollection shapes = shpReader.ReadAll(); ShapefileWriter.Write(destShpFilename, shapes, geometryFactory); // perfom binary compare on the .shp testName = String.Format("Test round trip .shp - {0}", filename); differenceCount = Compare.BinaryCompare(srcShpFilename + ".shp", destShpFilename + ".shp"); Assertion.AssertEquals(testName, 0, differenceCount); // perfom binary compare on the .shx file testName = String.Format("Test round trip .shx - {0}", filename); differenceCount = Compare.BinaryCompare(srcShpFilename + ".shx", destShpFilename + ".shx"); Assertion.AssertEquals(testName, 0, differenceCount); }
// see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111 public void issue_111_polygonhandler_with_invalid_values() { var factory = GeometryFactory.Default; var points = new Coordinate[5]; points[0] = new Coordinate(0, 0); points[1] = new Coordinate(1, 0); points[2] = new Coordinate(1, 1); points[3] = new Coordinate(0, 1); points[4] = new Coordinate(0, 0); var poly = factory.CreatePolygon(points); var mpoly = factory.CreateMultiPolygon(new[] { poly }); IGeometry[] arr = new[] { mpoly, GeometryCollection.Empty }; var geometries = factory.CreateGeometryCollection(arr); var shapeType = Shapefile.GetShapeType(geometries); Assert.AreEqual(ShapeGeometryType.PolygonZM, shapeType); string tempPath = Path.GetTempFileName(); var sfw = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType); Assert.Throws <ArgumentException>(() => sfw.Write(geometries)); }
private void TestBugCimino() { try { string file = "countryCopy.shp"; if (!File.Exists(file)) { throw new FileNotFoundException(); } ShapefileReader sfr = new ShapefileReader(file); IGeometryCollection gc = sfr.ReadAll(); for (int i = 0; i < gc.NumGeometries; i++) { Console.WriteLine(i + " " + gc.Geometries[i].Envelope); } // IsValidOp.CheckShellsNotNested molto lento nell'analisi di J == 7 (Poligono con 11600 punti) var write = Path.Combine(Path.GetTempPath(), "copy_countryCopy"); var sfw = new ShapefileWriter(gc.Factory); sfw.Write(write, gc); Console.WriteLine("Write Complete!"); } catch (Exception ex) { throw ex; } }
public static void minLineOutput(IList <IFeature> features) { IList <ILineString> minLines = new List <ILineString>(); for (int i = 0; i < features.Count; i++) { minLines.Add(MinPoints.getMinVector(features[i])); } string path1 = @"H:\test\结果\MinLine1.shp"; var shapefileWriter = new ShapefileWriter(path1, ShapeGeometryType.LineString); foreach (var minLine in minLines) { shapefileWriter.Write(minLine); } string path2 = @"H:\test\结果\MinLine1.dbf"; ShapefileWriter.WriteDummyDbf(path2, features.Count); shapefileWriter.Close(); Console.WriteLine("生成成功"); Console.ReadKey(); }
// see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111 public void issue_111_multilinehandler_with_invalid_values() { var factory = GeometryFactory.Default; var points = new Coordinate[3]; points[0] = new CoordinateZ(0, 0); points[1] = new CoordinateZ(1, 0); points[2] = new CoordinateZ(1, 1); var ls = factory.CreateLineString(points); var mls = factory.CreateMultiLineString(new[] { ls }); Geometry[] arr = new[] { mls, GeometryCollection.Empty }; var geometries = factory.CreateGeometryCollection(arr); var shapeType = Shapefile.GetShapeType(geometries); Assert.AreEqual(ShapeGeometryType.LineStringZM, shapeType); string tempPath = Path.GetTempFileName(); var sfw = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType); Assert.Throws <ArgumentException>(() => sfw.Write(geometries)); }
private static void WriteShape(IGeometryCollection geometries, string shapepath) { if (File.Exists(shapepath)) { File.Delete(shapepath); } var sfw = new ShapefileWriter(geometries.Factory); sfw.Write(Path.GetFileNameWithoutExtension(shapepath), geometries); }
private void WriteShape(IGeometryCollection geometries, string shapepath) { if (File.Exists(shapepath)) { File.Delete(shapepath); } ShapefileWriter writer = new ShapefileWriter(); writer.Write(Path.GetFileNameWithoutExtension(shapepath), geometries); }
public void TestWriteSimpleShapeFile() { IPoint p1 = Factory.CreatePoint(new Coordinate(100, 100)); IPoint p2 = Factory.CreatePoint(new Coordinate(200, 200)); GeometryCollection coll = new GeometryCollection(new IGeometry[] { p1, p2, }); ShapefileWriter writer = new ShapefileWriter(Factory); writer.Write(@"c:\test_arcview", coll); ShapefileWriter.WriteDummyDbf(@"c:\test_arcview.dbf", 2); // Not read by ArcView!!! }
public void ReadWrite_PolyLineM() { var expected = Shapefiles.PolyLineMShpFile.FilePath; var actual = "written.shp"; var reader = new Shapefile(expected); using (var writer = new ShapefileWriter <IPolyLineShape <IPointM> >(actual)) { foreach (var iFeature in reader.Features) { writer.Write(iFeature.Shape); } } AssertIsContentEqual(expected, actual); }
// see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111 public void issue_111_pointhandler_with_invalid_values() { var factory = GeometryFactory.Default; var p = factory.CreatePoint(new Coordinate(0, 0)); IGeometry[] arr = { p, GeometryCollection.Empty }; var geometries = factory.CreateGeometryCollection(arr); var shapeType = Shapefile.GetShapeType(geometries); Assert.AreEqual(ShapeGeometryType.PointZM, shapeType); string tempPath = Path.GetTempFileName(); var sfw = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType); Assert.Throws <ArgumentException>(() => sfw.Write(geometries)); }
// see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111 public void issue_111_multipointhandler_with_invalid_values() { IGeometryFactory factory = GeometryFactory.Default; IPoint p = factory.CreatePoint(new Coordinate(0, 0)); IMultiPoint mp = factory.CreateMultiPoint(new[] { p }); IGeometry[] arr = new[] { mp, GeometryCollection.Empty }; IGeometryCollection geometries = factory.CreateGeometryCollection(arr); ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries); Assert.AreEqual(ShapeGeometryType.MultiPointZM, shapeType); string tempPath = Path.GetTempFileName(); ShapefileWriter sfw = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType); sfw.Write(geometries); }
public void TestReadingShapeFileAfvalbakken() { IGeometryFactory factory = GeometryFactory.Default; List <IPolygon> polys = new List <IPolygon>(); const int distance = 500; using (ShapefileDataReader reader = new ShapefileDataReader("afvalbakken", factory)) { int index = 0; while (reader.Read()) { IGeometry geom = reader.Geometry; Assert.IsNotNull(geom); Assert.IsTrue(geom.IsValid); Debug.WriteLine(String.Format("Geom {0}: {1}", index++, geom)); IGeometry buff = geom.Buffer(distance); Assert.IsNotNull(buff); polys.Add((IPolygon)geom); } } IMultiPolygon multiPolygon = factory.CreateMultiPolygon(polys.ToArray()); Assert.IsNotNull(multiPolygon); Assert.IsTrue(multiPolygon.IsValid); IMultiPolygon multiBuffer = (IMultiPolygon)multiPolygon.Buffer(distance); Assert.IsNotNull(multiBuffer); Assert.IsTrue(multiBuffer.IsValid); ShapefileWriter writer = new ShapefileWriter(factory); writer.Write(@"test_buffer", multiBuffer); ShapefileWriter.WriteDummyDbf(@"test_buffer.dbf", multiBuffer.NumGeometries); }
// see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111 public void issue_111_multilinehandler_with_invalid_values() { IGeometryFactory factory = GeometryFactory.Default; Coordinate[] points = new Coordinate[3]; points[0] = new Coordinate(0, 0); points[1] = new Coordinate(1, 0); points[2] = new Coordinate(1, 1); ILineString ls = factory.CreateLineString(points); IMultiLineString mls = factory.CreateMultiLineString(new[] { ls }); IGeometry[] arr = new[] { mls, GeometryCollection.Empty }; IGeometryCollection geometries = factory.CreateGeometryCollection(arr); ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries); Assert.AreEqual(ShapeGeometryType.LineStringZM, shapeType); string tempPath = Path.GetTempFileName(); ShapefileWriter sfw = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType); sfw.Write(geometries); }
private void WriteGridAbundances(Project currentProject, string shapefileName) { try { List <IPolygon> projectGrids = new List <IPolygon>(); General_queries projq = new General_queries(currentProject); foreach (Station st in currentProject.StationsList) { IPolygon grid = st.Grid; StationStats tempStationStats = new StationStats(st.Guid, st.StationID); foreach (StationStats stst in projq.AllStatsByStation) { if (stst.StationGUID == st.Guid) { tempStationStats = stst; grid.UserData = tempStationStats; } } projectGrids.Add(grid); } GeometryCollection gc = new GeometryCollection(projectGrids.ToArray()); //Open Writer ShapefileWriter shpWriter = new ShapefileWriter(); shpWriter.Write(shapefileName, gc); //Create Header & Columns for points DbaseFileHeader dbfHeader = new DbaseFileHeader(); dbfHeader.AddColumn("Station_ID", 'C', 20, 0); //One column for each species in project foreach (SpeciesStats spcst in projq.AllStatsBySpecies) { dbfHeader.AddColumn(spcst.SpeciesName, 'N', 20, 0); } dbfHeader.NumRecords = gc.Count; //DBF Writer DbaseFileWriter dbfWriter = new DbaseFileWriter(shapefileName + ".dbf"); dbfWriter.Write(dbfHeader); //Loop through Business Object to get Features foreach (IPolygon p in gc.Geometries) { StationStats data = (StationStats)p.UserData; ArrayList columnValues = new System.Collections.ArrayList(); //Add Values columnValues.Add(data.StationID); foreach (SpeciesStats s in data.SpeciesStats) { columnValues.Add(s.SpeciesPictures); } dbfWriter.Write(columnValues); } //Close File dbfWriter.Close(); } catch (Exception ex) { throw ex; } }