-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathQuerylayerTest.cs
66 lines (43 loc) · 2.04 KB
/
QuerylayerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
namespace EngineApplication
{
class QueryLayerTest
{
public IFeatureLayer OracleQueryLayer()
{
// 创建SqlWorkspaceFactory的对象
Type pFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory");
IWorkspaceFactory pWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(pFactoryType);
// 构造连接数据库的参数
IPropertySet pConnectionProps = new PropertySetClass();
pConnectionProps.SetProperty("dbclient", "Oracle11g");
pConnectionProps.SetProperty("serverinstance", "esri");
pConnectionProps.SetProperty("authentication_mode", "DBMS");
pConnectionProps.SetProperty("user", "scott");
pConnectionProps.SetProperty("password", "arcgis");
// 打开工作空间
IWorkspace workspace = pWorkspaceFactory.Open(pConnectionProps, 0);
ISqlWorkspace pSQLWorkspace = workspace as ISqlWorkspace;
//获取数据库中的所有表的名称
//IStringArray pStringArray= pSQLWorkspace.GetTables();
//for (int i = 0; i < pStringArray.Count; i++)
//{
// MessageBox.Show(pStringArray.get_Element(i));
//}
// 构造过滤条件 SELECT * FROM PointQueryLayer
IQueryDescription queryDescription = pSQLWorkspace.GetQueryDescription("SELECT * FROM TEST");
ITable pTable = pSQLWorkspace.OpenQueryClass("QueryLayerTest", queryDescription);
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pTable as IFeatureClass;
return pFeatureLayer;
}
}
}