开发者

Connection GeoDB to ASP.Net web application

开发者 https://www.devze.com 2023-03-28 03:55 出处:网络
I have a 开发者_StackOverflow社区GeoDB which has the extension .gdb. Is there any one who has tried to connect a GeoDB using C# with using ArcGIS SDK?The ArcObjects code below requires that you\'ve ch

I have a 开发者_StackOverflow社区GeoDB which has the extension .gdb. Is there any one who has tried to connect a GeoDB using C# with using ArcGIS SDK?


The ArcObjects code below requires that you've checked out a license. (How that is done depends on the ArcGIS version you've installed. For example, with ArcGIS 9.3.1, a call to IAoInitialize.Initialize was sufficient. In ArcGIS 10, you additionally need to bind to a product first via a call to ESRI.ArcGIS.RuntimeManager.BindLicense.)

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
…

IWorkspaceFactory wsFactory = new FileGDBWorkspaceFactory();  // (see P.S. below)
IWorkspace ws = wsFactory.OpenFromFile(@"\path\to\your\file.gdb", hWnd);

You can then open feature classes, tables, etc. in the File Geodatabase by casting ws to IFeatureWorkspace and using that interface's methods such as OpenTable, OpenFeatureClass, etc.


P.S.: ESRI actually recommends that workspace factories (being singleton objects) be created with Activator.CreateInstance instead of new:

Type wsFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory wsFactory = (IWorkspaceFactory)Activator.CreateInstance(wsFactoryType);
…

(I hadn't mentioned that earlier because it adds some complexity to a simple code example.)

0

精彩评论

暂无评论...
验证码 换一张
取 消