第一步:添加EngineGeoDB许可初始化
IAoInitialize aoInitialize = new AoInitialize();如果不加,则会报错“The application is not licensed to create or modify schema for this type of data”
aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
第二步:连接sde数据库
var factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");参数的具体设置,详细见 http://blog.csdn.net/zy332719794/article/details/8961390
var workspaceFactory = (SdeWorkspaceFactory) Activator.CreateInstance(factoryType);
IPropertySet propertySet = new PropertySet();
propertySet.SetProperty("Server", "192.168.1.188");
propertySet.SetProperty("Instance", "esri_sde");
propertySet.SetProperty("User", "sde");
propertySet.SetProperty("Password", "sde");
propertySet.SetProperty("Database", "sdedb");
propertySet.SetProperty("version", "sde.default");
IWorkspace workspace = workspaceFactory.Open(propertySet, 0);
var featureWorkspace = (IFeatureWorkspace) workspace;
这样我们就获取了工作空间,现在可以增加Dataset了
第三步:创建FeatureDateset
// 创建坐标系参考这样我们的一个名为“NewDataset2”的Dataset就创建好了。
ISpatialReferenceFactory sf = new SpatialReferenceEnvironment();
var geographicCoordinate = sf.CreateGeographicCoordinateSystem(
(int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
featureWorkspace.CreateFeatureDataset("NewDataset2", geographicCoordinate);