public void TestMultiPolygon1()
        {
            string          wkt          = "MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))";
            GeometryFactory factory      = new GeometryFactory();
            IGeometry       geometry     = factory.CreateFromWKT(wkt);
            MultiPolygon    multiPolygon = (MultiPolygon)geometry;

            //Assertion.AssertEquals("Multilinestring 1",2,multiPolygon.NumGeometries);
            IGeometry  g     = multiPolygon.GetGeometryN(0);
            Polygon    poly1 = (Polygon)multiPolygon.GetGeometryN(0);
            LinearRing shell = poly1.Shell;
            LinearRing hole  = poly1.Holes[0];

            Assertion.AssertEquals("MPS 1", 10.0, shell.GetCoordinates()[0].X);
            Assertion.AssertEquals("MPS 2", 10.0, shell.GetCoordinates()[0].Y);
            Assertion.AssertEquals("MPS 3", 10.0, shell.GetCoordinates()[1].X);
            Assertion.AssertEquals("MPS 4", 20.0, shell.GetCoordinates()[1].Y);
            Assertion.AssertEquals("MPS 5", 20.0, shell.GetCoordinates()[2].Y);
            Assertion.AssertEquals("MPS 6", 20.0, shell.GetCoordinates()[2].Y);
            Assertion.AssertEquals("MPS 7", 20.0, shell.GetCoordinates()[3].X);
            Assertion.AssertEquals("MPS 8", 15.0, shell.GetCoordinates()[3].Y);
            Assertion.AssertEquals("MPS 9", 10.0, shell.GetCoordinates()[4].X);
            Assertion.AssertEquals("MPS 10", 10.0, shell.GetCoordinates()[4].Y);

            Assertion.AssertEquals("MPS 11", 50.0, hole.GetCoordinates()[0].X);
            Assertion.AssertEquals("MPS 12", 40.0, hole.GetCoordinates()[0].Y);
            Assertion.AssertEquals("MPS 13", 50.0, hole.GetCoordinates()[1].X);
            Assertion.AssertEquals("MPS 14", 50.0, hole.GetCoordinates()[1].Y);
            Assertion.AssertEquals("MPS 15", 60.0, hole.GetCoordinates()[2].X);
            Assertion.AssertEquals("MPS 16", 50.0, hole.GetCoordinates()[2].Y);
            Assertion.AssertEquals("MPS 17", 60.0, hole.GetCoordinates()[3].X);
            Assertion.AssertEquals("MPS 18", 40.0, hole.GetCoordinates()[3].Y);
            Assertion.AssertEquals("MPS 19", 50.0, hole.GetCoordinates()[4].X);
            Assertion.AssertEquals("MPS 20", 40.0, hole.GetCoordinates()[4].Y);

            string wkt2 = multiPolygon.ToText();

            Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2));
        }
示例#2
0
        public void shpWrite(string path)
        {
            fs.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));
            DataColumn col = new DataColumn("Project", typeof(string));

            col.MaxLength = 50;
            fs.DataTable.Columns.Add(col);
            fs.DataTable.Columns.Add(new DataColumn("Area", typeof(double)));
            IFeatureSet fsource = FeatureSet.Open(@"Sample\Sample.shp");

            fs.Projection = fsource.Projection;
            fsource.Close();
            int ID = 0;

            foreach (Geometries geometry in project.Geometries)
            {
                ID++;
                Polygon[] pgs = new Polygon[geometry.Polygons.Count];
                int       i   = 0;
                //foreach (Geometries geometry in project.Geometries) {

                foreach (GeoPolygon polygon in geometry.Polygons)
                {
                    List <Coordinate> vertices = new List <Coordinate>();

                    //polygon.Points.Reverse();

                    if (polygon.Circle > 1 && !polygon.GetDirection())
                    {
                        polygon.Points.Reverse();
                    }
                    else if (polygon.Circle == 1 && polygon.GetDirection())
                    {
                        polygon.Points.Reverse();
                    }

                    foreach (GeoPoint point in polygon.Points)
                    {
                        Coordinate vertice = new Coordinate();
                        vertice.X = point.X;
                        vertice.Y = point.Y;
                        vertices.Add(vertice);
                    }

                    Polygon geom = new Polygon(vertices);

                    pgs[i] = geom;

                    i++;
                }
                //}


                MultiPolygon geoms = new MultiPolygon(pgs);
                geoms.ToText();
                IFeature feature = fs.AddFeature(geoms);
                feature.DataRow.BeginEdit();
                feature.DataRow["ID"]      = ID;
                feature.DataRow["Project"] = project.Name;
                //feature.DataRow["Area"] = feature.Area();
                feature.DataRow.EndEdit();
            }
            //fs.Projection = ProjectionInfo.(@"F:\数据\2013SHP\DLTB.shp");
            //fs.ProjectionString = " +x_0=40500000 +y_0=0 +lat_0=0 +lon_0=120 +proj=tmerc +a=6378140 +b=6356755.28815753 +no_defs";

            fs.SaveAs(path, true);

            fs.Dispose();
            GeoRead gr = new GeoRead(path);

            gr.shpAreaReCalculate();
            //fs = FeatureSet.Open(path);
        }