Esempio n. 1
0
        /// <summary>
        /// Deletes the dataset.
        /// </summary>
        /// <param name="targetWorkspace">The target workspace.</param>
        /// <param name="sTargetName">Name of the s target.</param>
        /// <param name="type">The type.</param>
        public static void DeleteDataset(IWorkspace targetWorkspace, string sTargetName, esriDatasetType type = esriDatasetType.esriDTFeatureClass)
        {
            IDatasetName datasetName = null;

            switch (type)
            {
            case esriDatasetType.esriDTFeatureDataset:
                datasetName = new FeatureDatasetNameClass();
                break;

            case esriDatasetType.esriDTFeatureClass:
                datasetName = new FeatureClassNameClass();
                break;

            default:
                if (type == esriDatasetType.esriDTTable)
                {
                    datasetName = new TableNameClass();
                }
                break;
            }
            if (datasetName != null)
            {
                datasetName.Name          = sTargetName;
                datasetName.WorkspaceName = ((targetWorkspace as IDataset).FullName as IWorkspaceName);
                EngineAPI.DeleteDataset(targetWorkspace, datasetName);
            }
        }
Esempio n. 2
0
 private static void DeleteDataset(IWorkspace targetWorkspace, IDatasetName datasetName)
 {
     if (EngineAPI.IsNameExist(targetWorkspace, datasetName.Name, esriDatasetType.esriDTFeatureClass))
     {
         (targetWorkspace as IFeatureWorkspaceManage).DeleteByName(datasetName);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates SHPfile.
        /// </summary>
        /// <param name="sFilePath">The file path.</param>
        /// <param name="geometry">The geometry.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool CreateShpFile(string sFilePath, IGeometry geometry)
        {
            string            directoryName    = System.IO.Path.GetDirectoryName(sFilePath);
            IFeatureWorkspace featureWorkspace = EngineAPI.OpenWorkspace(directoryName, DataType.shp) as IFeatureWorkspace;
            bool result;

            if (featureWorkspace == null)
            {
                result = false;
            }
            else
            {
                try
                {
                    string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(sFilePath);
                    result = EngineAPI.CreateGeometryLayer(fileNameWithoutExtension, geometry, featureWorkspace, "");
                }
                finally
                {
                    if (featureWorkspace != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureWorkspace);
                    }
                }
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 打开矢量文件
        /// </summary>
        /// <param name="shpFile">文件名</param>
        /// <returns></returns>
        public static IFeatureClass OpenFeatureClass(string shpFile)
        {
            IFeatureClass result;
            FileInfo      fInfo = new FileInfo(shpFile);

            if (!System.IO.Directory.Exists(fInfo.DirectoryName))
            {
                result = null;
            }
            else
            {
                IWorkspace workspace = EngineAPI.OpenWorkspace(fInfo.DirectoryName, DataType.shp);
                if (workspace == null)
                {
                    result = null;
                }
                else
                {
                    IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
                    try
                    {
                        enumDatasetName.Reset();
                        IDatasetName datasetName;
                        while ((datasetName = enumDatasetName.Next()) != null)
                        {
                            if (fInfo.Name == (datasetName.Name + ".shp"))
                            {
                                break;
                            }
                        }
                        if (datasetName == null)
                        {
                            result = null;
                        }
                        else
                        {
                            IFeatureClass pFeatureClass = (datasetName as IName).Open() as IFeatureClass;
                            result = pFeatureClass;
                        }
                    }
                    finally
                    {
                        if (enumDatasetName != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(enumDatasetName);
                        }
                        if (workspace != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Opens the raster file.
        /// </summary>
        /// <param name="sPath">The s path.</param>
        /// <param name="sName">Name of the s.</param>
        /// <returns>IRasterDataset.</returns>
        public static IRasterDataset OpenRasterFile(string sPath, string sName)
        {
            IRasterDataset result;

            if (!System.IO.Directory.Exists(sPath))
            {
                result = null;
            }
            else
            {
                IWorkspace workspace = EngineAPI.OpenWorkspace(sPath, DataType.raster);
                if (workspace == null)
                {
                    result = null;
                }
                else
                {
                    IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTRasterDataset);
                    try
                    {
                        enumDatasetName.Reset();
                        IDatasetName datasetName;
                        while ((datasetName = enumDatasetName.Next()) != null)
                        {
                            if (string.Equals(datasetName.Name, sName, System.StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                        if (datasetName == null)
                        {
                            result = null;
                        }
                        else
                        {
                            IRasterDataset rasterDataset = (datasetName as IName).Open() as IRasterDataset;
                            result = rasterDataset;
                        }
                    }
                    finally
                    {
                        if (enumDatasetName != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(enumDatasetName);
                        }
                        if (workspace != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Create geometry layer
        /// </summary>
        /// <param name="sName">filename without extension</param>
        /// <param name="geometry">based geometry</param>
        /// <param name="featureWorkspace">featureWorkspace</param>
        /// <param name="sAlias"></param>
        /// <returns></returns>
        public static bool CreateGeometryLayer(string sName, List <ROIGeometry> geometryList, IFeatureWorkspace featureWorkspace, string sAlias = "")
        {
            bool result;

            try
            {
                IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();
                IFields          requiredFields  = objectClassDescription.RequiredFields;
                string           shapeFieldName  = (objectClassDescription as IFeatureClassDescription).ShapeFieldName;
                int              index           = requiredFields.FindField(shapeFieldName);
                IGeometryDef     geometryDef     = requiredFields.get_Field(index).GeometryDef;
                IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                geometryDefEdit.GeometryType_2     = geometryList[0].geometry.GeometryType;
                geometryDefEdit.SpatialReference_2 = geometryList[0].geometry.SpatialReference;
                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(sName, requiredFields, new UIDClass
                {
                    Value = "esriGeoDatabase.Feature"
                }, null, esriFeatureType.esriFTSimple, shapeFieldName, "");

                try
                {
                    foreach (ROIGeometry roi in geometryList)
                    {
                        IFeature feature = featureClass.CreateFeature();
                        feature.Shape = roi.geometry;
                        feature.Store();
                    }

                    if (!string.IsNullOrEmpty(sAlias))
                    {
                        EngineAPI.AlterDatasetAlias(featureClass, sAlias);
                    }
                }
                finally
                {
                    if (featureClass != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    }
                }
                result = true;
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Opens the GDB feature class.
        /// </summary>
        /// <param name="sFilePath">The s file path.</param>
        /// <param name="type">The type.</param>
        /// <param name="sFcName">Name of the s fc.</param>
        /// <returns>IFeatureClass.</returns>
        public static IFeatureClass OpenGDBFeatureClass(string sFilePath, DataType type, string sFcName)
        {
            IFeatureClass result;

            if (type == DataType.mdb && !System.IO.File.Exists(sFilePath))
            {
                result = null;
            }
            else if (type == DataType.gdb && !System.IO.Directory.Exists(sFilePath))
            {
                result = null;
            }
            else
            {
                IWorkspace workspace = EngineAPI.OpenWorkspace(sFilePath, type);
                if (workspace == null)
                {
                    result = null;
                }
                else
                {
                    try
                    {
                        result = (workspace as IFeatureWorkspace).OpenFeatureClass(sFcName);
                    }
                    catch
                    {
                        result = null;
                    }
                    finally
                    {
                        if (workspace != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace);
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// 打开栅格文件
        /// </summary>
        public static IRasterDataset OpenRasterFile(string inFile)
        {
            FileInfo fInfo = new FileInfo(inFile);

            return(EngineAPI.OpenRasterFile(fInfo.DirectoryName, fInfo.Name));
        }
Esempio n. 9
0
        /// <summary>
        /// Opens the cad feature class.
        /// </summary>
        /// <param name="sCadFilePath">The s cad file path.</param>
        /// <param name="sFcName">Name of the s fc.</param>
        /// <returns>IFeatureClass.</returns>
        public static IFeatureClass OpenCADFeatureClass(string sCadFilePath, string sFcName)
        {
            IFeatureClass result;

            if (!System.IO.File.Exists(sCadFilePath))
            {
                result = null;
            }
            else
            {
                IWorkspace workspace = EngineAPI.OpenWorkspace(System.IO.Path.GetDirectoryName(sCadFilePath), DataType.cad);
                if (workspace == null)
                {
                    result = null;
                }
                else
                {
                    string           fileName        = System.IO.Path.GetFileName(sCadFilePath);
                    IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
                    try
                    {
                        enumDatasetName.Reset();
                        IDatasetName datasetName = null;
                        IDatasetName datasetName2;
                        while ((datasetName2 = enumDatasetName.Next()) != null)
                        {
                            if (string.Equals(datasetName2.Name, fileName, System.StringComparison.OrdinalIgnoreCase))
                            {
                                IEnumDatasetName subsetNames = datasetName2.SubsetNames;
                                try
                                {
                                    subsetNames.Reset();
                                    while ((datasetName = subsetNames.Next()) != null)
                                    {
                                        if (string.Equals(datasetName.Name, sFcName, System.StringComparison.OrdinalIgnoreCase))
                                        {
                                            break;
                                        }
                                    }
                                }
                                finally
                                {
                                    if (subsetNames != null)
                                    {
                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(subsetNames);
                                    }
                                }
                                break;
                            }
                        }
                        if (datasetName == null)
                        {
                            result = null;
                        }
                        else
                        {
                            IFeatureClass featureClass = (datasetName as IName).Open() as IFeatureClass;
                            result = featureClass;
                        }
                    }
                    finally
                    {
                        if (enumDatasetName != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(enumDatasetName);
                        }
                        if (workspace != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace);
                        }
                    }
                }
            }
            return(result);
        }