POST
|
Here is a sample written by Miles Hitchen that should do the trick: 'Miles Hitchen
Private Function GetLayerFromFeature(pFtr As IFeature) As IFeatureLayer
'Dim pFtr As IFeature
Dim pFtrCls As IFeatureClass
Dim pMxDoc As IMxDocument
Dim pEnumLyr As IEnumLayer
Dim pLyr As ILayer
Dim pFtrLyr As IFeatureLayer
Dim pObj As IObject
' Get the featureclass of the feature
Set pObj = pFtr
Set pFtrCls = pObj.Class
' Get a layer enumerator on the map
Set pMxDoc = ThisDocument
Set pEnumLyr = pMxDoc.FocusMap.Layers
' Loop through the layers until we find one that contains
' the same featureclass as the feature
pEnumLyr.Reset
Set pLyr = pEnumLyr.Next
While Not pLyr Is Nothing
If TypeOf pLyr Is IFeatureLayer Then
Set pFtrLyr = pLyr
If pFtrLyr.FeatureClass Is pFtrCls Then
' Found it!
Set GetLayerFromFeature = pLyr
Exit Function
End If
End If
Set pLyr = pEnumLyr.Next
Wend
' Not found so return Nothing
Set GetLayerFromFeature = Nothing
End Function
... View more
09-20-2010
07:10 AM
|
0
|
0
|
383
|
POST
|
Have you tried calling FlashShape after the screen has finished drawing? If not you might look into using IMapControlEvents.OnAfterDraw or .OnAfterScreenDraw.
... View more
09-13-2010
08:54 AM
|
0
|
0
|
248
|
POST
|
Or even better would be how do I get the coordinate that the InvertAgent has snapped to?? I can see it has snapped, but when I create my new feature based on the mousePoint, it is not snapped. ISnapEnvironment.SnapPoint will change the coordinates of the point you pass in, if it has successfully snapped. Is 'mousePoint' is a modular level variable so you can use this point in another procedure such as _OnMouseUp or wherever your feature is being created?
... View more
09-10-2010
11:40 AM
|
0
|
0
|
437
|
POST
|
Hi Brian You are correct, if your users are setting up snapping manually you won't need your code to set up a snap agent. Setting the ISnapEnvironment to the IEditor should allow your tool's snapping to behave however the snapping window is set up. Are you using the Editor's edit session, or starting one from scratch on the workspace of your feature class? As for moving the cursor instead of the invert agent, you might try using IDisplayTransformation.FromMapPoint and pass in the resulting X and Y values: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position(ide).aspx
... View more
09-10-2010
07:41 AM
|
0
|
0
|
437
|
POST
|
A few questions: Does the invert agent show up while you are moving the mouse, but won't snap? Or does it not show up at all? If you open the Snapping Window, does the snap agent you created show up, and is it checked? What's your snap tolerance and is it set to pixels or map units?
... View more
09-09-2010
12:08 PM
|
0
|
0
|
437
|
POST
|
The snap agents set up what is available for snapping and how they behave. I'm guessing you want the blue circle of the edit tools to snap when you move the mouse over your features? Here is a snippet from the MouseMove event of a custom editing tool that may help:
mDisplay = mMxDoc.ActiveView.ScreenDisplay
'get the current mouse point
mMousePnt = mAV.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
'use ISnapEnvironment to see if the current mouse point will snap to any snap agents
mSnapEnv.SnapPoint(mMousePnt)
'set the invert agent (blue circle) to the snap point
'if no snap occurs it will stay "under" the cursor
mEditor.InvertAgent(mMousePnt, mEditor.Display.hDC)
'redraw
mDisplay.Invalidate(mAV.Extent.Envelope, True, esriScreenCache.esriNoScreenCache)
... View more
09-09-2010
08:08 AM
|
0
|
0
|
437
|
POST
|
Just a note to improve performance on a portion of the code Jeff provided. Make it a practice to get the index of any field outside of the loops you create and directly use the field index in the loop. The FindField operation does a schema search loop that really only needs to be done once outside of your loop. Repeating loops within loops drags down performance. Using the index value directly inside the loop acts like direct array access to the field and does not cause a secondary hidden loop to occur for every record your loop processes. (From best practices with cursors training at the ESRI conference). So the sample code should be revised as follows:
Dim pTableCursor As ICursor
Dim pRow As IRow
Set pTableCursor = pTable.Search(Nothing, True)
Set pRow = pTableCursor.NextRow
Dim fIndex as Long
fIndex = pTable.Fields.FindField("FeatureClass.FieldName") 'fully qualified field name from joined table
Do Until pRow Is Nothing
Debug.Print pRow.Value(fIndex) ' removes a hidden loop required to find the field
Set pRow = pTableCursor.NextRow
Loop Hope this helps. Good point Richard. It might also be worth mentioning to check if fIndex is <> -1 (i.e. the field name is not found in the feature class or table) before using it, to avoid an automation error.
... View more
09-03-2010
07:12 AM
|
0
|
0
|
499
|
POST
|
Here is a sample that loops through the selected features from a particular layer (in this case the selected layer in the table of contents): Public Sub GetLayerSelection()
'allows enumeration through all features selected from a particular layer
'to get all features regardless of what layer they are in, use IMap.SelectedFeatures
Dim mxDoc As IMxDocument
Set mxDoc = ThisDocument
Dim fLayer As IFeatureLayer
Set fLayer = mxDoc.SelectedLayer
Dim fSel As IFeatureSelection
Set fSel = fLayer
Dim ss As ISelectionSet
Set ss = fSel.SelectionSet
Dim fCur As IFeatureCursor
ss.Search Nothing, True, fCur
Dim feat As IFeature
Set feat = fCur.NextFeature
Do Until feat Is Nothing
Debug.Print feat.OID
Set feat = fCur.NextFeature
Loop
End Sub
... View more
09-02-2010
02:17 PM
|
0
|
0
|
506
|
POST
|
Try looping through the rows in the table to get the values. Just change "FeatureClass.FieldName" to match the table and field you want to see: Sub JoinedFields()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pFeatureLayer As IFeatureLayer
Set pFeatureLayer = pDoc.FocusMap.Layer(0)
Dim pFeat As IFeature
Set pFeat = pFeatureLayer.FeatureClass.GetFeature(12)
Dim pTable As ITable
Dim pDisplayTable As IDisplayTable
Set pDisplayTable = pFeatureLayer
Set pTable = pDisplayTable.DisplayTable
'Dim pFields As IFields
'Dim pField As IField
'Set pFields = pTable.Fields
'For i = 0 To pFields.fieldCount - 1
' Debug.Print pFields.Field(i).Name
'Next
Dim pTableCursor As ICursor
Dim pRow As IRow
Set pTableCursor = pTable.Search(Nothing, True)
Set pRow = pTableCursor.NextRow
Do Until pRow Is Nothing
Debug.Print pRow.Value(pTable.Fields.FindField("FeatureClass.FieldName")) 'fully qualified field name from joined table
Set pRow = pTableCursor.NextRow
Loop
End Sub
... View more
09-02-2010
12:11 PM
|
0
|
0
|
506
|
POST
|
Does your data contain true curves, or was it converted to shapefile from a dataset that did contain true curves? If so you might be seeing a "display error" when zoomed in to a very large scale. One thing you might try is to split the curve at your query point using , and then compare the X and Y values of the vertex from the polyline, and the point. If they are equal then it might be the display issue, but if the values are not the same then there may be something else going on.
... View more
08-30-2010
12:09 PM
|
0
|
0
|
529
|
POST
|
Yes, I would first try projecting your intermediate point to match the curve geometry, and see if that helps. Also, is any of your data Z aware? Regarding snapping, most likely the point is within the tolerance and that is why it is not moving. If nothing is helping, perhaps you could zip up a small amount of data and your code and someone can take a look...
... View more
08-30-2010
07:54 AM
|
0
|
0
|
529
|
POST
|
Is your data frame, curve geometry and return point geometry all in the same coordinate system?
... View more
08-27-2010
02:36 PM
|
0
|
0
|
529
|
POST
|
Nice catch - the Subtype thing was going to be my second question...now you probably can't call yourself a novice anymore 🙂
... View more
08-12-2010
01:13 PM
|
0
|
0
|
279
|
POST
|
Maybe try using IFeatureSelection.Add instead? Here is a sample that might help (currently just uses the top map layers, layer 0 is the point layer and layer 1 is the polygon layer) Public Sub SelectPoints()
Dim pFeature As IFeature
Dim pFLayer_point As IFeatureLayer
Dim pFLayer_poly As IFeatureLayer
Dim pFSelection_point As IFeatureSelection
Dim pFSelection_poly As IFeatureSelection
Dim pSelectionSet As ISelectionSet
Dim pFClass_poly As IFeatureClass
Dim pFCursor As IFeatureCursor
Dim pResult As IFeatureCursor
Dim pResFeat As IFeature
Dim pSpatialFilter As ISpatialFilter
Dim pGeometry As IGeometry
Dim pMxDocument As IMxDocument
Dim pActiveView As IActiveView
Dim pmap As IMap
Dim pTOC As IContentsView
Set pMxDocument = Application.Document
Set pActiveView = pMxDocument.ActiveView
Set pmap = pMxDocument.FocusMap
Set pFLayer_point = pmap.Layer(0)
Set pFLayer_poly = pmap.Layer(1)
Set pSpatialFilter = New SpatialFilter
Set pFClass_poly = pFLayer_poly.FeatureClass
Set pFSelection_poly = pFLayer_poly
Set pFCursor = pFClass_poly.Search(Nothing, False)
Set pFeature = pFCursor.NextFeature
While Not pFeature Is Nothing
Set pGeometry = pFeature.Shape
With pSpatialFilter
Set pSpatialFilter.Geometry = pGeometry
.GeometryField = pFClass_poly.ShapeFieldName 'not necessary
.SpatialRel = esriSpatialRelContains
End With
Set pResult = pFLayer_point.Search(pSpatialFilter, False)
Set pFSelection_point = pFLayer_point
Set pResFeat = pResult.NextFeature
Do Until pResFeat Is Nothing
pFSelection_point.Add pResFeat
Set pResFeat = pResult.NextFeature
Loop
Set pFeature = pFCursor.NextFeature
Wend
Set pActiveView = pMxDocument.ActiveView
pActiveView.Refresh
'refresh the selection tab of the TOC (item #2)
Set pTOC = pMxDocument.ContentsView(2)
pTOC.Refresh 0 'not sure why this needs an argument, #s 0-4 provide same result?
End Sub
... View more
08-12-2010
09:16 AM
|
0
|
0
|
279
|
Title | Kudos | Posted |
---|---|---|
1 | 06-14-2016 08:33 AM | |
1 | 02-23-2015 09:11 AM | |
3 | 07-14-2017 10:29 AM | |
1 | 07-16-2015 10:07 AM | |
2 | 10-16-2018 10:59 AM |
Online Status |
Offline
|
Date Last Visited |
12-08-2020
02:52 PM
|