[求助]根据属性值定位(arcgis server + c#)
前台输入村庄名称,实现根据该属性值进行地图定位。“xzqhmc”为村庄属性的字段名,“期末地类图斑”为村庄属性输在的图层。为什么输入正确的村庄名,还是会显示找不到该村庄呢?主要代码如下求高手帮忙,小弟是新手,请多多指教。
public void RaiseCallbackEvent(string enventargs)
{
System.Collections.IEnumerable func_enum = null;
//获取当前map1控件中所有的functionality
func_enum = Map1.GetFunctionalities();
System.Data.DataTable datatable;
//对所有的functionality进行遍历
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunctionality in func_enum)
{
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;
//得到该functionality的resource
gisresource = gisfunctionality.Resource;
//判断该resource是否支持IQueryFunctionality
bool supported = false;
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;
//获得图层的layerId和layerName,GetQueryableLayers的重载方法可以指定图层类型
qfunc.GetQueryableLayers(null, out lids, out lnames);
int selindex = -1;
for (int i = 0; i < lids.Length; i++)
{
if (lnames[i] == "期末地类图斑")
{
//找到期末地类图斑图层的序号
selindex = i;
break;
}
}
if (selindex > -1)
{
//设置过滤器的过滤条件
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
spatialfilter.ReturnADFGeometries = true;
spatialfilter.MaxRecords = 100;
//Response.Write(enventargs);
spatialfilter.WhereClause = "xzqhmc like '%" + enventargs + "%'";
//spatialfilter.WhereClause = "name like '%" + enventargs + "%'";
//对指定的图层进行查询,查询的结果保存为
datatable = qfunc.Query(null, lids[selindex], spatialfilter);
if (datatable != null)
{
if (datatable.Rows.Count > 0)
{
for (int j = 0; j < datatable.Columns.Count; j++)
{
if (datatable.Columns[j].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
{
//Point pnt = (Point)datatable.Rows[0][j];
ESRI.ArcGIS.ADF.Web.Geometry.Point pnt = (ESRI.ArcGIS.ADF.Web.Geometry.Point)datatable.Rows[0][j];
Map1.CenterAt(pnt);
m_ADFCallbackFunctionString = Map1.CallbackResults.ToString();
return;
}
}
}
else
{
object[] ob = new object[1];
string sa = "alert('没有找到该村庄');";
ob[0] = sa;
ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult callbackresult = new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(null, null, "JavaScript", ob);
Map1.CallbackResults.Add(callbackresult);
m_ADFCallbackFunctionString = Map1.CallbackResults.ToString();
}
}
}
}
}
}
public string GetCallbackResult()
{
return m_ADFCallbackFunctionString;
}
[解决办法]
查询语句 spatialfilter.WhereClause = "xzqhmc like '%" + enventargs + "%'";中好像没有%吧。
我觉得应该是spatialfilter.WhereClause = "xzqhmc like '" + enventargs + "'";
[解决办法]
我想查询 %a%,不是想查询 a,不过还是要谢谢你。
[解决办法]
spatialfilter.WhereClause = "xzqhmc like \'%" + enventargs + "%\'";
[解决办法]
遇到和你一样的问题,最终发现是因为“期末地图类斑”是面状图层,但是ESRI.ArcGIS.ADF.Web.Geometry.Point pnt = (ESRI.ArcGIS.ADF.Web.Geometry.Point)datatable.Rows[0][j];
是对点而言的,当要查找村庄时可以换上点状图层,然后再进行查询就ok了,不知道可以否,我的问题是这样解决的,希望对你有用