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've just started learning VBA and Arcobjects, and at the moment just playing around tyring to do different things. What i am trying to do is Click on a tool, and allow the user to put a point graphic on the map, but also buffer the point(marker) that has been added. I can get the point on the map, but seem to be going round in circles getting the buffer to work. Can someone give me some hints ( i dont want the exact answer just some guidance on where I am going wrong.

Code is here.

Private Sub Buffer_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)

Dim pMxDoc As IMxDocument ' Create Object for current document
Set pMxDoc = ThisDocument ' Set object to current Document

Dim pMap As IMap ' Create object for current map
Set pMap = pMxDoc.FocusMap ' Set object to the current active map

Dim pPoint As IPoint 'Create object for point on map
Set pPoint = pMxDoc.CurrentLocation '  Set object to current location

Dim pElement As IElement ' Create object for graphic THAT IS ADDED TO THE MAP!!!!
Set pElement = New MarkerElement ' Set object to a new marker element (point graphic)

pElement.Geometry = pPoint ' Assign the geometry of the element to the Point.

Dim pGraphics As IGraphicsContainer ' Create object to hold the graphic
Set pGraphics = pMap ' Set object to current active map

pGraphics.AddElement pElement, 0 '  Set the graphic that will be added

Dim pActiveView As IActiveView ' Create object for active map display
Set pActiveView = pMxDoc.ActiveView ' Set object to the Active view

'--------------CREATE BUFFER------------------------'

 Dim pSpaRef As ISpatialReference3
 Set pSpaRef = pMap.SpatialReference

 Dim pFCBuffer As IFeatureCursorBuffer2 ' Create Object for buffer
 Set pFCBuffer = New FeatureCursorBuffer ' Set object for new buffer

 pFCBuffer.Dissolve = True
 pFCBuffer.ValueDistance = 100
 Set pFCBuffer.BufferSpatialReference = pSpaRef
 Set pFCBuffer.DataFrameSpatialReference = pSpaRef
 Set pFCBuffer.SourceSpatialReference = pSpaRef
 Set pFCBuffer.TargetSpatialReference = pSpaRef


 Dim pCGLayer As ICompositeGraphicsLayer2
 Set pCGLayer = New CompositeGraphicsLayer

 Dim pGLayer As IGraphicsLayer
 Set pGLayer = pMap.ActiveGraphicsLayer


 pFCBuffer.BufferToGraphics pGLayer



   pActiveView.PartialRefresh esriViewGraphics, pElement, Nothing ' [partial refresh of the graphics element.

  End Sub

Thanks Halil

share|improve this question
add comment

1 Answer

Halil,

The interface you are using to create the buffers IFeatureCursorBuffer2 creates buffers for selected features. Your point that you create based upon the users button click is not a feature but a graphic which you are adding to the graphics container of the map. A Feature is essentially a row in a table or featureclass.

As you are adding your point as a graphic I assume the buffer you want to create will also end up as a graphic. Use the interface ITopologicalOperator and it's method Buffer to create a polygon then do as you did with your point, create a graphic element.

Duncan

share|improve this answer
    
Duncun, i have added the following Dim pTopoOp As ITopologicalOperator2 Dim pBuffPoly As IPolygon Set pTopoOp = pPoint.GeometryType Set pBuffPoly = pTopoOp.Buffer(1000) but I get a type mismatch error on line 3, i've also tried Set pTopoOp = pElement.Geometry but get the same mismatch error. Halil –  Halil Siddique Nov 11 '11 at 16:04
    
The line "Set pTopoOp = pPoint.GeometryType" should be "Set pTopoOp = pPoint" –  Hornbydd Dec 10 '11 at 18:11
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.