【2010-07-23-01】 ITopologicalOperator 需要知道的三点 (转)

转自:http://www.fovly.com/article.asp?id=455

When working with the ITopologicalOperator interface, there are 3 things that should be done.

1) QI over to ITopologicalOperator2 and set IsKnownSimple to False, then call Simplify. This should be done for ALL geometries involved.

2) ALL geometries involved should have a spatial reference set. If they don't, then set each geometry's spatial reference to that of the map or something (just set it). If ALL geometries involved do not have the SAME spatial reference, then project ALL geometries into the SAME spatial reference (doesn't matter which you use, just use one of them).

3) Call SnapToSpatialReference on all geometries involved.

After doing this, you will greatly increase your chances of making it through the operation without error. It does not work ALL of the time. ITopologicalOperator is one buggy interface, but doing the 3 things above every time you use it will cut down the number of errors you get significantly. Good luck.

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
// Here ' s some sample VB code that shows one way to do all
// of this.
Set pTopoOp = pPolygon1
pTopoOp.IsKnownSimple
= False
pTopoOp.Simplify

Set pTopoOp = pPolygon2
pTopoOp.IsKnownSimple
= False
pTopoOp.Simplify

If pPolygon1.SpatialReference Is Nothing Then
Set pPolygon1.SpatialReference = pMap.SpatialReference
End If

If pPolygon2.SpatialReference Is Nothing Then
Set pPolygon2.SpatialReference = pMap.SpatialReference
End If

pPolygon2.Project pPolygon1.SpatialReference

pPolygon1.SnapToSpatialReference
pPolygon2.SnapToSpatialReference

' now you can FINALLY do the Union.
Set pPolygon1 = pTopoOp.Union(pPolygon1)

' hopefully you get to here.
MsgBox " Done "

 

转载于:https://www.cnblogs.com/willwayer/archive/2010/07/23/1783493.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值