ArcGIS Server 9.3 中線緩衝區查詢的實現

效果如上圖。步驟如下:

1、加入一個按鈕和一個textbox,併爲按鈕設置監聽事件。如下所示:

請輸入緩衝距離:<ext:TextField ID="txtBuffer" runat="server">

</ext:TextField><br /><br />&nbsp;&nbsp; &nbsp;&nbsp;                                                                             

<ext:Button ID="btnOperAreaAnaysis" Text="作業帶分析runat="server">                   

 <Listeners>

  <Click Handler="OperAreaAnaysis(#{txtBuffer});" />

</Listeners>

</ext:Button>

2、前臺的點擊按鈕的js相應函數如下:

//作業帶分析

function OperAreaAnaysis(txtField) {

    if (txtField.getValue() == "") {

        Ext.MessageBox.alert('提示', '爲了使用作業帶分析,請設置緩衝距離!', function() {

           txtField.focus(true, true);

      });

     return false;

    }

    var map = $find('Map1');

    //畫線函數

  map.getGeometry(ESRI.ADF.Graphics.ShapeType.Path, SelectPipe, null, 'red', 'blue', 'pointer', true);

}

 

function SelectPipe(inputGeometry) {

    var map = $find('Map1');

    var val = document.getElementById("txtBuffer").value;

   

    var ringCoords = inputGeometry.getPath(0).get_coordinates();

    var CoordsStr = "";

   for (var i = 0; i < ringCoords.length; i++) {

 

        CoordsStr += ringCoords[i][0] + ":" + ringCoords[i][1] + ";";

}

//callback函數

    SetCustomOperation(CoordsStr + "%" + "OAA" + "*" + val);

   

requestTableData();//獲取查詢後的結果並顯示在一個Ext的gridpanel中。

   

}

Default頁面加入 callback函數如下:

function SetCustomOperation(sVal)

 {

            var message ='';

            message +=',' + sVal;

            var context ='Map1'

            <%=sCallBack%>              

 } 

3、後臺的callback函數如下:

 

public partial class _Default : System.Web.UI.PageICallbackEventHandler

{ public string sCallBack = string.Empty;

private string smapstring = string.Empty;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

  {

sCallBack = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);

}

}

 

}

 

#region ICallbackEventHandler 成員

public string GetCallbackResult()

 {

        return smapstring;

 }

public void RaiseCallbackEvent(string eventArgument)

 {

if (eventArgument.Contains("OAA"))

    {

       string[] str1 = eventArgument.Split('*');

       string[] str2 = str1[0].Split(',');

       string[] str3=str2[1].Split('%');

        string str = str3[0];

        OperationAreaAnaysis(str,str1[1]);

      }

}

#endregion

4、接着是實現功能函數了。如下:

public void OperationAreaAnaysis(string str, string bufferdistance)

{

     DataSet DS = new DataSet();

     DataTable DT = new DataTable();

 try

  {

         object[] oa = new object[1];

         if (Map1.Scale > 8000)

         {

             oa[0] = "Ext.MessageBox.alert('提示','爲了使用作業帶分析,請把地圖比例尺放大到8000以內');";

             CallbackResult pRst = new CallbackResult(null, null, "javascript", oa);

             Map1.CallbackResults.Add(pRst);

             smapstring = Map1.CallbackResults.ToString();

             Session["Gridview1"] = null;

             return;

         }

ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal  MapRes = Map1.GetFunctionality("管線").Resource as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal;

 IServerContext sc = MapRes.ServerContextInfo.ServerContext;

         ESRI.ArcGIS.Geometry.IPointCollection pPointColl = (ESRI.ArcGIS.Geometry.IPointCollection)sc.CreateObject("esriGeometry.Polyline");

 

         string[] Coord1 = str.Split(';');

         for (int i = 0; i < Coord1.Length - 1; i++)

         {

             string[] Coord2 = Coord1[i].Split(':');

             ESRI.ArcGIS.Geometry.IPoint pPoint = (ESRI.ArcGIS.Geometry.IPoint)sc.CreateObject("esriGeometry.Point");

             pPoint.X = Convert.ToDouble(Coord2[0]);

             pPoint.Y = Convert.ToDouble(Coord2[1]);

             object missingVal = System.Reflection.Missing.Value;

             pPointColl.AddPoint(pPoint, ref missingVal, ref missingVal);

 

         }

 

         IGeometry pPolylineGeo = pPointColl as IGeometry;

         ESRI.ArcGIS.Geometry.IGeometry igeo = null;

         //緩衝需要的Geometry

         igeo = pPolylineGeo;

 

         double distance = Convert.ToDouble(bufferdistance) / 100000;//因爲本例的地圖座標是WGS84座標,所以轉換了下單位

         ESRI.ArcGIS.ADF.Web.Geometry.Polygon mappoly = null;

 

         ESRI.ArcGIS.Geometry.ITopologicalOperator topop = (ESRI.ArcGIS.Geometry.ITopologicalOperator)igeo;

         ESRI.ArcGIS.Geometry.IPolygon bufferPolygon;

         bufferPolygon = (ESRI.ArcGIS.Geometry.IPolygon)topop.Buffer(distance);

         // 定義valueobject的點

         ESRI.ArcGIS.ADF.ArcGISServer.PolygonN buffer_polyn;

         // 進行comobject到valueobject之間的轉換

         buffer_polyn = (ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)          ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufferPolygon, sc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN));

         //緩衝分析的結果

         mappoly = (ESRI.ArcGIS.ADF.Web.Geometry.Polygon) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(buffer_polyn);

 

         //把buffer結果範圍進行顯示

         ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;

         //查找ElementGraphicsLayer在Buffer中

       ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality Tempfunc = Map1.GetFunctionality("TempEle");

ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = Tempfunc.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource;

 

               foreach (System.Data.DataTable dt in gResource.Graphics.Tables)

              {

              if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)

              {

                glayer=(ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;

      break;

           }

              }

              //如果Buffer中沒有ElementGraphicsLayer就新增加一ElementGraphicsLayer

             if (glayer == null)

          {

             glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();

              gResource.Graphics.Tables.Add(glayer);

           }

       //清除ElementGraphicsLayer中的內容

           glayer.Clear();

 

              ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)mappoly;

//設置點顯示

      ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.BlueViolet);

       //設置透明度

        ge.Symbol.Transparency = 50;

         //添加到Buffer中進行顯示

          glayer.Add(ge);

         Map1.RefreshResource(gResource.Name);

         //緩衝區查詢

         ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunc = Map1.GetFunctionality("興趣點");

         ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisRes = gisfunc.Resource;

         bool supp = gisRes.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

     if (supp)

    {

             ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality QFunc;

             QFunc=(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisRes.CreateFunctionality( typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

             string[] lids;

             string[] lnames;

             QFunc.GetQueryableLayers(null, out lids, out lnames);

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

             spatialfilter.ReturnADFGeometries = true;

             spatialfilter.MaxRecords = 10000;

             spatialfilter.Geometry = mappoly;

             for (int i = 0; i < lids.Length; i++)

             {

                 DataTable datatable = QFunc.Query(gisfunc.Name, lids[i], spatialfilter);

                 datatable.TableName = gisRes.Name + "_" + lnames[i];

 

                 if (datatable.Rows.Count > 0)

                 {

                     if (DT.Rows.Count < 1)

                     {

                         DT = datatable.Clone();

                     }

                     DT.Merge(datatable);

                 }

             }

         }

         DS.Tables.Add(DT);

         Session["Gridview1"] = DS;

         smapstring = Map1.CallbackResults.ToString();

         if (DS.Tables[0].Rows.Count < 1)

             return;

     }

     catch (Exception ex)

     {

         SystemLog.WriteLog("作業帶分析出錯!", ex);

     }

     Session["Gridview1"] = DS;

 }

5、以上函數就已經獲得緩衝區查詢後的dataset了,自己將他展示出來就行了(本博客中有相關的內容,例如ArcgisServer9.3 中矩形選擇查詢的實現(利用callback機制)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章