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

///
///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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值