阅读:1760回复:2
在地图上选择图元后,如何在代码里获得指定的某个图层上被选择的图元
<P>才开始用engine。现在有这样的一个功能请大家帮我看看代码,如何实现。</P>
<P>我在mapcontrol上显示了一个地图,里面有10多个图层,第一个叫ycbase,...。在toolbar control组件中放了一个select feature。提供给客户选择图元用。客户用它在地图上一拉,把从第一个图层到最底下的图层中拉选范围的图元都选择出来了。我这个时候通过代码得到了这些图元。但是我只关心想得到第一个图层上(或者某个图层上)的被选择的图元,那我怎么能得到呢?我下面的代码只能实现得到全部图层被选择的图元。请大家帮我看看怎么得到某个图层上的图元。</P> <P> try{<BR> <BR> com.esri.arcgis.carto.MapSelection selection = new com.esri.arcgis.carto.MapSelection(mapBean1.getActiveView().getSelection()); <BR> com.esri.arcgis.geodatabase.IEnumFeature enumFeature = (com.esri.arcgis.geodatabase.IEnumFeature)selection;<BR> com.esri.arcgis.geodatabase.IFeature feature = null;<BR> <BR> // Add the selected features geometry to the array<BR> enumFeature.reset();<BR> feature = enumFeature.next();<BR> while(feature != null){<BR> System.out.println("OID:" + feature.getOID());<BR> feature = enumFeature.next();<BR> }<BR> }<BR> catch(Exception e){<BR> e.printStackTrace();<BR> }</P><img src="images/post/smile/dvbbs/em08.gif" /> |
|
1楼#
发布于:2007-06-11 09:48
其实,你不需要知道选择的IFeature属于哪个图层,也可以照样对它进行操作的嘛。如果需要绘制 新图形的话,就需要先确定在哪个图层上绘制了。
|
|
|
2楼#
发布于:2007-06-09 11:27
<P>下面是在各个图层中查找选择的要素,你可以只在你要的图层里找,下面是例子的代码</P>
<P>Public Sub QuerySelectedFeatures()<BR> Dim pMxDoc As IMxDocument<BR> Dim pEnumLayer As IEnumLayer<BR> Dim pFeature As IFeature<BR> Dim pFeatureCursor As IFeatureCursor<BR> Dim pFeatureLayer As IFeatureLayer<BR> Dim pFeatureSelection As IFeatureSelection<BR> Dim pMap As IMap<BR> Dim pSelectionSet As ISelectionSet<BR> Dim pUID As IUID<BR></P><PRE>'the UID<EM> </EM>specifies the interface identifier (GUID)<BR>'that represents the type of layer you want returned.<BR>'in this case we want an EnumLayer containing all the FeatureLayer objects Set pUID = New UID pUID = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" ' Identifies FeatureLayer objects Set pMxDoc = Application.Document Set pMap = pMxDoc.FocusMap 'Loop through all feature layers in the map Set pEnumLayer = pMap.Layers(pUID, True) pEnumLayer.Reset Set pFeatureLayer = pEnumLayer.Next Do While Not pFeatureLayer Is Nothing 'Loop through the selected features per layer Set pFeatureSelection = pFeatureLayer 'QI Set pSelectionSet = pFeatureSelection.SelectionSet 'Can use Nothing keyword if you don't want to draw them, 'otherwise, the spatial reference might not match the Map's pSelectionSet.Search Nothing, False, pFeatureCursor Set pFeature = pFeatureCursor.NextFeature Do While Not pFeature Is Nothing 'Do something with the feature Debug.Print pFeature.Value(pFeature.Fields.FindField("Name")) Set pFeature = pFeatureCursor.NextFeature Loop Set pFeatureLayer = pEnumLayer.Next Loop End Sub </PRE> |
|
|