阅读:1719回复:4
c#点击查询
<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> |
|
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> |
|
|
2楼#
发布于:2006-07-19 16:15
<P>谢谢老大,实现了!</P>
<P>还是仔细学习一下老大的代码,感觉和我原来的思路不太一样了.</P> |
|
3楼#
发布于:2006-08-12 21:55
<P>好,这个代码也帮了我的忙了 谢过老大 ~~~~~~~</P>
|
|
4楼#
发布于:2006-08-13 15:58
<P>请问总统在这个代码里要多一个闪烁的功能是如何实现呢 </P>
<P>请指教指教在下 可以吗 </P> <P>谢过了</P> |
|