Esempio n. 1
0
 private void btnExport_Click(object sender, EventArgs e)
 {
     GeoRead geo = new GeoRead(@"G:\TEST\青田县东源镇驮龙、平溪垦造耕地项目.shp");
     project = geo.shpRead();
 }
Esempio n. 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);
        }
Esempio n. 3
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);
        }