⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form02b.frm

📁 这是一个计算面积的程序
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form02b 
   Caption         =   "墨西哥地图"
   ClientHeight    =   5355
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7005
   LinkTopic       =   "Form1"
   ScaleHeight     =   5355
   ScaleWidth      =   7005
   StartUpPosition =   3  '窗口缺省
   Begin MapObjects2.Map Map1 
      Height          =   4815
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   6975
      _Version        =   131072
      _ExtentX        =   12303
      _ExtentY        =   8493
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "form02b.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   375
      Left            =   1560
      TabIndex        =   1
      Top             =   4920
      Width           =   3495
   End
End
Attribute VB_Name = "Form02b"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xuewei,2003/5/20
'计算矩形和所有州的交集;

Option Explicit
Dim resultShape(32) As MapObjects2.Polygon
Dim recSelection(32) As MapObjects2.Recordset
Dim rect As MapObjects2.Polygon
 
'把查找的区域用黄色显示,找到区域用红色显示;
Private Sub Map1_AfterLayerDraw(ByVal index As Integer, ByVal canceled As Boolean, ByVal hDC As stdole.OLE_HANDLE)
  Dim sym(32) As New MapObjects2.Symbol
  Dim sym1 As New MapObjects2.Symbol
  Dim Ri As Integer
    
  If Not rect Is Nothing Then
    sym1.Color = moYellow
    Map1.DrawShape rect, sym1
  End If
  
  For Ri = 1 To 32
    If Not resultShape(Ri) Is Nothing Then
      sym(Ri).Color = moRed
      Map1.DrawShape resultShape(Ri), sym(Ri)
    End If
  Next Ri
End Sub

Sub DrawLayer()
  Dim dc As New DataConnection
  Dim layer As MapLayer
  dc.Database = App.Path + "\..\" + "Mexico"
  If Not dc.Connect Then
    MsgBox "在指定的文件夹下没找到图层数据文件!"
    End
  End If
  
  Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("States")
  layer.Symbol.Color = moLimeGreen
  Map1.Layers.Add layer
  
  Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("Rivers")
  layer.Symbol.Color = moRed
  Map1.Layers.Add layer
  
  Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("Cities")
  layer.Symbol.Color = moBlue
  Map1.Layers.Add layer
End Sub

Private Sub Form_Load()
  DrawLayer
  Label1.Caption = "在地图上画多边形。"
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  Dim Am As Single
  Const Ak = 1000
  Dim intersectShape(32) As MapObjects2.Polygon
  Dim strExpression As String
  Dim Ri As Integer
   
  Set rect = Map1.TrackPolygon
  Am = 0
  For Ri = 1 To 32
    strExpression = "STATE_ID = " & Ri
    Set recSelection(Ri) = Map1.Layers("States").SearchExpression(strExpression)
    Set intersectShape(Ri) = recSelection(Ri).Fields("Shape").Value
    Set resultShape(Ri) = rect.Intersect(intersectShape(Ri))
    If Not resultShape(Ri) Is Nothing Then
      Am = resultShape(Ri).Area + Am
    End If
  Next Ri
  
  If Am < 0.001 Then
    Label1.Caption = "没有相交。"
  Else
    Label1.Caption = "相交面积=" & Format(Am * Ak, "0.00") & "平方公里。"
  End If
  
  Map1.Refresh
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -