Ejemplo n.º 1
0
        /// <summary>
        /// 空间擦除
        /// </summary>
        /// <param name="featureClassPath"></param>
        /// <param name="layerId"></param>
        /// <param name="outFsName"></param>
        /// <returns></returns>
        public static IFeatureClass spatialErase(string gdb, IFeatureClass features, int layerId)
        {
            IFeatureClass kzxFs = Utils.featureClsArray[layerId];

            string layer_name = kzxFs.AliasName;

            Geoprocessor gp    = new Geoprocessor();
            Erase        erase = new Erase();

            erase.in_features    = features;
            erase.erase_features = kzxFs;

            erase.out_feature_class = gdb + @"\results\" + layer_name + @"EraseResult";

            try
            {
                gp.AddOutputsToMap = false;
                gp.OverwriteOutput = true;
                gp.Execute(erase, null);

                gp.ResetEnvironments();
                IFeatureClass outFs = FeatureOperations.OpenFeatureClass(gdb, "results", layer_name + @"EraseResult");

                return(outFs);
            }
            catch (System.Exception ex)
            {
                string error = "";
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    error += gp.GetMessage(i);
                }
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建FeatureClasss文件
        /// </summary>
        /// <param name="_strFullPath">文件名</param>
        /// <param name="spatial_reference">空间参考</param>
        /// <returns></returns>
        public static IFeatureClass CreateFeatureClass(string _strFullPath, string spatial_reference)
        {
            int           index          = _strFullPath.LastIndexOf("\\");
            string        strShapeFolder = _strFullPath.Substring(0, index);
            string        strShapeFile   = _strFullPath.Substring(index + 1);
            DirectoryInfo di             = new DirectoryInfo(strShapeFolder);

            if (!di.Exists)
            {
                di.Create();
            }
            Geoprocessor gp = new Geoprocessor();

            ESRI.ArcGIS.DataManagementTools.CreateFeatureclass createFs = new ESRI.ArcGIS.DataManagementTools.CreateFeatureclass();
            createFs.geometry_type     = "POLYGON";
            createFs.out_name          = strShapeFile;
            createFs.out_path          = strShapeFolder;
            createFs.spatial_reference = spatial_reference;
            try
            {
                gp.AddOutputsToMap = false;
                gp.OverwriteOutput = true;
                gp.Execute(createFs, null);
            }
            catch
            {
                string error = "";
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    error += gp.GetMessage(i);
                }
            }
            gp.ResetEnvironments();

            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strShapeFolder, 0) as IFeatureWorkspace;
            IFeatureClass     pFeatureClass     = pFeatureWorkspace.OpenFeatureClass(strShapeFile);

            return(pFeatureClass);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 空间求交
        /// </summary>
        /// <param name="featureClassPath"></param>
        /// <param name="layerId"></param>
        /// <returns></returns>
        public static IFeatureClass spatialIntersect(string gdb, IFeatureClass features, int layerId)
        {
            IFeatureClass kzxFs = Utils.featureClsArray[layerId];

            string layer_name = kzxFs.AliasName;

            Geoprocessor gp        = new Geoprocessor();
            Intersect    intersect = new Intersect();

            string fs1 = gdb + @"\inputs\input";
            string fs2 = gdb + @"\kzx\" + layer_name;

            intersect.in_features       = fs1 + ";" + fs2;
            intersect.out_feature_class = gdb + @"\results\" + layer_name + @"IntersectResult";

            try
            {
                gp.AddOutputsToMap = false;
                gp.OverwriteOutput = true;
                gp.Execute(intersect, null);

                gp.ResetEnvironments();
                IFeatureClass outFs = FeatureOperations.OpenFeatureClass(gdb, "results", layer_name + @"IntersectResult");

                return(outFs);
            }
            catch (System.Exception ex)
            {
                string error = "";
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    error += gp.GetMessage(i);
                }
                return(null);
            }
        }
Ejemplo n.º 4
0
        void IDataManager.TnCreateFeatureLayer(string inFeature, string outLayer, string dieukien,out string out_featureClass)
        {
            //num++;
               Geoprocessor GP = new Geoprocessor();
               //MessageBox.Show(dieukien);
               // Intialize the MakeFeatureLayer tool
               //GP.SetEnvironmentValue("workspace", environment);
               MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer();

               //MessageBox.Show(inFeature);
               makefeaturelayer.in_features = _tempPath.TempFullPath + inFeature; //"C:/tayninh/temp/tempmdb.mdb/tntn_hem_buff_1";
               makefeaturelayer.out_layer = "outlayer";//"C:/tayninh/temp/tempmdb.mdb/ot";//this.Mem4DataManager.TempFullPath+"tn" + outLayer;
               runTool(GP, makefeaturelayer, null);

               SelectLayerByAttribute SelectByAttribute = new SelectLayerByAttribute();
               GP.ResetEnvironments();
               SelectByAttribute.in_layer_or_view = "outlayer";//"C:/tayninh/temp/tempmdb.mdb/ot"; //this.Mem4DataManager.TempFullPath + "tn" + outLayer;
               SelectByAttribute.selection_type = "NEW_SELECTION";
               SelectByAttribute.where_clause = dieukien;
               runTool(GP, SelectByAttribute, null);

               CopyFeatures copyFeatures = new CopyFeatures();

               copyFeatures.in_features = "outlayer";

               copyFeatures.out_feature_class = _tempPath.TempFullPath + "tn" + "cop";// + TnFeatureClassName.HEM_BUFFER_1M_CREATED_FROM_LAYER;

               // Set the output Coordinate System environment
               //GP.SetEnvironmentValue("outputCoordinateSystem",
               //@"C:\Program Files\ArcGIS\Coordinate Systems\Projected Coordinate Systems\UTM\Nad 1983\NAD 1983 UTM Zone 21N.prj");

               //runTool(GP, copyFeatures, null);
               GP.Execute(copyFeatures, null);
               out_featureClass = _tempPath.TempFullPath + "tn" + "cop";// + TnFeatureClassName.HEM_BUFFER_1M_CREATED_FROM_LAYER;
        }
Ejemplo n.º 5
0
        string IDataManager.TnCreateFeatureLayer(string inFeature, string outLayer, string dieukien)
        {
            //num++;
               Geoprocessor GP = new Geoprocessor();
               //MessageBox.Show(dieukien);
               // Intialize the MakeFeatureLayer tool
               //GP.SetEnvironmentValue("workspace", environment);
               MakeFeatureLayer makefeaturelayer = new MakeFeatureLayer();

               makefeaturelayer.in_features = inFeature;//this.Mem4DataManager.TempFullPath + inFeature;
               makefeaturelayer.out_layer =string.Format("{0}{1}",_tempPath.TempFullPath,outLayer);
               runTool(GP, makefeaturelayer, null);

               SelectLayerByAttribute SelectByAttribute = new SelectLayerByAttribute();
               GP.ResetEnvironments();
               SelectByAttribute.in_layer_or_view =string.Format("{0}{1}",_tempPath.TempFullPath,outLayer);
               SelectByAttribute.selection_type = "NEW_SELECTION";
               SelectByAttribute.where_clause = dieukien;
               runTool(GP, SelectByAttribute, null);

               CopyFeatures copyFeatures = new CopyFeatures();

               copyFeatures.in_features = outLayer;

               copyFeatures.out_feature_class = _tempPath.TempFullPath + "copiedFeature";

               // Set the output Coordinate System environment
               //GP.SetEnvironmentValue("outputCoordinateSystem",
               //@"C:\Program Files\ArcGIS\Coordinate Systems\Projected Coordinate Systems\UTM\Nad 1983\NAD 1983 UTM Zone 21N.prj");

               //runTool(GP, copyFeatures, null);
               GP.Execute(copyFeatures, null);
               return _tempPath.TempFullPath + "copiedFeature";
        }