阅读:1646回复:2
生成多边形的问题?请各位高手帮忙!
如我现在知道6个点的坐标,如何将这6个点生成一个多边形?
|
|
1楼#
发布于:2005-11-18 11:12
<P>下面的函数可以帮助你完成任务</P>
<P>Sub ConvexHull()<BR> ' creates a polygon based on the convex hull of selected points<BR> ' in layer(0) and adds the polygon to the current edit target layer<BR> <BR> Dim pMxDoc As IMxDocument<BR> Set pMxDoc = ThisDocument<BR> <BR> Dim pFSel As IFeatureSelection<BR> Set pFSel = pMxDoc.FocusMap.Layer(0)<BR> <BR> If pFSel.SelectionSet.Count < 3 Then<BR> Debug.Print "not enough points selected"<BR> Exit Sub<BR> End If<BR> <BR> Dim pPolygon As IPolygon<BR> Set pPolygon = GetConvexHull(pFSel)<BR> If pPolygon Is Nothing Then Exit Sub<BR> <BR> Dim pUID As New UID<BR> pUID.Value = "esricore.Editor"<BR> <BR> Dim pEditor As IEditor<BR> Set pEditor = Application.FindExtensionByCLSID(pUID)<BR> <BR> If pEditor.EditState <> esriStateEditing Then<BR> Debug.Print "not editing"<BR> Exit Sub<BR> End If<BR> <BR> Dim pEL As IEditLayers<BR> Set pEL = pEditor<BR> <BR> If pEL.CurrentLayer.FeatureClass.ShapeType <> esriGeometryPolygon Then<BR> Debug.Print "target layer is not polygon"<BR> Exit Sub<BR> End If<BR> <BR> Dim pFeat As IFeature<BR> Set pFeat = pEL.CurrentLayer.FeatureClass.CreateFeature<BR> <BR> Set pFeat.Shape = pPolygon<BR> pFeat.Store<BR> pMxDoc.ActiveView.Refresh<BR>End Sub<BR><BR>Function GetConvexHull(pFSel As IFeatureSelection) As IPolygon<BR> Dim pGeomColl As IGeometryCollection<BR> Set pGeomColl = New Multipoint<BR> <BR> Dim pFCur As IFeatureCursor<BR> pFSel.SelectionSet.Search Nothing, True, pFCur<BR> Dim pFeat As IFeature<BR> Set pFeat = pFCur.NextFeature<BR> Do While Not pFeat Is Nothing<BR> pGeomColl.AddGeometry pFeat.ShapeCopy<BR> Set pFeat = pFCur.NextFeature<BR> Loop<BR> <BR> Dim pTopoOp As ITopologicalOperator<BR> Set pTopoOp = pGeomColl<BR> Dim pGeom As IGeometry<BR> Set pGeom = pTopoOp.ConvexHull<BR> <BR> If Not pGeom.GeometryType = esriGeometryPolygon Then<BR> Debug.Print "maybe the points were colinear?"<BR> Exit Function<BR> End If<BR> Set GetConvexHull = pGeom<BR>End Function<BR></P> |
|
|
2楼#
发布于:2005-11-21 16:18
<img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em04.gif" /><img src="images/post/smile/dvbbs/em05.gif" />
|
|