Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        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();
        }
        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.WriteGeometryCollection(@"test_buffer", multiBuffer);
        }
Esempio n. 5
0
        // 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));
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
        }
        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;
            }
        }
Esempio n. 9
0
        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_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);
        }
Esempio n. 12
0
        public void TestWriteSimpleShapeFile()
        {
            var p1 = Factory.CreatePoint(new Coordinate(100, 100));
            var p2 = Factory.CreatePoint(new Coordinate(200, 200));

            var coll = new GeometryCollection(new IGeometry[] { p1, p2, });

            ShapefileWriter.WriteGeometryCollection(@"test_arcview", coll);

            // Not read by ArcView!!!
        }
Esempio n. 13
0
        private void WriteShape(IGeometryCollection geometries, string shapepath)
        {
            if (File.Exists(shapepath))
            {
                File.Delete(shapepath);
            }

            ShapefileWriter writer = new ShapefileWriter();

            writer.Write(Path.GetFileNameWithoutExtension(shapepath), geometries);
        }
Esempio n. 14
0
        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!!!
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        // 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);
        }
        // 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);
        }
Esempio n. 19
0
        private static void DoTest(IGeometryCollection geomsWrite, Ordinates ordinates, bool testGetOrdinate = true)
        {
            string fileName = string.Empty;

            try
            {
                fileName = Path.GetTempFileName();
                fileName = Path.ChangeExtension(fileName, "shp");
                ShapefileWriter.WriteGeometryCollection(fileName, geomsWrite);
                var reader    = new ShapefileReader(fileName, ShapeFileShapeFactory.FactoryRead);
                var geomsRead = reader.ReadAll();

                // This tests x- and y- values
                if (!geomsWrite.EqualsExact(geomsRead))
                {
                    Assert.AreEqual(geomsWrite.NumGeometries, geomsRead.NumGeometries);
                    //
                    // This akward test is necessary since EqualsTopologically throws currently exceptions
                    bool equal = true;
                    for (int i = 0; i < geomsRead.NumGeometries; i++)
                    {
                        var gw = geomsWrite.GetGeometryN(i);
                        var gr = geomsRead.GetGeometryN(i);
                        if (gw.IsEmpty && gr.IsEmpty)
                        {
                            if ((gw is ILineal && gr is ILineal) ||
                                (gw is IPolygonal && gr is IPolygonal))
                            {
                                // suppose these are equal
                            }
                            else
                            {
                                Console.WriteLine(string.Format("Geometries don't match at index {0}", i));
                                Console.WriteLine(string.Format("  written: {0}", gw.AsText()));
                                Console.WriteLine(string.Format("  read   : {0}", gr.AsText()));
                                equal = false;
                                Assert.IsTrue(equal, "Differenced found in geometries written and read!");
                            }
                        }
                        else if (!gw.EqualsExact(gr))
                        {
                            double hsm = new HausdorffSimilarityMeasure().Measure(gw, gr);
                            double asm = new AreaSimilarityMeasure().Measure(gw, gr);
                            double smc = SimilarityMeasureCombiner.Combine(hsm, asm);
                            if (!gw.EqualsNormalized(gr) || (1d - smc) > 1e-7)
                            {
                                Console.WriteLine(string.Format("Geometries don't match at index {0}", i));
                                Console.WriteLine(string.Format("  written: {0}", gw.AsText()));
                                Console.WriteLine(string.Format("  read   : {0}", gr.AsText()));
                                equal = false;
                                Assert.IsTrue(equal, "Differenced found in geometries written and read!");
                            }
                        }
                    }

                    //For polygons this has a tendency to fail, since the polygonhandler might rearrange the whole thing
                    if (testGetOrdinate)
                    {
                        if ((ordinates & Ordinates.Z) == Ordinates.Z)
                        {
                            double[] writeZ = geomsWrite.GetOrdinates(Ordinate.Z);
                            double[] readZ  = geomsRead.GetOrdinates(Ordinate.Z);
                            Assert.IsTrue(ArraysEqual(writeZ, readZ));
                        }

                        if ((ordinates & Ordinates.M) == Ordinates.M)
                        {
                            double[] writeM = geomsWrite.GetOrdinates(Ordinate.M);
                            double[] readM  = geomsRead.GetOrdinates(Ordinate.M);
                            Assert.IsTrue(ArraysEqual(writeM, readM));
                        }
                    }
                }

                // delete sample files
                File.Delete(fileName);
                File.Delete(Path.ChangeExtension(fileName, "shx"));
                File.Delete(Path.ChangeExtension(fileName, "dbf"));
            }
            catch (AssertionException ex)
            {
                Console.WriteLine("Failed test with {0}", ordinates);
                Console.WriteLine(ex.Message);
                Console.WriteLine("  Testfile '{0}' not deleted!", fileName);
                throw;
            }
        }
        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;
            }
        }