Products: ArcView Minimum ArcGIS Release: 9.3 |
How to use:
- Make sure to add a reference to the ESRI DefenseSolutions Object Library.
- Paste the code into VBA.
- Run the function from the Macros dialog.
- Select the GeoPolygonElement graphic and drag it to another location in the map and note how it changes.
Public Sub
MakeGeoPolygon()
'get the MxDocument and ActiveView
Dim
pDocAs
IMxDocument
Set
pDoc = ThisDocument
Dim
pViewAs
IActiveView
Set
pView = pDoc.ActiveView
Dim
pMapAs
IMap
Set
pMap = pView.FocusMap
'Create the base polygon geometry.
Dim
pCollAs
IPointCollection4
Set
pColl =New
Polygon
Dim
pPointAs
IPoint
Set
pPoint =New
Point
pPoint.PutCoords 0, 63
pColl.AddPoint pPoint
pPoint.PutCoords 7, 51
pColl.AddPoint pPoint
pPoint.PutCoords 14, 63
pColl.AddPoint pPoint
pPoint.PutCoords 24, 56
pColl.AddPoint pPoint
pPoint.PutCoords 33, 74
pColl.AddPoint pPoint
pPoint.PutCoords 17, 68
pColl.AddPoint pPoint
Dim
pPolyAs
IPolygon4
Set
pPoly = pColl
pPoly.Close
'Set the spatial reference to that of the map
Dim
pSRMapAs
ISpatialReference
Set
pSRMap = pMap.SpatialReference
Set
pPoly.SpatialReference = pSRMap
'Create the GeoPolygon object and set its base geometry to the original polygon
Dim
pGeoPolyAs
IGeoPolygon
Set
pGeoPoly =New
GeoPolygon
pGeoPoly.Polygon = pPoly
'Set the properties of the GeoPolygon.
'
'Base spatial reference
Set
pGeoPoly.BaseSpatialReference = pMap.SpatialReference
'geodesy geometry type for the line segments comprising the GeoPolygon.
pGeoPoly.SpecialGeolineType = cjmtkSGTGeodesic
'Create a GeoPolygonElement graphic element and set its geometry using the GeoPolygon.
Dim
pElementAs
IElement
Set
pElement =New
GeoPolygonElement
pElement.Geometry = pGeoPoly
'Add the graphic to the map.
Dim
pGraphAs
IGraphicsContainer
Set
pGraph = pView.GraphicsContainer
pGraph.AddElement pElement, 0
pView.Refresh
End Sub