shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
阅读:3118回复:7

求助:怎样用polyline来切割多边形(有源码)

楼主#
更多 发布于:2005-08-25 21:55
<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" /><br>
[此贴子已经被作者于2005-8-26 11:44:16编辑过]
喜欢0 评分0
shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
1楼#
发布于:2005-08-26 11:35
怎么没人关注么?我看了Engine的帮助,好像Split和clip都可以切割多边形,但是不知道具体该怎么作,那位大虾做过,点评一下
举报 回复(0) 喜欢(0)     评分
shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
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>
举报 回复(0) 喜欢(0)     评分
shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
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" />
举报 回复(0) 喜欢(0)     评分
shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
4楼#
发布于:2005-08-27 20:25
不会把,居然没人关注
举报 回复(0) 喜欢(0)     评分
木白林
路人甲
路人甲
  • 注册日期2004-03-19
  • 发帖数319
  • QQ
  • 铜币824枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2005-08-28 10:19
帮顶了
心情卡片 一起分享...
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
6楼#
发布于:2005-08-28 10:51
<P>用相交就可以了吧</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
shixcn
外卖仔
外卖仔
  • 注册日期2003-11-02
  • 发帖数73
  • QQ
  • 铜币180枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
7楼#
发布于:2005-08-29 22:17
对的,用相交,我这里已经搞定了<img src="images/post/smile/dvbbs/em03.gif" /><img src="images/post/smile/dvbbs/em04.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部