コード例 #1
0
 private bool method_6(IDatasetName idatasetName_0, bool bool_2)
 {
     try
     {
         IDataset dataset = (idatasetName_0 as IName).Open() as IDataset;
         if (dataset != null)
         {
             IWorkspaceName name = new WorkspaceNameClass
             {
                 PathName = this.string_0,
                 WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"
             };
             IWorkspace copyWorkspace = (name as IName).Open() as IWorkspace;
             dataset.Copy(idatasetName_0.Name, copyWorkspace);
             this.method_0(
                 (this.string_0 + @"\" + System.IO.Path.GetFileNameWithoutExtension(idatasetName_0.Name)) +
                 System.IO.Path.GetExtension(idatasetName_0.Name), true);
             return(true);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
     return(false);
 }
コード例 #2
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;

            try
            {
                if (bDataPath == true)
                {
                    fileName = txtOutputData.Text;
                    shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX   = fileName.LastIndexOf("\\");
                    endX     = fileName.Length;
                    shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    shpDir  = txtOutputData.Text;
                    shpFile = "х╚ох¤▀";
                }
                if (m_pRasterLyr != null)
                {
                    double        dInterval        = Convert.ToDouble(txtConInterval.Text);
                    double        dBaseLine        = Convert.ToDouble(txtBaseLine.Text);
                    object        objBaseLine      = dBaseLine;
                    ISurfaceOp    pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster       pInRaster        = m_pRasterLyr.Raster;
                    IFeatureClass pOutFClass       = pRasterSurfaceOp.Contour(pInRaster as IGeoDataset, dInterval, ref objBaseLine) as IFeatureClass;
                    //2. QI to IDataset
                    IDataset pFDS = pOutFClass as IDataset;
                    //3. Get a shapefile workspace
                    IWorkspaceFactory pSWF = new  ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFWS = pSWF.OpenFromFile(shpDir, 0) as IFeatureWorkspace;
                    //4. Copy contour output to a new shapefile
                    IWorkspace pWS = pFWS as IWorkspace;
                    if (pWS.Exists() == true)
                    {
                        Utility.DelFeatureFile(shpDir, shpFile + ".shp");
                    }
                    pFDS.Copy(shpFile, pFWS as IWorkspace);
                    IFeatureLayer pFeatLyr = new FeatureLayerClass();
                    pFeatLyr.FeatureClass = pOutFClass;
                    pFeatLyr.Name         = pOutFClass.AliasName;
                    pFeatLyr.Visible      = true;
                    pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: DatasetHelper.cs プロジェクト: Mengzuozhu/AeHelper
        /// <summary>
        /// 数据集复制为矢量图层
        /// </summary>
        /// <param name="dataset">数据集</param>
        /// <param name="outFile">输出文件</param>
        /// <returns></returns>
        public static ILayer CopyDatasetAsFeatureLayer(IDataset dataset, string outFile)
        {
            //数据为空或文件已存在,则返回null
            if (IsCannotCopy(dataset, outFile))
            {
                return(null);
            }

            string     fileName  = Path.GetFileNameWithoutExtension(outFile);
            IWorkspace workSpace = FeatureInfoClass.GetShapefileWorkspace(outFile);

            dataset.Copy(fileName, workSpace);
            return(FeatureInfoClass.GetFeatureLayer(outFile));
        }
コード例 #4
0
ファイル: DatasetHelper.cs プロジェクト: Mengzuozhu/AeHelper
        /// <summary>
        /// 复制数据集为栅格图层
        /// </summary>
        /// <param name="dataset">数据集</param>
        /// <param name="outFile">输出路径</param>
        /// <returns></returns>
        public static ILayer CopyDatasetAsRasterLayer(IDataset dataset, string outFile)
        {
            //不能复制
            if (IsCannotCopy(dataset, outFile))
            {
                return(null);
            }

            string       fileName        = Path.GetFileName(outFile);
            IWorkspace   workspace       = RasterDataInfoClass.GetRasterWorkspace(outFile);
            IDataset     rasterDataset   = dataset.Copy(fileName, workspace);
            IRasterLayer copyRasterLayer = new RasterLayerClass();

            copyRasterLayer.CreateFromDataset((IRasterDataset)rasterDataset);
            return(copyRasterLayer);
        }
コード例 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedItem.ToString() == "")
            {
                MessageBox.Show("请选择有效图层!");
                return;
            }
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("请输入相对高程下限!");
                return;
            }
            if (this.textBox2.Text == "")
            {
                MessageBox.Show("请输入相对高程上限!");
                return;
            }
            if (this.textBox1.Text != "")
            {
                if (!IsNumeric(this.textBox1.Text.ToString()))
                {
                    MessageBox.Show("请输入数字!");
                    return;
                }
            }
            if (this.textBox2.Text != "")
            {
                if (!IsNumeric(this.textBox1.Text.ToString()))
                {
                    MessageBox.Show("请输入数字!");
                    return;
                }
            }
            IWorkspaceFactory m_workspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace featureWorkspce    = m_workspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
            IFeatureClass     feaC = featureWorkspce.OpenFeatureClass("test");

            if (this.textBox1.Text == "0")
            {
                IFeatureCursor feaCur   = feaC.Search(null, true);
                IFeature       pFeature = feaCur.NextFeature();
                IArea          area     = pFeature.Shape as IArea;
                double         areaD    = Math.Abs(area.Area) / 3;
                this.label11.Text = areaD.ToString("#######") + "平方米";
                while (pFeature != null)
                {
                    pFeature.set_Value(2, this.m_tin.Extent.ZMin + Convert.ToDouble(this.textBox2.Text.ToString()));
                    pFeature.Store();
                    pFeature = feaCur.NextFeature();
                }
                IDataset          pDataset          = feaC as IDataset;
                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                IWorkspace        pWorkspace        = pFeatureWorkspace as IWorkspace;
                pDataset.Copy("test2", pFeatureWorkspace as IWorkspace);

                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                IFeatureClass fea2 = pFeatureWorkspace.OpenFeatureClass("test2");

                TinPolygonVolume ff = new TinPolygonVolume(m_tin, fea2, "HEIGHT");
                ff.reference_plane = "BELOW";
                Geoprocessor gp = new Geoprocessor();
                gp.Execute(ff, null);
                feaCur   = fea2.Search(null, true);
                pFeature = feaCur.NextFeature();

                while (pFeature != null)
                {
                    double volume = (double)pFeature.get_Value(3);
                    this.label7.Text = volume.ToString("#######") + "立方米";
                    double sarea = (double)pFeature.get_Value(4);
                    this.label8.Text = sarea.ToString("#######") + "平方米";
                    pFeature         = feaCur.NextFeature();
                }
            }
            else
            {
                IFeatureCursor feaCur   = feaC.Search(null, true);
                IFeature       pFeature = feaCur.NextFeature();
                IArea          area     = pFeature.Shape as IArea;
                double         areaD    = Math.Abs(area.Area) / 3;
                this.label11.Text = areaD.ToString("#######") + "平方米";
                while (pFeature != null)
                {
                    pFeature.set_Value(2, this.m_tin.Extent.ZMin + Convert.ToDouble(this.textBox2.Text.ToString()));
                    pFeature.Store();
                    pFeature = feaCur.NextFeature();
                }
                IDataset          pDataset          = feaC as IDataset;
                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                IWorkspace        pWorkspace        = pFeatureWorkspace as IWorkspace;
                pDataset.Copy("test2", pFeatureWorkspace as IWorkspace);

                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                IFeatureClass fea2 = pFeatureWorkspace.OpenFeatureClass("test2");

                TinPolygonVolume ff = new TinPolygonVolume(m_tin, fea2, "HEIGHT");
                ff.reference_plane = "BELOW";
                Geoprocessor gp = new Geoprocessor();
                gp.Execute(ff, null);
                feaCur   = fea2.Search(null, true);
                pFeature = feaCur.NextFeature();
                double volume1 = 0;
                double sarea1  = 0;
                while (pFeature != null)
                {
                    volume1 = (double)pFeature.get_Value(3);
                    //this.label7.Text = volume.ToString("#######") + "立方米";
                    sarea1 = (double)pFeature.get_Value(4);
                    //this.label8.Text = sarea.ToString("#######") + "平方米";
                    pFeature = feaCur.NextFeature();
                }

                feaCur   = feaC.Search(null, true);
                pFeature = feaCur.NextFeature();
                double volume2 = 0;
                double sarea2  = 0;
                while (pFeature != null)
                {
                    pFeature.set_Value(2, this.m_tin.Extent.ZMin + Convert.ToDouble(this.textBox1.Text.ToString()));
                    pFeature.Store();
                    pFeature = feaCur.NextFeature();
                }
                pDataset          = feaC as IDataset;
                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                pWorkspace        = pFeatureWorkspace as IWorkspace;
                pDataset.Copy("test3", pFeatureWorkspace as IWorkspace);

                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\tempSHP", 0) as IFeatureWorkspace;
                fea2 = pFeatureWorkspace.OpenFeatureClass("test3");

                ff = new TinPolygonVolume(m_tin, fea2, "HEIGHT");
                ff.reference_plane = "BELOW";
                gp = new Geoprocessor();
                gp.Execute(ff, null);
                feaCur   = fea2.Search(null, true);
                pFeature = feaCur.NextFeature();
                while (pFeature != null)
                {
                    volume2 = (double)pFeature.get_Value(3);
                    //this.label7.Text = volume.ToString("#######") + "立方米";
                    sarea2 = (double)pFeature.get_Value(4);
                    //this.label8.Text = sarea.ToString("#######") + "平方米";
                    pFeature = feaCur.NextFeature();
                }
                double volume = volume1 - volume2;
                double sarea  = sarea1 - sarea2;
                this.label7.Text = volume.ToString("#######") + "立方米";
                this.label8.Text = sarea.ToString("#######") + "平方米";
            }

            string[] files = System.IO.Directory.GetFiles(Application.StartupPath + "\\tempSHP");
            for (int i = 0; i < files.Length; i++)
            {
                System.IO.File.Delete(files[i]);
            }
        }
コード例 #6
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);
            }
        }