版权声明:欢迎评论和转载,转载请注明来源。 https://blog.csdn.net/zy332719794/article/details/8966225
第一步:添加EngineGeoDB许可初始化
IAoInitialize aoInitialize = new AoInitialize();
aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
如果不加,则会报错“The application is not licensed to create or modify schema for this type of data”
第二步:连接sde数据库
var factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
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;
参数的具体设置,详细见
http://blog.csdn.net/zy332719794/article/details/8961390
这样我们就获取了工作空间,现在可以增加Dataset了
第三步:创建FeatureDateset
// 创建坐标系参考
ISpatialReferenceFactory sf = new SpatialReferenceEnvironment();
var geographicCoordinate = sf.CreateGeographicCoordinateSystem(
(int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
featureWorkspace.CreateFeatureDataset("NewDataset2", geographicCoordinate);
这样我们的一个名为“NewDataset2”的Dataset就创建好了。