| 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 SubMakeGeoPolygon()
'get the MxDocument and ActiveView
DimpDocAsIMxDocument
SetpDoc = ThisDocument
DimpViewAsIActiveView
SetpView = pDoc.ActiveView
DimpMapAsIMap
SetpMap = pView.FocusMap
'Create the base polygon geometry.
DimpCollAsIPointCollection4
SetpColl =NewPolygon
DimpPointAsIPoint
SetpPoint =NewPoint
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
DimpPolyAsIPolygon4
SetpPoly = pColl
pPoly.Close
'Set the spatial reference to that of the map
DimpSRMapAsISpatialReference
SetpSRMap = pMap.SpatialReference
SetpPoly.SpatialReference = pSRMap
'Create the GeoPolygon object and set its base geometry to the original polygon
DimpGeoPolyAsIGeoPolygon
SetpGeoPoly =NewGeoPolygon
pGeoPoly.Polygon = pPoly
'Set the properties of the GeoPolygon.
'
'Base spatial reference
SetpGeoPoly.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.
DimpElementAsIElement
SetpElement =NewGeoPolygonElement
pElement.Geometry = pGeoPoly
'Add the graphic to the map.
DimpGraphAsIGraphicsContainer
SetpGraph = pView.GraphicsContainer
pGraph.AddElement pElement, 0
pView.Refresh
End Sub
浙公网安备 33010602011771号