/// <summary>
/// 创建access工作空间。
/// </summary>
/// <param name="fileName">mdb文件名称。</param>
/// <param name="fileDirectory">mdb文件所在目录的路径。</param>
/// <returns>新创建的Personal GDB的<see cref="T:ESRI.ArcGIS.Geodatabase.IWorkspaceName" />。</returns>
public static IWorkspaceName CreateAccessWorkspace(string fileName, string fileDirectory)
{
if (!Directory.Exists(fileDirectory))
{
throw new DirectoryNotFoundException(string.Format("目录'{0}'不存在", fileDirectory));
}
string path = Path.Combine(fileDirectory, fileName);
if (File.Exists(path))
{
throw new ArgumentException(string.Format("mdb文件'{0}'已经存在", fileName), "fileName");
}
Type typeFromProgID = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeFromProgID);
return workspaceFactory.Create(fileDirectory, fileName, null, 0);
}
/// <summary>
/// 创建access工作空间。
/// </summary>
/// <param name="mdbFilePath">mdb文件路径。</param>
/// <returns>新创建的Personal GDB的<see cref="T:ESRI.ArcGIS.Geodatabase.IWorkspaceName" />。</returns>
public static IWorkspaceName CreateAccessWorkspace(string mdbFilePath)
{
if (File.Exists(mdbFilePath))
{
throw new ArgumentException(string.Format("mdb文件'{0}'已经存在", mdbFilePath), "mdbFilePath");
}
string directoryName = Path.GetDirectoryName(mdbFilePath);
if (!Directory.Exists(directoryName))
{
throw new DirectoryNotFoundException(string.Format("目录'{0}'不存在", directoryName));
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(mdbFilePath);
Type typeFromProgID = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeFromProgID);
return workspaceFactory.Create(directoryName, fileNameWithoutExtension, null, 0);
}
/// <summary>
/// 创建File GDB工作空间。
/// </summary>
/// <param name="fileGDBName">file gdb名称。</param>
/// <param name="fileGDBDirectory">file gdb所在目录路径。</param>
/// <returns>如果<paramref name="fileGDBPath" />新创建的File GDB的<see cref="T:ESRI.ArcGIS.Geodatabase.IWorkspaceName" />。</returns>
public static IWorkspaceName CreateFileGDBWorkspace(string fileGDBName, string fileGDBDirectory)
{
if (!Directory.Exists(fileGDBDirectory))
{
throw new DirectoryNotFoundException(string.Format("目录'{0}'不存在", fileGDBDirectory));
}
string path = Path.Combine(fileGDBDirectory, fileGDBName);
if (File.Exists(path))
{
throw new ArgumentException(string.Format("file gdb '{0}'已经存在", fileGDBName), "fileGDBName");
}
Type typeFromProgID = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeFromProgID);
return workspaceFactory.Create(fileGDBDirectory, fileGDBName, null, 0);
}
/// <summary>
/// 创建File GDB工作空间。
/// </summary>
/// <param name="mdbFilePath">file gdb路径。</param>
/// <returns>如果<paramref name="fileGDBPath" />新创建的File GDB的<see cref="T:ESRI.ArcGIS.Geodatabase.IWorkspaceName" />。</returns>
public static IWorkspaceName CreateFileGDBWorkspace(string fileGDBPath)
{
if (Directory.Exists(fileGDBPath))
{
throw new ArgumentException(string.Format("file gdb '{0}'已经存在", fileGDBPath), "fileGdbPath");
}
string directoryName = Path.GetDirectoryName(fileGDBPath);
if (!Directory.Exists(directoryName))
{
throw new DirectoryNotFoundException(string.Format("目录'{0}'不存在", directoryName));
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileGDBPath);
Type typeFromProgID = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeFromProgID);
return workspaceFactory.Create(directoryName, fileNameWithoutExtension, null, 0);
}
/// <summary>
/// 创建shape file工作空间。
/// </summary>
/// <param name="shapefileDirectory">shape file文件所在目录的路径。</param>
/// <returns>如果<paramref name="shapefileDirectory" />新创建的shape file的<see cref="T:ESRI.ArcGIS.Geodatabase.IWorkspaceName" />。</returns>
public static IWorkspaceName CreateShapefileWorkspace(string shapefileDirectory)
{
string directoryName = Path.GetDirectoryName(shapefileDirectory);
if (!Directory.Exists(directoryName))
{
throw new DirectoryNotFoundException(string.Format("目录'{0}'不存在", shapefileDirectory));
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(shapefileDirectory);
Type typeFromProgID = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeFromProgID);
return workspaceFactory.Create(directoryName, fileNameWithoutExtension, null, 0);
}
创建mdb、gdb、shp文件,并返回IWorkspaceName
猜你喜欢
转载自blog.csdn.net/qq_30430463/article/details/111682105
今日推荐
周排行