C#举办MapX二遍开发之地图搜索

在GIS中,地方统一标准可能道路等音讯寻找是一项很重要的效应,类似于大家寻找数据库记录那样,需求模糊进行匹配,一般的话,找到须求的地方统一标准或许道路等地图元素后,双击能够固定到地图的具体地方,并推广地图,类似于GoogleMap的Fly to效能。

正文先介绍MapX怎样在地形图中检索所须要的地图成分。

鉴于地图的消息是安分守纪层来储存的,所以我们寻找音信的时候,也是依照一稀罕来展开搜索,由于MapInfo的地图一般有好多层,每层进行遍历会相比耗时,所以一般的规范系统,都只是事关一部分层,大家家常便饭在安顿文件中钦定感兴趣的层名集合,然后搜索的时候,在那么些层中摸索,那样能够拉长检索的进程。

笔者们看看操作层的代码,是怎么促成的。

           foreach (string layer in layerNameArray)
            {
                if (string.IsNullOrEmpty(layer)) 
                    continue;

                try
                {
                    #region 每层的询问
                    string condition = string.Format(“NAME like \”%{0}%\””, SearchLocation);
                    MapXLib.Layer mapLayer =  TarMap.Layers._Item(layer);
                    if (mapLayer != null)
                    {
                        feature = mapLayer.Search(condition, null);
                        int count = feature.Count;
                        if (feature != null)
                        {
                            MapXLib.Dataset ds = TarMap.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetLayer, mapLayer, layer,
                                0, 0, 0, Missing.Value, false);
                            Dictionary<string, ResultOfSearching> resultList = new Dictionary<string, ResultOfSearching>();
                            
                            //To Do 遍历性情代码,待续
                            
                            TarMap.DataSets.RemoveAll();
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }                
            }

 

招来的时候,我们获取了各样Feature,然后对Feature的ID和Name举行判定查找,怎样有格外的,就代表找到了1个对象,若是最后1个也从没,那么这次地图搜索应该没有匹配的因素了,Feature的查找代码如下所示

                            #region 遍历特性
                            for (int i = 1; i < feature.Count; i++)
                            {
                                try
                                {
                                    object objLocation = ds.get_Value(feature[i], “Name”);
                                    object objID = ds.get_Value(feature[i], “Id”);

                                    string strLocation = (objLocation == null) ? “” : objLocation.ToString();
                                    string strID = (objID == null) ? “” : objID.ToString();

                                    if (!resultList.ContainsKey(strID) && feature[i].FeatureID != 0)
                                    {
                                        ResultOfSearching searchInfo = new ResultOfSearching();
                                        searchInfo.FeatureID = feature[i].FeatureID;
                                        searchInfo.ID = strID;
                                        searchInfo.Layer = layer;
                                        searchInfo.Location = feature[i].Name;

                                        if (!resultList.ContainsKey(strID))
                                        {
                                            resultList.Add(strID, searchInfo);
                                        }
                                        if (!allResultList.ContainsKey(strID))
                                        {
                                            allResultList.Add(strID, searchInfo);
                                        }
                                    }
                                }
                                catch(Exception ex)
                                {
                                    //LogHelper.Error(ex);
                                }
                            } 
                            #endregion

 

咱俩遍历每层,对每层的Feature的音讯实行搜索,把结果放到集合中,当大家回来集合的时候,大家就能够把搜索到的消息呈今后树形控件中了。

                    if (searchResult != null && searchResult.Count > 0)
                    {
                        this.tvwResult.BeginUpdate();

                        TreeNode node = null;
                        foreach (ResultOfSearching info in searchResult.Values)
                        {
                            if (!string.IsNullOrEmpty(info.Location))
                            {
                                node = tvwResult.Nodes.Add(info.Location);
                                node.Tag = info;
                            }
                        }

                        this.tvwResult.EndUpdate();
                        this.tssl_Status.Text = string.Format(“从地图上找到 {0} 结果”, searchResult.Count);
                    }
                    else
                    {
                        this.tssl_Status.Text = “地图上找不到你须要的数码”;
                    }

 

终极大家看来查找消息的界面如下所示

图片 1

相关文章