使用MapObjects绘制缓冲区

       MapObjects使用Buffer函数生成缓冲区,并返回一个pologon。需要注意的是,Buffer函数的第二个参数,即一个地图范围,通常设置为Map.Extent,但该extent必须能够包含所生成的缓冲区,否则缓冲区无法生成,返回null。

       为避免缓冲区生成失败,可以认为设定Buffer的extent参数。以点状shape的缓冲区生成为例,可以获取缓冲区的包络矩形的范围,然后使得extent参数的范围能够完全容纳这个矩形即可。


代码如下


    If listCity.Text <> "" Then
        Dim distance As Double '缓冲距离
        Dim leftside As Double
        Dim rightside As Double
        Dim topside As Double
        Dim bottomside As Double
        Dim rect As MapObjects2.Rectangle
        Dim p As MapObjects2.Point
        Dim city As New MapObjects2.Recordset
        
        distance = 1050000
       
        Set city = cityLayer.SearchExpression("mc = '" + listCity.Text + "'")  'mc = '" + listCity.Text + "'
        If Not city Is Nothing Then
            city.MoveFirst
            If Not city.EOF Then
                Set p = city.Fields("shape").Value
                
                MsgBox (p.X)
                leftside = p.X - distance
                rightside = p.X + distance
                topside = p.Y + distance
                bottomside = p.Y - distance
                
                Set rect = New Rectangle
                
                If leftside < map.Extent.Left Then
                    rect.Left = leftside - 1 '不能重叠,所以-1
                Else
                    rect.Left = map.Extent.Left
                End If
                
                If rightside > map.Extent.Right Then
                    rect.Right = rightside + 1
                Else: rect.Right = map.Extent.Right
                End If
                
                If topside > map.Extent.Top Then
                    rect.Top = topside + 1
                Else: rect.Top = map.Extent.Top
                End If
                
                If bottomside < map.Extent.Bottom Then
                    rect.Bottom = bottomside - 1
                Else: rect.Bottom = map.Extent.Bottom
                End If
                
'                map.Extent = rect
                'map.Refresh
                
                Set bufferCircle = p.Buffer(distance, rect)
                MsgBox (bufferCircle.Area)
            End If
        MsgBox (city.Count)
        MsgBox (listCity.Text)
         End If
    map.TrackingLayer.Refresh True
        
    Else
        MsgBox "请首先选中一个地级市!"
    End If
    
    
End Sub

注意,不能让缓冲区的包络矩形的一侧正好与extent重叠,否则无法生成,既extent要“真包含”这一矩形。在程序中,可适当加减一个数值即可,本例中为1.


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值