zoukankan      html  css  js  c++  java
  • GIS二次开发之查询

          最近做B/S的项目,实在是有点忙,虽然感觉没什么难度,可是复杂的流程和巨大的工作量还是很无奈。上班时间根本没有时间再学习GIS,所以只好下班回去简单的学习一下。本来上讲中提到这讲会介绍MapTOCControl的右击菜单,哈哈,这个暂时没整理好,还是先看看GIS的查询吧。哈哈。

         老规矩,有图有真相,看看效果图。

         在GIS中查询分为:属性查询和空间查询,分别对应的接口是IQueryFilter和ISpatialFilter,当然后者继承了前者。

         在效果图中,用鼠标点击地图弹出BalloonCallOut的是利用空间查询实现的,在右边的查询条件中点击查询按钮实现的定位查询是属性查询。(哈哈,我想大家一看就知道了。)

         ①:属性查询代码:

    代码
           #region 属性查询
            
    private void btnSearchCity_Click(object sender, EventArgs e)
            {
                IActiveView pActiveView 
    = axMapMain.Map as IActiveView;
                IGraphicsContainer pGrahpicsContainer 
    = pActiveView as IGraphicsContainer;
                
    //先清除
                pGrahpicsContainer.DeleteAllElements();
                axMapMain.Extent 
    = pActiveView.FullExtent;
                axMapMain.ActiveView.ScreenDisplay.UpdateWindow();

                IFeatureLayer pFeatureLayer 
    = axMapMain.get_Layer(1as IFeatureLayer;
                
    if (null == pFeatureLayer) MessageBox.Show("选择图层不是Feature图层");
                IQueryFilter queryFilter 
    = new QueryFilterClass();
                queryFilter.WhereClause 
    = "Name='" + this.cbCity.Text + "'";
                IFeatureCursor featureCursor 
    = pFeatureLayer.Search(queryFilter, false);
                IFeature pFeature 
    = null;
                
    while ((pFeature = featureCursor.NextFeature()) != null)
                {
                    axMapMain.FlashShape(pFeature.Shape);
                }
            }
            
    #endregion

          ②:空间查询

    代码
           #region 几何查询
            
    private void axMapMain_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
            {
                IFeatureLayer pFeatureLayer 
    = axMapMain.get_Layer(1as IFeatureLayer;
                
    if (null == pFeatureLayer) return;

                IPoint point 
    = new PointClass();
                point.X 
    = e.mapX;
                point.Y 
    = e.mapY;

                ISpatialFilter spatialFilter 
    = new SpatialFilterClass();
                spatialFilter.Geometry 
    = point;
                spatialFilter.SpatialRel 
    = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureCursor featureCursor 
    = pFeatureLayer.Search(spatialFilter, true);
                IFeature pFeature 
    = featureCursor.NextFeature();

                
    while (pFeature != null)
                {
                    
    int index = pFeature.Table.FindField("Name");
                    
    string name = pFeature.Table.GetRow(pFeature.OID).get_Value(index).ToString();
                    AddBalloonCallout(e.mapX, e.mapY, name);
                    axMapMain.FlashShape(pFeature.Shape);
                    pFeature 
    = featureCursor.NextFeature();
                }

                System.Threading.Thread.Sleep(
    1000);
                IActiveView pActiveView 
    = axMapMain.Map as IActiveView;
                IGraphicsContainer pGrahpicsContainer 
    = pActiveView as IGraphicsContainer;
                pGrahpicsContainer.DeleteAllElements();
                axMapMain.ActiveView.ScreenDisplay.UpdateWindow();
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, 
    nullnull);
            }
            
    #endregion
  • 相关阅读:
    [PHP] php调用不存在的方法会自动调用 __call 魔术方法
    [PHP] laravel框架响应json信息中文禁止unicode编码
    [PHP] php中的trait代码复用方式
    [nginx] 解决:upstream timed out (110: Connection timed out) while reading response header from upstream
    [linux] Linux下格式化JSON程序-jq
    [git] Git Clean 清除 untrack 没有加入版本库的文件
    goland终端如何导入github上的包
    calico 配置 BGP Route Reflectors
    改善 Kubernetes 上的 JVM 预热问题
    golang开源对象存储
  • 原文地址:https://www.cnblogs.com/wangyong/p/1914100.html
Copyright © 2011-2022 走看看