iwannafly
路人甲
路人甲
  • 注册日期2005-12-03
  • 发帖数35
  • QQ
  • 铜币274枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1719回复:4

c#点击查询

楼主#
更多 发布于:2006-07-19 12:13
<P>我在做一个关于c#点击查询的例子,出现了若干问题,不知道该如何解决.</P>
<P>问题是没有提示错误,但是操作没有任何效果!在IArray pIDArray=pIdentify.Identify (point) as IArray 处就已经不能在控制台输出任何东西测试了!</P>
<DIV>我的代码</DIV>
<DIV>private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)<BR>  {<BR>        IIdentify pIdentify;<BR>        IPoint pPoint;<BR>        IFeatureIdentifyObj pFeatIdObj;<BR>        IGeoFeatureLayer pGeoLayer=axMapControl1.get_Layer (0) as IGeoFeatureLayer ; </DIV>
<DIV>        pIdentify=pGeoLayer as IIdentify ;<BR>        pPoint=axMapControl1.ActiveView .ScreenDisplay .DisplayTransformation .ToMapPoint (e.x ,e.y);</DIV>
<DIV>        IGeometry point=pPoint as IGeometry ;<BR>   ****     IArray pIDArray=pIdentify.Identify (point) as IArray ;<BR>        pFeatIdObj=pIDArray.get_Element (0) as IFeatureIdentifyObj;<BR>        IRowIdentifyObject pIdObj = pFeatIdObj as IRowIdentifyObject ;// IIdentifyObj ;<BR>        IFeature pFeature=pIdObj.Row as IFeature;<BR>        IRow ipRow=pFeature;</DIV>
<DIV>        if(ipRow != null)<BR>        {<BR>          string strValue="";<BR>          IRowBuffer ipRowBuffer = ipRow;<BR>          for(int i=0;i<ipRowBuffer.Fields.FieldCount;i++)<BR>          {<BR>             strValue ="->"+ ipRowBuffer.get_Value(i).ToString();<BR>        <BR>          }<BR>          MessageBox.Show(strValue);<BR>       }<BR>      else<BR>      MessageBox.Show ("go to hell");</DIV>
<DIV>  }</DIV>
<DIV>  <BR></DIV>
喜欢0 评分0
cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5917
  • QQ14265545
  • 铜币29669枚
  • 威望217点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
1楼#
发布于:2006-07-19 15:19
<P>  private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)<BR>  {<BR>   IFeatureLayer GISEmpireFeatureLayer = (IFeatureLayer)axMapControl1.get_Layer(0);<BR>   IFeatureClass GISEmpireFeatureClass  = GISEmpireFeatureLayer.FeatureClass;</P>
<P>   IActiveView pActiveView = (IActiveView)axMapControl1.Map;<BR>   IPoint pPoint  = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);<BR>   IGeometry pGeometry = pPoint;<BR>      <BR>   //选择缓冲区<BR>   double length = ConvertPixelsToMapUnits(pActiveView, 4);<BR>   ITopologicalOperator pTopo = (ITopologicalOperator)pGeometry;<BR>   IGeometry pBuffer = pTopo.Buffer(length);<BR>   pGeometry  = (IGeometry)pBuffer.Envelope;</P>
<P>   ISpatialFilter pSpatialFilter = new SpatialFilter();<BR>   pSpatialFilter.Geometry = pGeometry;<BR>   switch(GISEmpireFeatureClass.ShapeType)<BR>   {<BR>    case esriGeometryType.esriGeometryPoint:<BR>     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;<BR>     break;<BR>    case esriGeometryType.esriGeometryPolyline:<BR>     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;<BR>     break;<BR>    case esriGeometryType.esriGeometryPolygon:<BR>     pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;<BR>     break;<BR>   }<BR>   pSpatialFilter.GeometryField = GISEmpireFeatureClass.ShapeFieldName;<BR>   IQueryFilter GISEmpireFilter = pSpatialFilter;</P>
<P>   IFeatureCursor pCursor = GISEmpireFeatureLayer.Search(GISEmpireFilter, false);</P>
<P>   //第一个,我很懒<BR>   IFeature GISEmpireFeature = pCursor.NextFeature();</P>
<P>   //打印出选择的要素<BR>   MessageBox.Show(GISEmpireFeature.get_Value(2).ToString());</P>
<P>  }</P>
<P>  private double ConvertPixelsToMapUnits(IActiveView pActiveView , double pixelUnits)<BR>  {<BR>   IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;<BR>   IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;<BR>   int x1, x2, y1, y2;<BR>   pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);<BR>   pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);<BR>   double pixelExtent = x2 - x1;<BR>   double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;<BR>   double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;<BR>   return pixelUnits * sizeOfOnePixel;<BR>  }</P>
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
举报 回复(0) 喜欢(0)     评分
iwannafly
路人甲
路人甲
  • 注册日期2005-12-03
  • 发帖数35
  • QQ
  • 铜币274枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-07-19 16:15
<P>谢谢老大,实现了!</P>
<P>还是仔细学习一下老大的代码,感觉和我原来的思路不太一样了.</P>
举报 回复(0) 喜欢(0)     评分
hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-08-12 21:55
<P>好,这个代码也帮了我的忙了  谢过老大 ~~~~~~~</P>
举报 回复(0) 喜欢(0)     评分
hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-08-13 15:58
<P>请问总统在这个代码里要多一个闪烁的功能是如何实现呢 </P>
<P>请指教指教在下  可以吗 </P>
<P>谢过了</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部