using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XXZX.OSMP.OneMap.Gis
{
public class GisDatasource
{
/// <summary>
/// 连接SDE方法1
/// </summary>
/// <param name="_pServerIP"></param>
/// <param name="_pInstance"></param>
/// <param name="_pDatabase"></param>
/// <param name="_pUser"></param>
/// <param name="_pPassword"></param>
/// <param name="_pVersion"></param>
/// <returns></returns>
public static IWorkspace GetSDEWorkspace(String _pServerIP, String _pInstance, String _pDatabase, String _pUser, String _pPassword, string _pVersion)
{
ESRI.ArcGIS.esriSystem.IPropertySet pPropertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
pPropertySet.SetProperty("SERVER", _pServerIP);
pPropertySet.SetProperty("INSTANCE", _pInstance);
pPropertySet.SetProperty("DATABASE", _pDatabase);
pPropertySet.SetProperty("USER", _pUser);
pPropertySet.SetProperty("PASSWORD", _pPassword);
//pPropertySet.SetProperty("VERSION", _pVersion);
// pPropertySet.SetProperty("AUTHENTICATION_MODE", "DBMS");
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();
IWorkspace pws = workspaceFactory.Open(pPropertySet, 0);
return pws;
}
/// <summary>
/// 连接SDE方法2
/// </summary>
/// <param name="_pServerIP"></param>
/// <param name="_pInstance"></param>
/// <param name="_pDatabase"></param>
/// <param name="_pUser"></param>
/// <param name="_pPassword"></param>
/// <param name="_pVersion"></param>
/// <returns></returns>2
public static IFeatureWorkspace GetSDEWorkspace2(String _pServerIP, String _pInstance, String _pDatabase, String _pUser, String _pPassword, string _pVersion)
{
SdeWorkspaceFactory sdeWorkspaceFactory = new SdeWorkspaceFactory();
PropertySet pset = new PropertySet();
pset.SetProperty("SERVER", _pServerIP);
pset.SetProperty("INSTANCE", _pInstance);
pset.SetProperty("DATABASE", _pDatabase);
pset.SetProperty("USER", _pUser);
pset.SetProperty("PASSWORD", _pPassword);
IWorkspaceFactory workspaceFactroy = new SdeWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactroy.Open(pset, 0);
return featureWorkspace;
}
/// <summary>
/// 连接gdb数据库
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static IWorkspace GetGDBWorkspace(String path)
{
//@"E:\workspace\layer\test.gdb"
IWorkspaceFactory pWsFac = new FileGDBWorkspaceFactoryClass();
IWorkspace pWs = pWsFac.OpenFromFile(path, 0);
return pWs;
}
/// <summary>
/// 打开shp文件
/// @"E:\workspace\layer\publish\publish1\publish1.shp"
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static IFeatureClass GetShpFeatureClass(string filePath)
{
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspaceFactoryLockControl pWorkspaceFactoryLockControl = pWorkspaceFactory as IWorkspaceFactoryLockControl;
if (pWorkspaceFactoryLockControl.SchemaLockingEnabled)
{
pWorkspaceFactoryLockControl.DisableSchemaLocking();
}
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(filePath));
return pFeatureClass;
}
}
}
ArcGIS Engine10.2部分封装方法一览
2020-03-03