示例#1
0
文件: GisUtil.cs 项目: Leooonard/CGXM
 public static List<IPolygon> GetPolygonListFromPolylineList(string polylineListShpPath, string outputTempPath)
 {
     if (!File.Exists(polylineListShpPath))
     {
         return null;
     }
     if (File.Exists(outputTempPath))
     {
         GisUtil.DeleteShpFile(outputTempPath);
     }
     List<IPolygon> polygonList = new List<IPolygon>();
     Geoprocessor geoProcessor = new Geoprocessor();
     ESRI.ArcGIS.DataManagementTools.FeatureToPolygon featureToPolygonTool = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon();
     featureToPolygonTool.in_features = polylineListShpPath;
     featureToPolygonTool.out_feature_class = outputTempPath;
     geoProcessor.OverwriteOutput = true;
     geoProcessor.Execute(featureToPolygonTool, null);
     IFeatureClass featureClass = getFeatureClass(System.IO.Path.GetDirectoryName(outputTempPath), System.IO.Path.GetFileName(outputTempPath));
     for (int i = 0; i < featureClass.FeatureCount(null); i++)
     {
         IFeature feature = featureClass.GetFeature(i);
         IPolygon polygon = feature.ShapeCopy as IPolygon;
         polygonList.Add(polygon);
     }
     if (polygonList.Count == 0)
         return null;
     else
         return polygonList;
 }
示例#2
0
文件: GisUtil.cs 项目: Leooonard/CGXM
 public static void FeatureToPolygon(string inputPath, string outputPath)
 {
     Geoprocessor gp = new Geoprocessor();
     ESRI.ArcGIS.DataManagementTools.FeatureToPolygon feaToPoly = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon();
     //"C://work//城规项目//基础数据201401//data2//test1//test.shp"
     feaToPoly.in_features = inputPath;
     //"C://work//城规项目//基础数据201401//data2//test1//feature.shp"
     feaToPoly.out_feature_class = outputPath;
     gp.Execute(feaToPoly, null);
 }
示例#3
0
        private void TransForm(string Inputfile, string Output, string outputPath)
        {
            //构造Geoprocessor
            Geoprocessor gp   = new Geoprocessor();
            string       path = Path.GetDirectoryName(Output);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer step1 = new ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer();
                step1.table      = Inputfile + "\\Sheet1$";//textBox1.Text.ToString() + "\\xy.xls\\Sheet1$";
                step1.in_x_field = txbX.Text.ToString();
                step1.in_y_field = txbY.Text.ToString();
                RunTool(gp, step1, null);
                Console.WriteLine(Inputfile);
                //Console.WriteLine("MakeXYEventLayer:添加点数据");

                ESRI.ArcGIS.DataManagementTools.PointsToLine step2 = new ESRI.ArcGIS.DataManagementTools.PointsToLine();
                step2.Input_Features       = step1.out_layer;
                step2.Output_Feature_Class = outputPath + "\\temp.shp";//@"C:\Users\Yayu.Jiang\Desktop\output\temp.shp";
                RunTool(gp, step2, null);
                //Console.WriteLine("PointsToLine:点转线");

                ESRI.ArcGIS.DataManagementTools.FeatureToPolygon step3 = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon();
                step3.in_features       = step2.Output_Feature_Class;
                step3.out_feature_class = Output;//@"C:\Users\Yayu.Jiang\Desktop\output\xy.shp";
                RunTool(gp, step3, null);
                //Console.WriteLine("FeatureToPolygon:要素转面");

                ESRI.ArcGIS.DataManagementTools.CalculateField calculateField = new ESRI.ArcGIS.DataManagementTools.CalculateField();
                calculateField.in_table = Output;
                calculateField.field    = "ID";
                //calculateField.expression = "5";
                calculateField.expression      = Path.GetFileNameWithoutExtension(Output);
                calculateField.expression_type = "VB";
                RunTool(gp, calculateField, null);
                //Console.WriteLine("CalculateField:填充ID字段");

                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table     = Output;
                addField.field_name   = "YSBH";
                addField.field_type   = "TEXT";
                addField.field_length = 50;
                RunTool(gp, addField, null);
                //Console.WriteLine("AddField:添加字段YSBH");

                string[] foldName = Inputfile.Split('\\');
                calculateField.in_table        = addField.out_table;
                calculateField.field           = "YSBH";
                calculateField.expression_type = "VB";
                calculateField.expression      = "\"" + foldName[foldName.Length - 2] + "\"";
                //calculateField.expression = "\"aaa\"";
                RunTool(gp, calculateField, null);
                //Console.WriteLine("CalculateField:填充字段YSBH");

                #region 添加字段
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow  dr     = dt.Rows[i];
                    string[] fields = { dr["fields"].ToString(), dr["types"].ToString(), dr["length"].ToString() };
                    addField.field_name = fields[0];
                    addField.field_type = fields[1];
                    if (fields[1] == "TEXT")
                    {
                        addField.field_length = Convert.ToInt32(fields[2]);
                    }
                    RunTool(gp, addField, null);
                    //Console.WriteLine("AddField:添加字段" + dr["fields"].ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }