Ejemplo n.º 1
0
        /// <summary>
        /// 使用AE的GP工具实现图层到图层的转换
        /// </summary>
        /// <param name="sourcePath">源数据路径,shape为全路径。数据库路径以mdb为例:C:\测试\test.mdb\zyxb</param>
        /// <param name="tarPath">源数据路径,shape为全路径。数据库路径以mdb为例:C:\测试\test.mdb\zyxbtar</param>
        /// <param name="msgLog"></param>
        /// <returns></returns>
        public static bool GPFeatToFeat(string sourcePath, string tarPath, string filter, out string msgLog)
        {
            msgLog = string.Empty;
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            string out_path = tarPath.Substring(0, tarPath.LastIndexOf('\\'));
            string out_name = tarPath.Substring(tarPath.LastIndexOf('\\') + 1);

            try
            {
                //复制到更新小班图层
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass pFeatToFeat1 = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();
                pFeatToFeat1.in_features  = sourcePath;
                pFeatToFeat1.out_path     = out_path; //zyxbFeatClass.Workspace.InnerObject as ESRI.ArcGIS.Geodatabase.IWorkspace;
                pFeatToFeat1.out_name     = out_name;
                pFeatToFeat1.where_clause = filter;
                gp.Execute(pFeatToFeat1, null);

                if (!ReturnErrMessage(gp, ref msgLog))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                ReturnErrMessage(gp, ref msgLog);
                return(false);
            }
            finally
            {
                gp = null;
            }
            msgLog = "";
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 要素类到要素类
        /// </summary>
        /// <param name="sourceFC"></param>
        /// <param name="tarDatabase"></param>
        /// <param name="filter"></param>
        /// <param name="msgLog"></param>
        /// <returns></returns>
        public static bool GPFeatToFeat(ESRI.ArcGIS.Geodatabase.IFeatureClass sourceFC, string tarDatabase, string filter, out string msgLog)
        {
            msgLog = string.Empty;

            try
            {
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass pFeatToFeat = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();
                pFeatToFeat.in_features  = sourceFC;
                pFeatToFeat.out_path     = tarDatabase;
                pFeatToFeat.out_name     = sourceFC.AliasName;
                pFeatToFeat.where_clause = filter;
                gp.Execute(pFeatToFeat, null);
                if (!ReturnErrMessage(gp, ref msgLog))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                ReturnErrMessage(gp, ref msgLog);
                return(false);
            }

            msgLog = "";
            return(true);
        }
Ejemplo n.º 3
0
        private void featureClassToFeatureClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass featureClassToFeatureClass = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();
            featureClassToFeatureClass.in_features = fileGDBPath + "\\" + sourceFCName;
            featureClassToFeatureClass.out_path    = sdePath;
            featureClassToFeatureClass.out_name    = targetFCName;

            ExecuteGP(featureClassToFeatureClass as IGPProcess);
        }
Ejemplo n.º 4
0
        public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a feature layer
                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source;

                // create a new feature class to feature class converter utility
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc
                    = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();

                // set the input feature layer
                fc2fc.in_features = featureLayer;

                // set the output path and Shapefile name
                fc2fc.out_path = shapePath;
                fc2fc.out_name = shapeName + ".shp";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                geoprocessor.TemporaryMapLayers = true;

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(fc2fc, null);

                // export a copy of the layer file definition too for upload/style at a later time
                ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile
                    = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile();
                saveToLayerFile.in_layer  = source;
                saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr";

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(saveToLayerFile, null);

                // remove reference to the tool and geoprocessor
                fc2fc        = null;
                geoprocessor = null;
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
        public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a feature layer
                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source;
                
                // create a new feature class to feature class converter utility
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc 
                    = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();

                // set the input feature layer
                fc2fc.in_features = featureLayer;

                // set the output path and Shapefile name
                fc2fc.out_path = shapePath;
                fc2fc.out_name = shapeName + ".shp";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                geoprocessor.TemporaryMapLayers = true;

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(fc2fc, null);

                // export a copy of the layer file definition too for upload/style at a later time
                ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile 
                    = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile();
                saveToLayerFile.in_layer = source;
                saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr";

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(saveToLayerFile, null);

                // remove reference to the tool and geoprocessor
                fc2fc = null;
                geoprocessor = null;
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }