開源SharpMap實例講解(三)剖析課件_第1頁
開源SharpMap實例講解(三)剖析課件_第2頁
開源SharpMap實例講解(三)剖析課件_第3頁
開源SharpMap實例講解(三)剖析課件_第4頁
開源SharpMap實例講解(三)剖析課件_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、開源SharpMap實例講解(三)要素查詢實例一:拉框查詢要素屬性實例二:點擊查詢要素屬性實例三:屬性查詢實例一:拉框查詢要素屬性代碼剖析1、單擊事件中調用代碼2、QueryMapByClick函數(shù)3、ExecuteIntersectionQuery函數(shù)41、單擊事件中調用代碼在 圖形的ImgMap_Click事件單擊,查詢要素屬性,所調用的代碼SharpMap.Geometries.Point ClickPnt = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y);SharpMap.Data.FeatureDataSet dsResu

2、lt; dsResult = QueryMapByClick(ClickPnt2, ClickPnt); if (dsResult.Tables.Count 0) SessionTHETABLE = dsResult; SessionTABLENUM = 1; string strNames = ;/如何獲取選中要素的屬性數(shù)據(jù) foreach (DataRow dr in dsResult.Tables0.Rows) strNames = strNames + dr0.ToString() + ,; .1、單擊事件中調用代碼./打開顯示站點屬性的頁面if (strNames.Length 0)

3、 strNames = strNames.Substring(0, strNames.Length - 1); string strURL = StationInfo.aspx?StationName= + strNames; string strPage = window.open( + strURL + ,站點屬性,height=450,width=470,status=no,toolbar=no,menubar=no,scrollbars=yes,location=no); Response.Write(strPage); 1、單擊事件中調用代碼 /將選中的要素產(chǎn)生一個新的圖層,高亮度顯

4、示 SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer(Selection); SharpMap.Data.Providers.GeometryProvider objGeoPrd = new SharpMap.Data.Providers.GeometryProvider(dsResult.Tables0); laySelected.DataSource = objGeoPrd; laySelected.Style.Symbol = new Bitmap(HttpContext.Current.S

5、erver.MapPath(App_dataStation2.bmp); laySelected.Style.SymbolScale = 0.8f; myMap.Layers.Add(laySelected);/刷新地圖 注意需重點掌握 QueryMapByClick函數(shù) 如何提取查詢結果信息 foreach (DataRow dr in dsResult.Tables0.Rows) 如何構建新的選擇集圖層,并設置符號,高亮度顯示2、QueryMapByClick函數(shù)private SharpMap.Data.FeatureDataSet QueryMapByClick(SharpMap.Ge

6、ometries.Point clickPoint1, SharpMap.Geometries.Point clickPoint2) SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); SharpMap.Geometries.BoundingBox objBounds; if (clickPoint1.X != clickPoint2.X) objBounds = new SharpMap.Geometries.BoundingBox(clickPoint1.X, clickPoint1.Y, clickP

7、oint2.X, clickPoint2.Y); else objBounds = new SharpMap.Geometries.BoundingBox(clickPoint1.X - 0.01, clickPoint1.Y - 0.01, clickPoint1.X + 0.01, clickPoint1.Y + 0.01); 2、QueryMapByClick函數(shù). /Execute click-query on first layer in layers collection SharpMap.Layers.VectorLayer objVLyr = myMap.Layers站點 as

8、 SharpMap.Layers.VectorLayer; if (!objVLyr.DataSource.IsOpen) objVLyr.DataSource.Open(); objVLyr.DataSource.ExecuteIntersectionQuery(objBounds, ds); if (ds.Tables.Count 0) /We have a result return ds; 3、ExecuteIntersectionQuery函數(shù) public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox b

9、ox, FeatureDataSet ds) FeatureDataTable fdt = new FeatureDataTable(); fdt = _features.Clone(); foreach (FeatureDataRow fdr in _features) if (fdr.Geometry.GetBoundingBox().Intersects(box) fdt.LoadDataRow(fdr.ItemArray, false); (fdt.Rowsfdt.Rows.Count - 1 as FeatureDataRow).Geometry = fdr.Geometry; ds

10、.Tables.Add(fdt); /private FeatureDataTable _features;ExecuteIntersectionQuery函數(shù)為sharpmap內部函數(shù),僅需了解實例二:點擊查詢要素屬性代碼剖析1、單擊事件中調用代碼2、QueryMapByClick函數(shù)3、ExecuteIntersectionQuery函數(shù) if (rblMapTools.SelectedValue = 3) SharpMap.Geometries.Point ClickPnt = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y);

11、SharpMap.Data.FeatureDataSet dsResult; dsResult = QueryMapByClick(ClickPnt); if (dsResult.Tables.Count 0) lblProperty.Text = ; foreach (System.Data.DataRow dr in dsResult.Tables0.Rows) lblProperty.Text += 屬性:; for (int i = 0; i dsResult.Tables0.Columns.Count; i+) lblProperty.Text += + dsResult.Table

12、s0.Columnsi.ColumnName; lblProperty.Text += + dri.ToString() + ; lblProperty.Text += ; lblProperty.Visible = true; 1、單擊事件中調用代碼在 圖形的ImgMap_Click事件單擊,查詢要素屬性,所調用的代碼。 for (int i = 0; i dsResult.Tables0.Columns.Count; i+) lblProperty.Text += + dsResult.Tables0.Columnsi.ColumnName; lblProperty.Text += + d

13、ri.ToString() + ; lblProperty.Text += ; lblProperty.Visible = true; 1、單擊事件中調用代碼在 圖形的ImgMap_Click事件單擊,查詢要素屬性,所調用的代碼2、QueryMapByClick函數(shù)private SharpMap.Data.FeatureDataSet QueryMapByClick(SharpMap.Geometries.Point clickPoint) SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); SharpM

14、ap.Layers.VectorLayer objVLyr = myMap.Layers0 as SharpMap.Layers.VectorLayer; if (!objVLyr.DataSource.IsOpen) objVLyr.DataSource.Open(); SharpMap.Geometries.BoundingBox objBounds = new SharpMap.Geometries.BoundingBox(clickPoint.X - 0.01, clickPoint.Y - 0.01, clickPoint.X + 0.01, clickPoint.Y + 0.01)

15、; objVLyr.DataSource.ExecuteIntersectionQuery(objBounds, ds); / objVLyr.DataSource.ExecuteIntersectionQuery(clickPoint, ds); if (ds.Tables.Count 0) /We have a result /Add clicked features to a new selection layer SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer(Selection); l

16、aySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(ds.Tables0); laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); myMap.Layers.Add(laySelected); return ds; 2、QueryMapByClick函數(shù)。 laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(

17、ds.Tables0); laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); myMap.Layers.Add(laySelected); return ds; 3、ExecuteIntersectionQuery函數(shù) 為sharpMap內部函數(shù),與上同實例三:屬性查詢依據(jù)查詢條件,查詢要素獲取該要素的屬性高亮度顯示該要素private void QueryFeatureByAttri(string sLayerName, string sFieldName, string s

18、FieldValue) SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); SharpMap.Layers.VectorLayer objVLyr = myMap.LayerssLayerName as SharpMap.Layers.VectorLayer; if (objVLyr != null) long count = objVLyr.DataSource.GetFeatureCount(); if (!objVLyr.DataSource.IsOpen) objVLyr.DataSource.Op

19、en(); SharpMap.Data.FeatureDataRow tempFeat; for (uint i = 0; i count; i+) tempFeat = objVLyr.DataSource.GetFeature(i); lblProperty.Text = tempFeatsFieldName.ToString();/判斷字段值是否相等,若相等,則查詢到該要素 if (tempFeatsFieldName.ToString() = sFieldValue) /高亮度顯示該要素 SharpMap.Data.FeatureDataTable tempTable = new Sh

20、arpMap.Data.FeatureDataTable(); tempTable = (tempFeat.Table as SharpMap.Data.FeatureDataTable).Clone(); tempTable.LoadDataRow(tempFeat.ItemArray, false); FeatureDataRow tempRow; tempRow = tempTable.RowstempTable.Rows.Count - 1 as FeatureDataRow; tempRow.Geometry = tempFeat.Geometry; SharpMap.Layers.

21、VectorLayer laySelected = new SharpMap.Layers.VectorLayer(Selection); laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(tempTable); laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); myMap.Layers.Add(laySelected); /顯示該要素的其他屬性 lblProperty.Text = ;

22、 lblProperty.Text += 屬性:; for (int j = 0; j tempFeat.Table.Columns.Count; j+) / lblProperty.Text += tempFeat.Table.Columnsi.ColumnName+ +tempFeati.ToString()+ lblProperty.Text += + tempFeat.Table.Columnsj.ColumnName; lblProperty.Text += + tempFeatj.ToString() + ; lblProperty.Visible = true; break; /

23、判斷字段值是否相等,若相等,則查詢到該要素 if (tempFeatsFieldName.ToString() = sFieldValue) /高亮度顯示該要素 SharpMap.Data.FeatureDataTable tempTable = new SharpMap.Data.FeatureDataTable(); tempTable = (tempFeat.Table as SharpMap.Data.FeatureDataTable).Clone(); tempTable.LoadDataRow(tempFeat.ItemArray, false); FeatureDataRow t

24、empRow; tempRow = tempTable.RowstempTable.Rows.Count - 1 as FeatureDataRow; tempRow.Geometry = tempFeat.Geometry; SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer(Selection); laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(tempTable); laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); myMap.Layers.Add(laySelected); /顯示該要素的其他屬性 lblProperty.Text = ; lblProperty.Text += 屬性:; for (int j = 0; j tempFeat.Table.Columns.Coun

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論