您的位置:首页 > 理论基础 > 计算机网络

ArcGIS.Server.9.2.DotNet网络分析之最短路径分析

2008-09-25 17:06 537 查看
目的:

1.arcgis server9.2 ADF实现短路径分析,输入起点的名称和终点的名称然后分析出最短路径进行显示。

准备工作:

1.用ArcGis Server Manager或者ArcCatalog发布一个叫citys的Map Service,citys这个必须包含可以分析的网络数据集,关于网络数据集可以查网络上的资料这里不详细说了,发布的时候一定勾上Network Analysis这个选项,并且把这个Service启动起来。

完成后的效果图:

起点:<br />

2<input id="Text1" type="text" value="宁夏" /><br />

3终点:<br />

4<input id="Text2" type="text" value="安徽" /><br />

5<input id="Button1" type="button" value="查找最短路径" onclick="search()" />
4.切换到cs的代码视图,实现 ICallbackEventHandler接口,代码如下:
1public partial class FindPath : System.Web.UI.Page, ICallbackEventHandler

2<script>

2 function search()

3

15 function processCallbackError()

16 </script>
6.当点击按钮执行search()时,会把起点和终点的名称作为请求字符串像服务端的发起请求,切换到代码视图编写代码处理search()发起的请求,代码和说明如下:
1

16 private string RaiseCallbackEvent(string _callbackArg)

17

36 private void doFindPath(string name1,string name2)

37

125 public void ShowResults(NAServerSolverResults solverResults)

126

152 private void AddRoutesAndStops(NAServerRouteResults rResult)

153

212 //按名称查找点

213 private PointN QueryPoint(string name)

214 {

215 PointN point = new PointN();

216 IEnumerable func_enum = Map1.GetFunctionalities();

217 DataTable dt = null;

218 foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisfunctionality in func_enum)

219 {

220 if (gisfunctionality.Resource.Name == "citys")

221 {

222 bool supported = false;

223 ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = gisfunctionality.Resource;

224 supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

225

226 if (supported)

227 {

228 ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc=(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

229 string[] lids;

230 string[] lnames;

231 qfunc.GetQueryableLayers(null, out lids, out lnames);

232 ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();

233 spatialfilter.ReturnADFGeometries = false;

234 spatialfilter.MaxRecords = 1;

235 spatialfilter.WhereClause = "NAME LIKE '" + name + "'";

236 spatialfilter.Geometry = Map1.GetFullExtent();

237 dt = qfunc.Query(null, lids[3], spatialfilter);

238 }

239 }

240 }

241

242 DataRowCollection drs = dt.Rows;

243

244 int shpind = -1;

245 for (int i = 0; i < dt.Columns.Count; i++)

246 {

247 if (dt.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))

248 {

249 shpind = i;

250 break;

251 }

252 }

253 foreach (DataRow dr in drs)

254 {

255 ESRI.ArcGIS.ADF.Web.Geometry.Point geom = (ESRI.ArcGIS.ADF.Web.Geometry.Point)dr[shpind];

256 //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection points = geom.Points;

257 point.X = geom.X;

258 point.Y = geom.Y;

259

260 }

261 return point;

262 }
7.这样就可以测试查看效果了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: