阅读:2233回复:0
ArcIMS C# ADF开发讨论
<P>大家这方面的资料可以一起讨论哦!以下是偶提供的一个简单例子,arcgis server +adf+C#开发的</P>
<P align=left> 根据查询语句实现图层信息查询<p></p></P> <P align=left> 准备工作:<p></p></P> <P align=left> 1.Windows XP sp2中/英文版<BR> 2.Visual Studio 2005中/英文版<BR> 3.ArcGIS Server 9.2(我打上了sp2补丁),创建一个ArcGIS Server服务,Map Server属性中更改Pooling,使用池化连接方式,Progresses选择“In a seperate process for each instance(high isolation)”,我的服务为“World”<BR> 4.利用vs2005创建一个模板server应用--Web Mapping Application,并更改MapResourceManager属性<BR><v:shapetype><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path connecttype="rect" gradientshapeok="t" extrusionok="f"></v:path><lock aspectratio="t" v:ext="edit"></lock></v:shapetype><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><BR> 这样我们可以测试程序看是否能够正常运行,启动调试看到如下结果:<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><BR> 代码实现:<p></p></P> <P align=left> 我们要完成的工作是对图层属性信息的查询,首先在页面左侧添加一个新的panel,左侧的Tasks、Results等都是放置在panel之中,在这个新的panel中分别添加TreeViewPlus、TextBox、Button三个控件,TextBox输入查询条件,Button确定查询, TreeViewPlus显示结果,在设计试图中浏览效果如下:<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><BR> 双击“Query”Button,编写点击事件。<p></p></P> <P align=left><v:shape><v:imagedata></v:imagedata></v:shape> protected void cmdQuery_Click(object sender, EventArgs e)<BR><v:shape><v:imagedata></v:imagedata></v:shape><v:shape><v:imagedata></v:imagedata></v:shape> <v:shape> <v:imagedata></v:imagedata></v:shape>{<BR><v:shape><v:imagedata></v:imagedata></v:shape> Query(Map1.Extent);<BR><v:shape><v:imagedata></v:imagedata></v:shape> }<p></p></P> <P align=left> Query方法实现了对图层属性信息的查询。 <p></p></P> <P align=left><v:shape><v:imagedata></v:imagedata></v:shape>protected void Query(ESRI.ArcGIS.ADF.Web.Geometry.Geometry geometry)<BR><v:shape><v:imagedata></v:imagedata></v:shape><v:shape><v:imagedata></v:imagedata></v:shape> <v:shape> <v:imagedata></v:imagedata></v:shape>{<BR><v:shape><v:imagedata></v:imagedata></v:shape> IEnumerable func_enum = null;<BR><v:shape><v:imagedata></v:imagedata></v:shape> //获取当前map1控件中所有的functionality<BR><v:shape><v:imagedata></v:imagedata></v:shape> func_enum = Map1.GetFunctionalities();<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> System.Data.DataTable datatable;<BR><v:shape><v:imagedata></v:imagedata></v:shape> //对所有的functionality进行遍历<BR><v:shape><v:imagedata></v:imagedata></v:shape> foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunctionality in func_enum)<BR><v:shape><v:imagedata></v:imagedata></v:shape><v:shape><v:imagedata></v:imagedata></v:shape> <v:shape> <v:imagedata></v:imagedata></v:shape>{<BR><v:shape><v:imagedata></v:imagedata></v:shape> ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;<BR><v:shape><v:imagedata></v:imagedata></v:shape> //得到该functionality的resource<BR><v:shape><v:imagedata></v:imagedata></v:shape> gisresource = gisfunctionality.Resource;<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> //判断该resource是否支持IQueryFunctionality <BR><v:shape><v:imagedata></v:imagedata></v:shape> bool supported = false;<BR><v:shape><v:imagedata></v:imagedata></v:shape> supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> if (supported)<BR><v:shape><v:imagedata></v:imagedata></v:shape><v:shape><v:imagedata></v:imagedata></v:shape> <v:shape> <v:imagedata></v:imagedata></v:shape>{<BR><v:shape><v:imagedata></v:imagedata></v:shape> ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;<BR><v:shape><v:imagedata></v:imagedata></v:shape> qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> string[] lids;<BR><v:shape><v:imagedata></v:imagedata></v:shape> string[] lnames;<BR><v:shape><v:imagedata></v:imagedata></v:shape> //获得图层的layerId和layerName,GetQueryableLayers的重载方法可以指定图层类型<BR><v:shape><v:imagedata></v:imagedata></v:shape> qfunc.GetQueryableLayers(null, out lids, out lnames);<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();<BR><v:shape><v:imagedata></v:imagedata></v:shape> //设置过滤器的过滤条件,txtQuery就是panel中text box的ID<BR><v:shape><v:imagedata></v:imagedata></v:shape> spatialfilter.ReturnADFGeometries = false;<BR><v:shape><v:imagedata></v:imagedata></v:shape> spatialfilter.MaxRecords = 1000;<BR><v:shape><v:imagedata></v:imagedata></v:shape> spatialfilter.WhereClause = txtQuery.Text;<BR><v:shape><v:imagedata></v:imagedata></v:shape> spatialfilter.Geometry = geometry;<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> //对指定的图层进行查询,查询的结果保存为DataTable<BR><v:shape><v:imagedata></v:imagedata></v:shape> datatable = qfunc.Query(null, lids[0], spatialfilter);<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> TreeViewPlus1.Nodes.Clear();<BR><v:shape><v:imagedata></v:imagedata></v:shape> if (datatable != null)<BR><v:shape><v:imagedata></v:imagedata></v:shape><v:shape><v:imagedata></v:imagedata></v:shape> <v:shape> <v:imagedata></v:imagedata></v:shape>{<BR><v:shape><v:imagedata></v:imagedata></v:shape> System.Data.DataSet ds = new System.Data.DataSet();<BR><v:shape><v:imagedata></v:imagedata></v:shape> ds.Tables.Add(datatable);<BR><v:shape><v:imagedata></v:imagedata></v:shape> TreeViewPlus1.ShowClearAllButton = false;<BR><v:shape><v:imagedata></v:imagedata></v:shape> //将结果绑定到TreeViewPlus控件上<BR><v:shape><v:imagedata></v:imagedata></v:shape> TreeViewPlus1.BindToDataSet(ds);<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><v:shape><v:imagedata></v:imagedata></v:shape> TreeViewPlus1.Nodes[0].Expanded = true;<BR><v:shape><v:imagedata></v:imagedata></v:shape> }<BR><v:shape><v:imagedata></v:imagedata></v:shape> }<BR><v:shape><v:imagedata></v:imagedata></v:shape> }<BR><v:shape><v:imagedata></v:imagedata></v:shape> }<p></p></P> <P align=left> 运行程序,text box中输入“CNTRY_NAME LIKE 'A%'”,查询结果:<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><BR> 这样这个小程序就完成了,在server中实现了对图层属性信息的查询,现在我们需要进行更多的考虑:<BR><BR> 第一,考虑web控件、 functionality、datasource、resource、resourcemamager之间的关系,代码中多次对它们的关系进行了描述,用文档中的一幅图可以概括整个框架,这篇文章对此进行了阐述--《<a href="http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=6659;extra=page%3D1" target="_blank" >ArcGIS Server .Net Web ADF体系结构</A>》。<BR><v:shape><v:imagedata></v:imagedata></v:shape><BR><BR> 第二,程序中使用的mxd仅仅包含一个world图层,因此对图层进行遍历的过程中只需获得第一图层的ID,如果指定图层名,可以在lnames得到所需的图层进行查询。<p></p></P> <P align=left> 第三,程序实现的查询方式相当简单,在text box中输入原始的sql来完成where语句,只仅仅是一个测试,一般我们会屏蔽掉sql相关的关键字,提供多个text box或dropdownlist供用户选择进行字段查询。<p></p></P> <P align=left> 第四,如果查询信息量不大,返回结果数量不多,完全可以考虑ajax来完成页面请求,不论是速度还是用户体验都会得到提高。<p></p></P> <P align=left> 第五,通过程序可以看到,查询结果保存在一个datatable中,这极大的方便了server查询和.net的无缝连接,直接将结果和TreeViewPlus绑定,换成其他的visual studio控件也没问题。<p></p></P> <P align=left> 只要整个框架思路清晰了,查询功能的实现其实很简单,这也是途径2开发方式的一个例子,可以看出ArcGIS Server ADF给开发提供了很多便利,和ArcIMS相比开发难度相当,多看看文档和ADF OMD图可以让我们对ArcGIS Server ADF开发有更多的了解,记住,这只是server开发的起步。<p></p></P> |
|