阅读:2595回复:3
AE+C#三维开发,怎样进行属性查询?给个思路?小弟感激不尽?
<P>AE+C#三维开发,怎样进行属性查询?给个思路?小弟感激不尽?本人找到点源码,但是VB的</P>
<P>本人找到点源码,但是VB的,哪位大哥帮忙翻译一下</P> <P>Private Sub cmdApply_Click()<BR> Dim result As esriSelectionResultEnum<BR> <BR> ' Apply button pressed. If control key is depressed then add this selections<BR> ' of this operation to the current selection set, other wise create a new one<BR> If (Not (GetKeyState(VK_CONTROL) < 0)) Then<BR> result = esriSelectionResultNew<BR> Else<BR> result = esriSelectionResultAdd<BR> End If<BR> <BR> Select Case tbsOptions.SelectedItem.Index<BR> Case 1<BR> QueryByClass result<BR> Case 2<BR> QueryByAttribute result '从这里调用的<BR> Case 3<BR> QueryBySpace result<BR> End Select<BR>End Sub<BR><BR><BR><BR>Private Sub QueryByAttribute(operator As esriSelectionResultEnum)<BR> Dim pFeatureLayer As IGeoFeatureLayer<BR> Dim j As Long<BR> Dim i As Long<BR> Dim pFeatureselection As IFeatureSelection<BR> Dim pActiveView As IActiveView<BR> Dim pFields As IFields<BR> Dim pField As IField<BR> Dim FieldID As Long<BR> Dim operatorString As String<BR> Dim whereClause As String<BR> Dim pFilter As IQueryFilter<BR> Dim attName As String<BR> Dim attValue As Variant<BR> <BR> On Error GoTo ErrorHandler<BR> <BR> ' construct the where clause from the users entries on the form<BR> If ((lstAttribute.SelCount < 1) Or (txtValue = "")) Then<BR> GiveWarning "Warning", "You must select an attribute along with a value!"<BR> Exit Sub<BR> End If<BR> <BR> For i = 0 To lstAttribute.ListCount - 1<BR> If (lstAttribute.Selected(i)) Then<BR> attName = lstAttribute.List(i)<BR> i = lstAttribute.ListCount<BR> End If<BR> Next i<BR> <BR> Select Case cboOperator.Text<BR> Case "等于"<BR> operatorString = "="<BR> Case "不等于"<BR> operatorString = "<>"<BR> Case "小于"<BR> operatorString = "<"<BR> Case "大于"<BR> operatorString = ">"<BR> Case "小于或等于"<BR> operatorString = "<="<BR> Case "大于或等于"<BR> operatorString = ">="<BR> End Select<BR> <BR> Set pActiveView = m_pMap<BR> pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR> For j = 0 To lstClass.ListCount - 1<BR> If (lstClass.Selected(j)) Then<BR> If (FoundLayer(lstClass.List(j), pFeatureLayer)) Then<BR> Set pFeatureselection = pFeatureLayer<BR> If (pFeatureLayer.Selectable) Then<BR> ' Must convert the attribute value to the correct type<BR> Set pFields = pFeatureLayer.FeatureClass.Fields<BR> FieldID = pFeatureLayer.FeatureClass.FindField(attName)<BR> Set pField = pFields.Field(FieldID)<BR> attValue = txtValue.Text<BR> Select Case pField.Type<BR> Case esriFieldTypeInteger<BR> attValue = CInt(attValue)<BR> Case esriFieldTypeSingle<BR> attValue = CInt(attValue)<BR> Case esriFieldTypeSmallInteger<BR> attValue = CInt(attValue)<BR> Case esriFieldTypeDouble<BR> attValue = CDbl(attValue)<BR> Case esriFieldTypeOID<BR> attValue = CLng(attValue)<BR> Case esriFieldTypeString<BR> attValue = CStr(attValue)<BR> attValue = "'" ; CStr(attValue) ; "'"<BR> End Select<BR> whereClause = attName ; operatorString ; " " ; CStr(attValue)<BR> Set pFilter = New QueryFilter<BR> pFilter.SubFields = "*"<BR> pFilter.whereClause = whereClause<BR> Set pFilter.OutputSpatialReference(attName) = m_pMap.SpatialReference<BR> pFeatureselection.SelectFeatures pFilter, operator, False<BR> Else<BR> If (operator = esriSelectionResultNew) Then pFeatureselection.Clear<BR> End If<BR> End If<BR> Else<BR> If (FoundLayer(lstClass.List(j), pFeatureLayer)) Then<BR> Set pFeatureselection = pFeatureLayer<BR> If ((operator = esriSelectionResultNew) Or _<BR> (operator = esriSelectionResultAnd)) Then pFeatureselection.Clear<BR> End If<BR> End If<BR> Next j<BR> Debug.Print pFeatureLayer.name<BR> pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR> frmMDIMain.ActiveBar.Bands("StatusBar").Tools("StatusBarLabel").Caption = "选择实体数目: " ; CStr(m_pMap.SelectionCount)<BR> RefreshSelectButtons<BR> <BR> Exit Sub<BR>ErrorHandler:<BR> MsgBox "An unexpected error has occured with the Selection Dialog." ; vbCr ; vbCr ; _<BR> "Details : " ; Err.Description, vbExclamation + vbOKOnly, "Error"<BR>End Sub<BR><BR>Private Sub QueryBySpace(operator As esriSelectionResultEnum)<BR> Dim pClassList As Collection<BR> Dim i As Long<BR> Dim j As Long<BR> Dim pElement As IElement<BR> Dim relOperator As esriSpatialRelEnum<BR> Dim pGeometry As IGeometry<BR> Dim pPoint As IPoint<BR> Dim pEnv As IEnvelope<BR> Dim pSelectEnv As ISelectionEnvironment<BR> Dim pActiveView As IActiveView<BR>' Dim pMxApp As IMxApplication<BR> Dim prevSelMethod As esriSelectionResultEnum<BR> Dim shiftKeyDown As Boolean<BR> Dim prevAreaSelection As esriSpatialRelEnum<BR> Dim prevLineSelection As esriSpatialRelEnum<BR> Dim prevPointSelection As esriSpatialRelEnum<BR> Dim pColn As Collection<BR> Dim pLayer As ILayer<BR> Dim pGeoLayer As IGeoFeatureLayer<BR> <BR> On Error GoTo ErrorHandler<BR> <BR> If (m_pSearchGeometry Is Nothing) Then Exit Sub<BR> <BR> 'Set pMxApp = m_pApp<BR><BR> Set pSelectEnv = New SelectionEnvironment<BR> prevAreaSelection = pSelectEnv.AreaSelectionMethod<BR> prevLineSelection = pSelectEnv.LinearSelectionMethod<BR> prevPointSelection = pSelectEnv.PointSelectionMethod<BR> If (optSpatialOp(0).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelContains<BR> ElseIf (optSpatialOp(1).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelCrosses<BR> ElseIf (optSpatialOp(2).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelIntersects<BR> ElseIf (optSpatialOp(3).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelOverlaps<BR> ElseIf (optSpatialOp(4).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelTouches<BR> ElseIf (optSpatialOp(5).Value = True) Then<BR> pSelectEnv.AreaSelectionMethod = esriSpatialRelWithin<BR> End If<BR> pSelectEnv.LinearSelectionMethod = pSelectEnv.AreaSelectionMethod<BR> pSelectEnv.PointSelectionMethod = pSelectEnv.AreaSelectionMethod<BR> ' now set the layers to be search through. This is done by going through and setting all<BR> ' non searchable layers to false<BR> <BR> prevSelMethod = pSelectEnv.CombinationMethod<BR> pSelectEnv.CombinationMethod = operator<BR><BR> Set pActiveView = m_pMap<BR> If (prevSelMethod <> esriSelectionResultAdd) Then pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR> <BR> <BR> Set pColn = New Collection<BR> For i = 0 To (m_pMap.LayerCount - 1)<BR> Set pLayer = m_pMap.Layer(i)<BR> If (TypeOf pLayer Is IGeoFeatureLayer) Then<BR> Set pGeoLayer = pLayer<BR> pColn.Add pGeoLayer.Selectable, CStr(i)<BR> pGeoLayer.Selectable = False<BR> For j = 0 To lstClass.ListCount - 1<BR> If (lstClass.Selected(j)) Then<BR> If (lstClass.List(j) = pGeoLayer.name) Then<BR> pGeoLayer.Selectable = True<BR> j = lstClass.ListCount<BR> End If<BR> End If<BR> Next j<BR> End If<BR> Next i<BR> m_pMap.SelectByShape m_pSearchGeometry, pSelectEnv, False<BR> pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR><BR> ' reset the selection status of thje layers back<BR> For i = 0 To (m_pMap.LayerCount - 1)<BR> Set pLayer = m_pMap.Layer(i)<BR> If (TypeOf pLayer Is IGeoFeatureLayer) Then<BR> Set pGeoLayer = pLayer<BR> pGeoLayer.Selectable = pColn.Item(CStr(i))<BR> End If<BR> Next i<BR> <BR> pSelectEnv.CombinationMethod = prevSelMethod<BR> pSelectEnv.AreaSelectionMethod = prevAreaSelection<BR> pSelectEnv.LinearSelectionMethod = prevLineSelection<BR> pSelectEnv.PointSelectionMethod = prevLineSelection<BR> RefreshSelectButtons<BR><BR> Exit Sub<BR>ErrorHandler:<BR> MsgBox "An unexpected error has occured with the Selection Dialog." ; vbCr ; vbCr ; _<BR> "Details : " ; Err.Description, vbExclamation + vbOKOnly, "Error"<BR>End Sub</P> |
|
1楼#
发布于:2008-02-20 14:20
没人回答我顶了
|
|
2楼#
发布于:2008-02-22 12:42
<TABLE fixed; WORD-BREAK: break-all" height="85%" width="95%" align=center border=0>
<TR> <TD 9pt; LINE-HEIGHT: 12pt" vAlign=top width=* height="100%"><IMG src="http://www.gisempire.com/bbs/Skins/Default/topicface/face0.gif"> <B></B><BR>没人回答我顶了</TD></TR></TABLE> |
|
3楼#
发布于:2009-05-18 09:32
我也想知道
|
|