看两种不同的图层查询方法
方法一:
1 m_agsBase.InitializeVar(CsMap);//m_agsBase为通用类,初始化地图控件,获取各个参数
2
3 IMap pMap = m_agsBase.GetMap();
4
6
7
8
9
10 IServerContext pSOC = m_agsBase.GetSOC();
11 IQueryFilter pQueryFilter = (IQueryFilter)pSOC.CreateObject("esriGeodatabase.QueryFilter");
12 pQueryFilter.WhereClause = txtQuery.Text;
13
14 //取地图上的第一个图层
15 ILayer pLayer = pMap.get_Layer(2);
16 IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
17 IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
18 IFeatureCursor pFeatCursor = pFeatCls.Search(pQueryFilter, false);
19
2
3 IMap pMap = m_agsBase.GetMap();
4
6
7
8
9
10 IServerContext pSOC = m_agsBase.GetSOC();
11 IQueryFilter pQueryFilter = (IQueryFilter)pSOC.CreateObject("esriGeodatabase.QueryFilter");
12 pQueryFilter.WhereClause = txtQuery.Text;
13
14 //取地图上的第一个图层
15 ILayer pLayer = pMap.get_Layer(2);
16 IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
17 IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
18 IFeatureCursor pFeatCursor = pFeatCls.Search(pQueryFilter, false);
19
上面的方法的思路总结:基于底层进行属性查找,一方面由SoC生成IQueryFilter,另一方面生成 IFeatureLayer,两者结合使用方法:search,返回结果为 IFeatureCursor
方法二:
IEnumerable func_enum = null;
func_enum = CsMap.GetFunctionalities();
System.Data.DataTable mytable;
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisfunctionality in func_enum)
{
//gisresource = gisfunctionality.Resource;
//对特定的数据库图层进行查询
if (gisfunctionality.Resource.Name == "CsMap")
{ bool supported = false;
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;
gisresource = gisfunctionality.Resource;
supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
//如果支持
if (supported)
{
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;
qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
string[] lids;
string[] lnames;
qfunc.GetQueryableLayers(null, out lids, out lnames);
//对查询进行过滤
mytable = qfunc.Query(null, lids[2], spatialfilter);
func_enum = CsMap.GetFunctionalities();
System.Data.DataTable mytable;
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisfunctionality in func_enum)
{
//gisresource = gisfunctionality.Resource;
//对特定的数据库图层进行查询
if (gisfunctionality.Resource.Name == "CsMap")
{ bool supported = false;
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;
gisresource = gisfunctionality.Resource;
supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
//如果支持
if (supported)
{
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;
qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
string[] lids;
string[] lnames;
qfunc.GetQueryableLayers(null, out lids, out lnames);
//对查询进行过滤
mytable = qfunc.Query(null, lids[2], spatialfilter);
方法二思路:1判断resource是否支持空间查询;
2生成queryfunction接口,并获取当前数据源中包含的可以查询的图层
3生成空间查询过滤器
4返回的结果为 Datatable
方法二是基于ADF框架的,而方法一是基于AO的
所有版权归小能所有哦!!!