Ejemplo n.º 1
0
        /// <summary>
        /// 复制图层
        /// </summary>
        /// <param name="inFile">输入文件</param>
        /// <param name="outFile">输出文件</param>
        /// <returns></returns>
        private static IFeatureLayer CopyLayer(string inFile, string outFile)
        {
            IFeatureClass featureClass = FeatureInfoClass.GetFeatureClass(inFile);
            IDataset      dataset      = featureClass as IDataset;

            if (dataset == null || !dataset.CanCopy())
            {
                return(null);
            }
            DatasetHelper.CopyDatasetAsFeatureLayer(dataset, outFile);
            return(FeatureInfoClass.GetFeatureLayer(outFile));
        }
Ejemplo n.º 2
0
        private void cmbLayerTrans_SelectedIndexChanged(object sender, EventArgs e)
        {
            //for (int i = 0; i < pMapControl.LayerCount;i++ )
            //{
            //   if (pMapControl.get_Layer(i).Name==cmbLayerTrans.Text)
            //   {
            pFeatureLayer = ClsGDBDataCommon.GetLayerFromName(pMapControl.Map, cmbLayerTrans.Text) as IFeatureLayer;
            IFeatureClass pFC       = pFeatureLayer.FeatureClass;
            IDataset      pDS       = pFC as IDataset;
            IWorkspace    pWS       = pDS.Workspace;
            string        filedir   = pWS.PathName;
            string        fdestname = "";

            if (radioButtonENUtoNED.Checked == true)
            {
                fdestname = pDS.BrowseName + "_NED";
            }
            if (radioButtonNEDtoENU.Checked == true)
            {
                fdestname = pDS.BrowseName + "_ENU";
            }
            txtLayerExp.Text    = filedir;
            txtFeatureName.Text = fdestname;


            //表示为gdb的feature,只能往gdb拷贝
            if (pDS.CanCopy() == false)
            {
                txtLayerExp.Enabled   = false;
                BtnWorkBrowse.Enabled = false;
            }
            else
            {
                txtLayerExp.Enabled   = true;
                BtnWorkBrowse.Enabled = true;
            }

            //string rasterfilepath = pFeatureLayer.ToString();//选中图层的文件路径
            //string rasterfiledir = System.IO.Path.GetDirectoryName(rasterfilepath);//文件位置
            //string rasterfilename=System.IO.Path.GetFileNameWithoutExtension(rasterfilepath);//文件名称
            //LayerExpName = rasterfiledir + "\\" + rasterfilename + "Trans.tif";
            //txtLayerExp.Text = LayerExpName;
            //break;
            //   }
            //}
        }
Ejemplo n.º 3
0
 public bool CanCopy()
 {
     try
     {
         IDataset dataset = this.Dataset;
         if (dataset != null)
         {
             bool flag = false;
             flag    = dataset.CanCopy();
             dataset = null;
             return(flag);
         }
     }
     catch
     {
     }
     return(false);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 数据集不能复制
 /// </summary>
 /// <param name="dataset"></param>
 /// <returns></returns>
 private static bool IsDatasetCannotCopy(IDataset dataset)
 {
     return(dataset == null || !dataset.CanCopy());
 }
Ejemplo n.º 5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //首先进行坐标系x,y变换
            //string fileExpTran;//进行x,y做表转换后输出的tiff文件存储路径,用这一文件在进行后期的Z转换
            //fileExpTran = System.IO.Path.GetDirectoryName(LayerExpName) +"\\"+ System.IO.Path.GetFileNameWithoutExtension(LayerExpName)+"XY.tif";
            //try
            //{
            //    if (NorthEastToEastNorth(pRasterLayer, LayerExpName))
            //    {
            //        RasterLayerClass rasterlayer = new RasterLayerClass();
            //        rasterlayer.CreateFromFilePath(LayerExpName);
            //        IRaster2 pRaster2 = rasterlayer.Raster as IRaster2;
            //        IRasterDataset2 pRasterDataset = pRaster2.RasterDataset as IRasterDataset2;
            //        ChangeRasterValue(pRasterDataset, -1, 0);
            //        pMapControl.AddLayer(rasterlayer as ILayer);
            //        this.Close();
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}

            try
            {
                IFeatureClass    pFC        = pFeatureLayer.FeatureClass;
                IDataset         pDS        = pFC as IDataset;
                IWorkspace       pWS        = pDS.Workspace;
                string           filedir    = pWS.PathName;
                string           fdestname  = System.IO.Path.GetFileNameWithoutExtension(txtFeatureName.Text);
                ClsGDBDataCommon CGD        = new ClsGDBDataCommon();
                IWorkspace       pTargetWS  = CGD.OpenFromShapefile(txtLayerExp.Text);
                IWorkspace2      workspace2 = pTargetWS as IWorkspace2;

                if (workspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, fdestname))
                {
                    MessageBox.Show("目标文件已存在!");
                    return;
                }
                //shape文件直接拷贝后再修改
                if (pDS.CanCopy() == true)
                {
                    pDS.Copy(txtFeatureName.Text, pTargetWS);
                    IFeatureWorkspace pFW = pTargetWS as IFeatureWorkspace;
                    pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text);
                    TransCoordiante(pFW as IWorkspace, pTargetFeatureClass);
                }
                //表示为gdb的feature,只能往gdb拷贝
                else
                {
                    // Create workspace name objects.
                    IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass();
                    IWorkspaceName targetWorkspaceName = new WorkspaceNameClass();
                    IName          targetName          = (IName)targetWorkspaceName;

                    // Set the workspace name properties.
                    sourceWorkspaceName.PathName = pWS.PathName;
                    sourceWorkspaceName.WorkspaceFactoryProgID =
                        "esriDataSourcesGDB.FileGDBWorkspaceFactory";
                    // targetWorkspaceName.PathName = @"PartialMontgomery.gdb";
                    targetWorkspaceName.PathName = txtLayerExp.Text;
                    targetWorkspaceName.WorkspaceFactoryProgID =
                        "esriDataSourcesGDB.FileGDBWorkspaceFactory";

                    //if (txtLayerExp.Text.Length>4 && txtLayerExp.Text.Substring(txtLayerExp.Text.Length-4,4) == ".gdb")
                    //{
                    //    targetWorkspaceName.WorkspaceFactoryProgID =
                    //      "esriDataSourcesGDB.FileGDBWorkspaceFactory";
                    //}
                    //else
                    //{
                    //    targetWorkspaceName.WorkspaceFactoryProgID =
                    //     "esriDataSourcesFile.ShapefileWorkspaceFactory";
                    //}

                    // Create a name object for the source feature class.
                    IFeatureClassName featureClassName = new FeatureClassNameClass();

                    // Set the featureClassName properties.
                    IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
                    sourceDatasetName.WorkspaceName = sourceWorkspaceName;
                    sourceDatasetName.Name          = pDS.BrowseName;
                    IName sourceName = (IName)sourceDatasetName;


                    // Create an enumerator for source datasets.
                    IEnumName     sourceEnumName     = new NamesEnumeratorClass();
                    IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

                    // Add the name object for the source class to the enumerator.
                    sourceEnumNameEdit.Add(sourceName);

                    // Create a GeoDBDataTransfer object and a null name mapping enumerator.
                    IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
                    IEnumNameMapping   enumNameMapping   = null;

                    // Use the data transfer object to create a name mapping enumerator.
                    Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName,
                                                                                   targetName, out enumNameMapping);
                    enumNameMapping.Reset();
                    //修改拷贝的文件名
                    INameMapping nameMapping = enumNameMapping.Next();
                    if ((nameMapping != null))
                    {
                        nameMapping.TargetName = txtFeatureName.Text;
                    }

                    // Check for conflicts.
                    //if (conflictsFound)
                    //{
                    //    // Iterate through each name mapping.
                    //    INameMapping nameMapping = null;
                    //    while ((nameMapping = enumNameMapping.Next()) != null)
                    //    {
                    //        // Resolve the mapping's conflict (if there is one).
                    //        if (nameMapping.NameConflicts)
                    //        {
                    //            nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
                    //        }

                    //        // See if the mapping's children have conflicts.
                    //        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                    //        if (childEnumNameMapping != null)
                    //        {
                    //            childEnumNameMapping.Reset();

                    //            // Iterate through each child mapping.
                    //            INameMapping childNameMapping = null;
                    //            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                    //            {
                    //                if (childNameMapping.NameConflicts)
                    //                {
                    //                    childNameMapping.TargetName = childNameMapping.GetSuggestedName
                    //                        (targetName);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}

                    // Start the transfer.
                    geoDBDataTransfer.Transfer(enumNameMapping, targetName);
                    IFeatureWorkspace pFW = CGD.OpenFromFileGDB(txtLayerExp.Text) as IFeatureWorkspace;
                    pTargetFeatureClass = pFW.OpenFeatureClass(txtFeatureName.Text);
                    TransCoordiante(pFW as IWorkspace, pTargetFeatureClass);
                }

                if (pTargetFeatureClass != null)
                {
                    //添加到图层中
                    IFeatureLayer featureLayer = new FeatureLayerClass();
                    featureLayer.FeatureClass = pTargetFeatureClass;
                    featureLayer.Name         = fdestname;
                    pMapControl.AddLayer(featureLayer as ILayer);
                    pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }