C# AE 地物名称到地图空间位置查询函数(转)

论坛 期权论坛 脚本     
匿名技术用户   2021-1-2 06:42   32   0
///
///mc//载入地图的控件 ///findstr//查询字符串与SQL语句相同如:NAME ='***' ///sLayerName//查询的地物所在图层 /// public void findlocation(AxMapControl mc,string findstr,string sLayerName)//查询函数 { IQueryFilter pQueryFilter = new QueryFilterClass(); IFeatureLayer pFeatureLayer; pFeatureLayer = mc.get_Layer(GetLayerFromName(sLayerName, mc)) as IFeatureLayer; //GetLayerFromName函数下文有,主要是根据图层名获取图层所在的索引号 mc.MapScale = pFeatureLayer.MinimumScale; if(pFeatureLayer == null) return; mc.Map.ClearSelection(); IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; pQueryFilter.WhereClause = findstr;//查询条件 IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, false); pFeature = pFeatureCursor.NextFeature(); IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; while (pFeature != null) { mc.Map.SelectFeature(mc.get_Layer(GetLayerFromName(sLayerName, mc)), pFeature); mc.FlashShape(pFeature.Shape, 1, 500,null); mc.DrawShape(pFeature.Shape); pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); showcenter(mc, pFeature);//下文有函数,作用是使查询地物居中显示 pFeature = pFeatureCursor.NextFeature(); } } //从图层的名称获得Ilayer接口类 private int GetLayerFromName(string sName, AxMapControl axmap) { int pLyrid=0; try { for (int i = 0; i <= axmap.LayerCount - 1; i++) { if (axmap.get_Layer(i).Name == sName) { pLyrid = i; } } } catch (System.Exception Ex) { MessageBox.Show(Ex.ToString()); } return pLyrid; } public double x; public double y; private void showcenter(AxMapControl mc,IFeature pftr)//查询地物居中显示函数 { x = pftr.Extent.XMin + pftr.Extent.Height / 2; y = pftr.Extent.YMin + pftr.Extent.Width / 2; IPoint pt = new PointClass(); pt.PutCoords(x, y); mc.CenterAt(pt); }

更多GIS开发相关问题请加入 GIS开发学习QQ交流群 192251607 共同交流学习!

转载于:https://www.cnblogs.com/hl137510705/p/9266785.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP