Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am attempting to loop through polygon features and rotate pairs of features by a specified angle.

Pseudo logic:

1) Open up a standalone table in the map document and retrieve a unique identifier that will used to select a pair of polygons from a feature class. This code works just fine. Code retrieves the identifying value for selecting the polygons and the rotation angle.

2) Create a selection using the unique identifier. In this application only two records will be returned.

3) Rotate the selected polygons around the SelectionAnchor

4) Advance to the next standalone table record, repeat making selection and rotation

Every works fine up to the point that the rotation routine attempts to apply QuerryCoords on the selection anchor. The SelectionAnchor is seen as empty geometry.

If I manually select the polygon set, and run the RotateSelectedFeatures routine, it produces the desired outcome.

Code for selection features:

Sub RotateSelectedFeatures()
    Dim sHRMashUP As String
    Dim intLayerCnt As Integer
    Dim pMXDoc As IMxDocument
    Dim pMap As IMap
    Dim pFeatureLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim pUID As New UID
    Dim pEditor As IEditor
    Dim pRotatePoint As IPoint
    Dim pEnumFeature As IEnumFeature
    Dim pFeature As IFeature
    Dim pRotateSet As ISet
    Dim pFeatureEdit As IFeatureEdit
    Dim pFeatureSelection As IFeatureSelection
    Dim pQueryFilter As IQueryFilter
    Dim sSQL As String
    Dim pActiveView As IActiveView
    Dim pInvalidArea As IInvalidArea
    Dim pStartPoint As IPoint
    Dim origX As Double
    Dim origY As Double

    Set pMXDoc = ThisDocument
    Set pMap = pMXDoc.FocusMap
    Set pActiveView = pMap

    pUID.Value = "esricore.Editor"

    Set pEditor = Application.FindExtensionByCLSID(pUID)

    'Name of layer with home range polygons
    sHRMashUP = "HomeRangePairs_Mashup_2"

    'Loop through the table of contents to see which layer is the target home range poygons identified above
    For intLayerCnt = 0 To pMXDoc.FocusMap.LayerCount - 1
        If pMXDoc.FocusMap.Layer(intLayerCnt).Name = sHRMashUP Then
            Set pFeatureLayer = pMXDoc.FocusMap.Layer(intLayerCnt)
        End If
    Next intLayerCnt


    If pEditor.EditState = esriStateEditing Then
        pEditor.StopEditing False
    End If

    If pEditor.EditState = esriStateNotEditing Then
        Set pDataset = pFeatureLayer.FeatureClass
        pEditor.StartEditing pDataset.Workspace

        ' Select features using the X,Y coordinates read in from text file
        Set pFeatureSelection = pFeatureLayer 'QI

        'Create the query filter for selecting on the field with the coma delimited xy location read from the text file
        Set pQueryFilter = New QueryFilter

        sSQL = "XYCoords = " & Chr(39) & g_sXYCoords & Chr(39)

        pQueryFilter.WhereClause = sSQL

        ' Invalidate only the selection cache
        'Flag the original selection
        pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing

        'Perform the selection
        pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False

        'Make sure something has been selected
        'Debug.Print g_sXYCoords
        If pEditor.SelectionCount = 0 Then
            pEditor.StopEditing False
            Exit Sub
        Else
            Call RotateSelectedFeatures
        End If

        'Flag the new selection
        pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
    End If
End Sub
Public Sub RotateSelectedFeatures()
  Dim pEditor As IEditor
  Dim pID As New UID
  Dim pEnumFeature As IEnumFeature
  Dim pFeature As IFeature
  Dim mySet As ISet
  Dim pSpatialReference As ISpatialReference
  Dim pStartPoint As IPoint
  Dim pEndPoint As IPoint
  Dim pFeatureEdit As IFeatureEdit
  Dim pLine As ILine
  Dim origX As Double
  Dim origY As Double
  Dim Count As Integer

  'Get a reference to the editor extension
  pID = "esriEditor.Editor"
  Set pEditor = Application.FindExtensionByCLSID(pID)
  'Make sure something has been selected
  If pEditor.SelectionCount = 0 Then
    MsgBox "Nothing Selected"
    Exit Sub
  End If
  'Create an edit operation enabling undo/redo
  pEditor.StopOperation "Rotate Selection"
  pEditor.StartOperation

  'Get the selection from the Editor and add all the features to a new Set
  Set pEnumFeature = pEditor.EditSelection
  Set mySet = New esriSystem.Set
  pEnumFeature.Reset
  For Count = 0 To pEditor.SelectionCount - 1
    Set pFeature = pEnumFeature.Next
    mySet.Add pFeature
  Next Count

  'Reset the Set
  mySet.Reset

  'MoveSet requires a line to specify the new location
  'Use the selection anchor as a starting point for the line
  Set pStartPoint = pEditor.SelectionAnchor.Point
  pStartPoint.QueryCoords origX, origY

  ' Rotate the set
  Do
    Set pFeatureEdit = mySet.Next
    If Not pFeatureEdit Is Nothing Then
      pFeatureEdit.RotateSet mySet, pStartPoint, g_dblAngle
    Else
      Exit Do
    End If
  Loop

  'Stop the Edit Operation
  pEditor.StopOperation "Rotate Selection"  'String to appear in Edit menu

  'Refresh the Map to redisplay the moved features
  pEditor.Display.Invalidate Nothing, True, esriAllScreenCaches

End Sub

The Where clause uses two variables set in the calling routine

If a selection is produced, this routine calls the RotateSelectedFeatures routine which acts on the selected set.

Bails on the pStartPoint.QueryCoords origX, origY line due to empty geometry.

share|improve this question
    
prog-ids with "esricore" were deprecated after arcgis 8.3. –  Kirk Kuykendall Mar 26 '13 at 2:42
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.