My Blog List

Tuesday, August 30, 2011

SW Gas: What shape is a polygon anyway?

Well, I found out today that a polygon is NOT just an envelope.  I was trying to create a polygon from an envelope that I had, and that didn't work.  I guess this isn't too surprising.  You actually have to create a new Polygon class and populate it from the envelope.  I wrote some VBA code to test this.


Private Sub MakeIsoationPoly(env As IEnvelope, fc As IFeatureClass)
Dim app As IApplication
Set app = New AppRef
Dim edExt As IEditor
Set edExt = app.FindExtensionByName("ESRI OBJECT EDITOR")
edExt.StartOperation
Dim newFe As IFeature
Set newFe = fc.CreateFeature
Dim segCol As ISegmentCollection
Set segCol = New Polygon
Dim ln1 As ILine, ln2 As ILine, ln3 As ILine, ln4 As ILine
Set ln1 = New Line
Set ln2 = New Line
Set ln3 = New Line
Set ln4 = New Line
ln1.FromPoint = env.LowerLeft
ln1.ToPoint = env.LowerRight
ln2.FromPoint = env.LowerRight
ln2.ToPoint = env.UpperRight
ln3.FromPoint = env.UpperRight
ln3.ToPoint = env.UpperLeft
ln4.FromPoint = env.UpperLeft
ln4.ToPoint = env.LowerLeft
segCol.AddSegment ln1
segCol.AddSegment ln2
segCol.AddSegment ln3
segCol.AddSegment ln4

Set newFe.Shape = segCol
newFe.Store
edExt.StopOperation ("Make polygon")

End Sub

No comments:

Post a Comment