Draw Rectangle

455
3
10-18-2010 04:38 PM
AsimShrestha1
New Contributor
Can anyone please tell me how do I draw rectangles on my map. I'm using ArcGIS Engine 9.3 and C#. Also I need to know how to read from a dataset because I'll need that to adjust the height of the rectangle.

Thanks in advance!
0 Kudos
3 Replies
NirYoscovitz
New Contributor III
Hi Asim,

You can use ControlsNewPolygonTool CoClass.

Regards,
Nir

ICommand command = new ControlsNewPolygonToolClass();
command.OnCreate(axMapControl1.Object); 
axMapControl1.CurrentTool= (ITool) command;
0 Kudos
AsimShrestha1
New Contributor
Thanks for your reply Nir,
I don't need to add a tool to draw rectangle, rather I need to draw them dynamically. I actually have to draw histograms on top of the segments of a road map. The position of these road segments in determined by the road segments and the height is determined by the attributes that should be read from a data table.
0 Kudos
GuyUrban
New Contributor
I find arcgis hard to code.
Here is some VBA code I wrote that works. It makes a triangle, but adding a few more sides is straight forward.

Private Sub Polyline_Click()
'get the GraphicsContainer and the map spatial reference
Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  
   Dim pGraphicsContainer As IGraphicsContainer
  Set pGraphicsContainer = pMxDoc.ActiveView
     
  Dim pColor As IColor
  Set pColor = New RgbColor
  pColor.RGB = RGB(0, 0, 0)

  Dim pSLS As ISimpleLineSymbol
  Set pSLS = New SimpleLineSymbol
  pSLS.Color = pColor
  pSLS.Style = esriSLSSolid
  pSLS.Width = 4
 
  Dim pStartPoint As IPoint
  Set pStartPoint = New Point
  pStartPoint.PutCoords 117, 0
  FromPoint = pStartPoint
 
  Dim pEndPoint As IPoint
  Set pEndPoint = New Point
  pEndPoint.PutCoords 0, -60
  ToPoint = pEndPoint
 
  'Create LINE Element
  Dim pElement As IElement
  Set pElement = New LineElement

  Dim pLineElement As ILineElement
  Set pLineElement = New LineElement
  pLineElement.Symbol = pSLS
  
  Set pElement = pLineElement
  
   Dim pGeometryCollection As IGeometryCollection
   Set pGeometryCollection = New Polyline
  
  
  ' Dim pSeg As ISegment
   Dim pSegcoll As ISegmentCollection
   Set pSegcoll = New Path
 
 
  Dim pLine As ILine
  Set pLine = New Line

 
  pLine.PutCoords pStartPoint, pEndPoint
 
  pSegcoll.AddSegment pLine
 
'  pSegcoll.AddSegment pLine.ToPoint
  pGeometryCollection.AddGeometry pSegcoll
 
  'pLine.FromPoint = pStartPoint
  'pLine.ToPoint = pEndPoint
   Dim pStartPoint2 As IPoint
  Set pStartPoint2 = New Point
  pStartPoint2.PutCoords 0, -60
  FromPoint = pStartPoint2
 
  Dim pEndPoint2 As IPoint
  Set pEndPoint2 = New Point
  pEndPoint2.PutCoords 10, 60
  ToPoint = pEndPoint2


Dim pLine2 As ILine
  Set pLine2 = New Line
pLine2.PutCoords pStartPoint2, pEndPoint2
 
  pSegcoll.AddSegment pLine2

pGeometryCollection.AddGeometry pSegcoll


    Dim pStartPoint3 As IPoint
  Set pStartPoint3 = New Point
  pStartPoint3.PutCoords 10, 60
  FromPoint = pStartPoint3
 
  Dim pEndPoint3 As IPoint
  Set pEndPoint3 = New Point
  pEndPoint3.PutCoords 117, 0
  ToPoint = pEndPoint3


Dim pLine3 As ILine
  Set pLine3 = New Line
pLine3.PutCoords pStartPoint3, pEndPoint3
 
pSegcoll.AddSegment pLine3

pGeometryCollection.AddGeometry pSegcoll


  pElement.Geometry = pGeometryCollection

 
  pGraphicsContainer.AddElement pElement, 0
  'pGraph.AddElement pElement, 0
 
  pMxDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing

 

End Sub

I am now in the process of writing this in JAVA.
Guy
0 Kudos