版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版飲品店投資與經(jīng)營管理協(xié)議3篇
- 2025年度家居用品出口合同履行與環(huán)保材料應用協(xié)議4篇
- 二零二五年度房地產(chǎn)項目過橋資借款擔保合作協(xié)議3篇
- 2025年度智能路燈控制系統(tǒng)采購合同模板3篇
- 2025年度程序員入職及職業(yè)發(fā)展規(guī)劃合同3篇
- 二零二五年度藝術品展覽租賃合同書(含策展服務)3篇
- 2025年度知識產(chǎn)權代理個人勞務承包合同2篇
- 2025年度廚師長團隊建設與激勵機制合同3篇
- 二零二五年度政府項目宣傳拍攝合同3篇
- 二零二五年度農業(yè)產(chǎn)業(yè)化貸款借款合同4篇
- 火災安全教育觀后感
- 農村自建房屋安全協(xié)議書
- 快速康復在骨科護理中的應用
- 國民經(jīng)濟行業(yè)分類和代碼表(電子版)
- ICU患者外出檢查的護理
- 公司收購設備合同范例
- 廣東省潮州市2023-2024學年高二上學期語文期末考試試卷(含答案)
- 2024年光伏發(fā)電項目EPC總包合同
- 子女放棄房產(chǎn)繼承協(xié)議書
- 氧化還原反應配平專項訓練
- 試卷(完整版)python考試復習題庫復習知識點試卷試題
評論
0/150
提交評論