阅读:1743回复:2
编辑时的snapping
<P>在ArcMap中编辑工具条上有snapping的功能,请问在AE中用哪些接口可以实现该功能?</P>
|
|
1楼#
发布于:2007-05-24 11:37
<P>捕捉的要素的类型比较多,那你需要写的代码和用的接口也会更多</P>
<P>看看下面的例子,或许 有点帮助</P> <P>The following code snaps the Polygon drawn nearest to another polygon. One map Unit Search Tolerance is set (pSr = 1)for finding nearest vertex. Draw a polygon close to another polygon and select the drawn polygon. Run the code, it will create another polygon which is snapped to the nearest polygon. Set the tolerances according to your data. Also modify the code to call it in your OnCreateFeature Method. Hope this works for you. <BR><BR>Checked on Polygon Shape file and works fine for me with the set tolerance. Also change pEnv.Expand 3,3,False to suit your data if does not work. Ensure that you digize the polygon such that you have a vertex nearer to the existing polygon to get better results. see attached image. <BR><BR><BR>Private Sub SnapFeatures() <BR>Dim pMx As IMxDocument <BR>Dim pEnum As IEnumFeature <BR>Dim pFeat As IFeature <BR>Dim pPointColl As IPointCollection <BR>Dim pPoint As IPoint <BR>Dim pTPoint As IPoint <BR>Dim pGeom As IGeometry <BR>Dim pSr As Double, pDist As Double, pInx As Long, pSeg As Long <BR>Dim pHit As IHitTest <BR>pSr = 1 <BR><BR>Set pMx = ThisDocument <BR>Set pEnum = pMx.FocusMap.FeatureSelection <BR>Set pFeat = pEnum.Next <BR>Set pPoint = New point <BR>If Not pFeat Is Nothing Then <BR>Set pPointColl = pFeat.Shape <BR>Dim pTopo As ITopologicalOperator <BR>Dim pSF As ISpatialFilter <BR>Dim pFeatCls As IFeatureClass <BR>Dim pFeatcur As IFeatureCursor <BR>Dim pEnv As IEnvelope <BR>Dim pFeature As IFeature <BR><BR>Set pFeatCls = pFeat.Class <BR>Set pSF = New SpatialFilter <BR>Set pEnv = pFeat.Shape.Envelope <BR>pEnv.Expand 3, 3, False <BR>Set pSF.Geometry = pEnv <BR>pSF.GeometryField = "Shape" <BR>pSF.SpatialRel = esriSpatialRelEnvelopeIntersects <BR><BR>Set pFeatcur = pFeatCls.Search(pSF, False) <BR>Set pFeature = pFeatcur.NextFeature <BR>Do While Not pFeature Is Nothing <BR>Set pHit = pFeature.Shape <BR>If pFeature.oid <> pFeat.oid Then <BR>For i = 0 To pPointColl.PointCount - 1 <BR>Set pTPoint = pPointColl.point(i) <BR>bFlag = pHit.HitTest(pPointColl.point(i), pSr, esriGeometryPartVertex, pPoint, pDist, pInx, pSeg, False) <BR>If bFlag = True Then <BR>pPointColl.UpdatePoint i, pPoint <BR>Debug.Print "Vertex Moved to Vertex" <BR>Else <BR>bFlag = pHit.HitTest(pPointColl.point(i), pSr, esriGeometryPartBoundary, pPoint, pDist, pInx, pSeg, False) <BR>If bFlag = True Then <BR>pPointColl.UpdatePoint i, pPoint <BR>Debug.Print "Vertex moved to Edge" <BR>End If <BR>End If <BR>Next i <BR>End If <BR>Set pFeature = pFeatcur.NextFeature <BR>Loop <BR>End If <BR><BR>Dim ppoly As IPolygon <BR>Set ppoly = New Polygon <BR>Set ppoly = pPointColl <BR>Set pFeat.Shape = ppoly <BR>pFeat.Store <BR><BR>End Sub <BR></P> |
|
|
2楼#
发布于:2007-05-24 11:39
<P>上述程序的效果图</P>
<P><IMG src="http://forums.esri.com/Attachments/19403.JPG"></P> |
|
|