ArcGIS Server 中栅格数据的查询。
本例是想获取dem数据中的某点的高程值。有两种方法可以实现,一种是用ADF 来实现,另外一种就是通过AO来实现了。
(其中对象pt就是要查询的点)
《1》ADF方法
//获取栅格地图资源
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality func = map.GetFunctionality("DEM");
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisRes = func.Resource;
bool supp = gisRes.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
DataTable[] dt = new DataTable[1];
int m_IdentifyTolerance = 2;
IdentifyOption m_idOption = IdentifyOption.VisibleLayers;
if (supp)
{
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisRes.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
if (qfunc != null && qfunc.Supports("identify"))
{
try
{
dt = qfunc.Identify(func.Name, pt, m_IdentifyTolerance, m_idOption, null);//dt即为查询结果
}
catch
{
}
}
}
string h=dt.tables[0][1].toString(); //h即为所要查询的高程值
《2》AO方法
//因地图资源与开发不在同一机器上,因而首先连接远程地图服务。
ESRI.ArcGIS.ADF.Identity id = new ESRI.ArcGIS.ADF.Identity();
id.UserName = "Administrator" ;
id.Password = "123456";
id.Domain = "gis2_trq";
string domainstr = "10.150.38.34";
ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsconn = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(domainstr, id);
agsconn.Connect();
if (!agsconn.IsConnected)
{
agsconn.Dispose();
return "";
}
ESRI.ArcGIS.Server.IServerObjectManager som = agsconn.ServerObjectManager;
string servertype = "MapServer";
//获取dem地图资源
string serverobjectname1 = "DEM_12503";
ESRI.ArcGIS.Server.IServerContext sc1 = som.CreateServerContext(serverobjectname1, servertype);
IMapServer pMapServer1 = sc1.ServerObject as IMapServer;
IMapServerObjects pMapServerObjs1 = pMapServer1 as IMapServerObjects;
IMap pMap1 = pMapServerObjs1.get_Map(pMapServer1.DefaultMapName);
IRasterLayer pRLayer = pMap1.get_Layer(0) as IRasterLayer;
//IRaster pRaster = pRLayer.Raster as IRaster;
ESRI.ArcGIS.Geometry.IPoint pt1 = sc1.CreateObject("esriGeometry.Point") as ESRI.ArcGIS.Geometry.IPoint;
pt1.X = pt.X;
pt1.Y = pt.Y;
IIdentify identify = (IIdentify)pRLayer;
IArray pIDArray = identify.Identify(pt1);
string HVal = String.Empty;
if (pIDArray != null)
{
IRasterIdentifyObj pRasObj = (IRasterIdentifyObj)pIDArray.get_Element(0);
HVal = pRasObj.Name;
}
HVal 就是所要的特定点的高程值(转换成double类型就好了)。