gchwang
路人甲
路人甲
  • 注册日期2005-08-01
  • 发帖数11
  • QQ
  • 铜币156枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1646回复:2

生成多边形的问题?请各位高手帮忙!

楼主#
更多 发布于:2005-11-17 15:12
如我现在知道6个点的坐标,如何将这6个点生成一个多边形?
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
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>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
gchwang
路人甲
路人甲
  • 注册日期2005-08-01
  • 发帖数11
  • QQ
  • 铜币156枚
  • 威望0点
  • 贡献值0点
  • 银元0个
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" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部