阅读:3118回复:7
求助:怎样用polyline来切割多边形(有源码)
<P>我要将图中得多边形用图中得红线切割,不知道怎么作,我用ITopologicalOperator得cut,切出来很差,数据都乱了套,那位大虾帮忙指点一下,谢了!</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em12.gif" /><img src="images/post/smile/dvbbs/em11.gif" />
[此贴子已经被作者于2005-8-26 11:44:16编辑过]
|
|
1楼#
发布于:2005-08-26 11:35
怎么没人关注么?我看了Engine的帮助,好像Split和clip都可以切割多边形,但是不知道具体该怎么作,那位大虾做过,点评一下
|
|
2楼#
发布于:2005-08-26 11:42
<P>Private Sub CutPolygon()<BR> Dim pPolygonlyr As IFeatureLayer<BR> Dim pPolygonCls As IFeatureClass<BR> Dim pCutLyr As IFeatureLayer<BR> Dim pCutCls As IFeatureClass<BR> Dim pLayer As ILayer<BR> Dim pPolygonCur As IFeatureCursor<BR> Dim pPolygonFeat As IFeature<BR> Dim pCutFeat As IFeature<BR> Dim pGeometry As IGeometry<BR> Dim pLeftCut As IGeometry<BR> Dim pRightCut As IGeometry<BR> Dim pCut As IPolyline<BR> Dim pTopoOp As ITopologicalOperator<BR> Dim pCutCur As IFeatureCursor<BR> Dim i As Integer, j As Integer<BR> Dim n As Long<BR> Set pLayer = MapControl1.Layer(0)<BR> Set pCutLyr = pLayer<BR> Set pCutCls = pCutLyr.FeatureClass<BR> Set pLayer = MapControl1.Layer(1)<BR> Set pPolygonlyr = pLayer<BR> Set pPolygonCls = pPolygonlyr.FeatureClass<BR> Set pPolygonCur = pPolygonCls.Search(Nothing, False)<BR> Set pPolygonFeat = pPolygonCur.NextFeature<BR> Do While Not pPolygonFeat Is Nothing<BR> Set pGeometry = pPolygonFeat.Shape<BR> Set pTopoOp = pGeometry<BR> Dim pFilter As ISpatialFilter<BR> Set pFilter = New SpatialFilter<BR> With pFilter<BR> Set .Geometry = pGeometry<BR> .GeometryField = "SHAPE"<BR> .SpatialRel = esriSpatialRelContains<BR> End With<BR> <BR> Set pCutCur = pCutCls.Search(pFilter, False)<BR> Set pCutFeat = pCutCur.NextFeature<BR> Do While Not pCutFeat Is Nothing<BR> If pCutFeat.Shape.GeometryType = esriGeometryPolyline Then<BR> Set pCut = pCutFeat.Shape<BR> <BR> Set pLeftCut = New Polygon<BR> Set pRightCut = New Polygon<BR> pTopoOp.Cut pCut, pLeftCut, pRightCut<BR> If (Not pLeftCut.IsEmpty) And (Not pRightCut.IsEmpty) Then<BR> Dim pNewfeature As IFeature<BR> Set pNewfeature = pPolygonCls.CreateFeature<BR> <BR> 'copy the feature's attributes<BR> Dim FieldCountFrom As Integer<BR> Dim FieldCountTo As Integer<BR> FieldCountFrom = pPolygonFeat.Fields.FieldCount - 1<BR> FieldCountTo = pNewfeature.Fields.FieldCount - 1</P>
<P> <BR> For i = 0 To FieldCountFrom<BR> On Error Resume Next<BR> If (Not pPolygonFeat.Fields.Field(i).Type = esriFieldTypeGeometry) And (Not pPolygonFeat.Fields.Field(i).Type = esriFieldTypeOID) Then<BR> 'match field names before copying over the attribute info<BR> For j = 0 To FieldCountTo<BR> If Not (UCase(pNewfeature.Fields.Field(j).Name) = "PNUM") Then<BR> <BR> If (UCase(pNewfeature.Fields.Field(j).Name) = UCase(pPolygonFeat.Fields.Field(i).Name)) Then<BR> pNewfeature.Value(j) = pPolygonFeat.Value(i) 'copying the attribute value<BR> End If<BR> End If<BR> Next j<BR> End If<BR> Next i<BR> 'copy over the feature's shape<BR> Set pNewfeature.Shape = pLeftCut<BR> pNewfeature.Store<BR> <BR> Set pNewfeature.Shape = pRightCut<BR> pNewfeature.Store<BR> Debug.Print pPolygonFeat.OID<BR>' pPolygonFeat.Delete<BR> n = n + 1<BR> End If<BR> End If<BR> Set pCutFeat = pCutCur.NextFeature<BR> <BR> Loop<BR> Set pPolygonFeat = pPolygonCur.NextFeature<BR> Loop<BR> MsgBox "处理完毕!共分割" ; n ; "个对象", vbInformation<BR>End Sub</P> |
|
3楼#
发布于:2005-08-26 11:48
<P>这里的空间过滤对象设置可能有点问题,我用的是包含,红线可能在两头不及或穿越,所以不知道该怎么设置这个属性,Overlap意思是部分覆盖,但是好像是对多边形</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em08.gif" />
|
|
4楼#
发布于:2005-08-27 20:25
不会把,居然没人关注
|
|
5楼#
发布于:2005-08-28 10:19
帮顶了
|
|
|
6楼#
发布于:2005-08-28 10:51
<P>用相交就可以了吧</P>
|
|
|
7楼#
发布于:2005-08-29 22:17
对的,用相交,我这里已经搞定了<img src="images/post/smile/dvbbs/em03.gif" /><img src="images/post/smile/dvbbs/em04.gif" />
|
|