阅读:1718回复:3
AO如何实现几何体边界的光滑???
<P><STRONG><FONT color=#000066>我想通过AO对POLYGON的边界进行光滑处理,只能找到Smooth 方法这个方法对Polygon和Ring的边界的光滑处理会出现重叠的现象 ,有没有那位仁兄做过相关的程序,或者能不能给点思路,谢谢!!!</FONT></STRONG></P>
[此贴子已经被作者于2005-8-5 0:00:34编辑过]
|
|
1楼#
发布于:2005-08-05 00:06
Beg for your help!
|
|
2楼#
发布于:2005-08-05 17:30
<P>看看下面</P>
<P>Option Explicit<BR>Private Sub UIButtonControl1_Click()<BR> '<BR> ' smooth each ring of each selected polygon<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> MsgBox "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 "not a polygon layer"<BR> Exit Sub<BR> End If<BR> <BR> Dim pFSel As IFeatureSelection<BR> Set pFSel = pEL.CurrentLayer<BR> If pFSel.SelectionSet.Count = 0 Then<BR> Debug.Print "nothing selected"<BR> Exit Sub<BR> End If<BR> Dim pFCur As IFeatureCursor<BR> pFSel.SelectionSet.Search Nothing, False, pFCur<BR> <BR> Dim pMxDoc As IMxDocument<BR> Set pMxDoc = ThisDocument<BR> Dim pAV As IActiveView<BR> Set pAV = pMxDoc.FocusMap<BR> Dim dMaxOffset As Double<BR> dMaxOffset = GetMaxOffset(pAV)<BR> <BR> pEditor.StartOperation<BR> Dim pFeat As IFeature<BR> Set pFeat = pFCur.NextFeature<BR> Do While Not pFeat Is Nothing<BR> SmoothPolygon pFeat, dMaxOffset<BR> Set pFeat = pFCur.NextFeature<BR> Loop<BR> pEditor.StopOperation "SmoothPolygon"<BR> <BR> Dim lCacheID As Long<BR> lCacheID = pAV.ScreenCacheID(esriViewGeoSelection, Nothing)<BR> pAV.ScreenDisplay.Invalidate Nothing, True, lCacheID<BR>End Sub<BR><BR>Function GetMaxOffset(pAV As IActiveView) As Double<BR> Dim pNDlg As INumberDialog<BR> Set pNDlg = New NumberDialog<BR> Dim dDefault As Double<BR> dDefault = pAV.ScreenDisplay.DisplayTransformation.FittedBounds.Width / 100#<BR> If pNDlg.DoModal("Smooth", dDefault, 2, 0) Then<BR> GetMaxOffset = Abs(pNDlg.Value)<BR> Else<BR> GetMaxOffset = dDefault<BR> End If<BR>End Function<BR><BR>Sub SmoothPolygon(pFeat As IFeature, dMaxOffset As Double)<BR> Dim pInGeomColl As IGeometryCollection<BR> Set pInGeomColl = pFeat.ShapeCopy<BR> <BR> Dim pOutGeomColl As IGeometryCollection<BR> Set pOutGeomColl = New Polygon<BR> <BR> ' for each exterior ring (ring implements IPath)<BR> Dim l As Long<BR> For l = 0 To pInGeomColl.GeometryCount - 1<BR> Dim pClone As IClone<BR> Set pClone = pInGeomColl.Geometry(l)<BR> Dim pPath As IPath<BR> Set pPath = pClone.Clone<BR> On Error Resume Next<BR> pPath.Smooth 0 ' dMaxOffset<BR> If Err = 0 Then<BR> Dim pTopoOp As ITopologicalOperator<BR> Set pTopoOp = pPath<BR> pTopoOp.Simplify<BR> pOutGeomColl.AddGeometry pPath<BR> Else<BR> ' I guess the maxoffset is too large for the size of the ring?<BR> pOutGeomColl.AddGeometry pInGeomColl.Geometry(l)<BR> Err.Clear<BR> End If<BR> Next l<BR> Set pFeat.Shape = pOutGeomColl<BR> pFeat.Store<BR><BR>End Sub<BR></P> |
|
|
3楼#
发布于:2005-08-06 00:28
<P>Thanks a lot!!!</P>
<P>不过,这个Smooth的平滑就是相邻的边界就是会出错 ,我找了好久都没合适的办法…………不知道有没有更合理方法可以实现的???</P> <P><IMG src="http://www.mingxu.com/02gis/test1.bmp.jpg" border=0></P> [此贴子已经被作者于2005-8-6 0:50:32编辑过]
|
|