📄 projector.frm
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1
Caption = "Projector Sample"
ClientHeight = 8595
ClientLeft = 885
ClientTop = 1035
ClientWidth = 6795
LinkTopic = "Form1"
ScaleHeight = 8595
ScaleWidth = 6795
Begin VB.CommandButton CmdRemoveLyr
Caption = "Remove Layer"
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 14
Top = 720
Width = 1455
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 6000
Top = 4440
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton CmdExport
Caption = "Export Layer Projected"
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 13
Top = 2640
Width = 1455
End
Begin VB.CommandButton CmdReadPRJ
Caption = "Read PRJ File"
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 12
Top = 2040
Width = 1455
End
Begin VB.CommandButton CmdFullExt
Caption = "Full Extent"
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 8
Top = 1440
Width = 1455
End
Begin VB.CommandButton CmdSetMapCS
Caption = "Set Map Coordinate System"
Height = 615
Left = 5280
Style = 1 'Graphical
TabIndex = 7
Top = 3960
Width = 1455
End
Begin VB.CommandButton CmdSetLyrCS
Caption = "Set Layer Coordinate System"
Height = 615
Left = 3600
Style = 1 'Graphical
TabIndex = 6
Top = 3960
Width = 1455
End
Begin VB.ComboBox CboCS
Height = 315
Left = 3600
TabIndex = 4
Text = "Combo1"
Top = 3480
Width = 3135
End
Begin VB.Frame Frame1
Height = 1335
Left = 120
TabIndex = 2
Top = 3360
Width = 3135
Begin VB.OptionButton OptCS
Caption = "File Coordinate System"
Height = 255
Index = 2
Left = 240
TabIndex = 11
Top = 960
Width = 2535
End
Begin VB.OptionButton OptCS
Caption = "Geographic Coordinate System"
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 600
Width = 2535
End
Begin VB.OptionButton OptCS
Caption = "Projected Coordinate System"
Height = 255
Index = 0
Left = 240
TabIndex = 3
Top = 240
Width = 2535
End
End
Begin VB.CommandButton CmdAddLyr
Caption = "Add Layer"
Height = 495
Left = 120
Style = 1 'Graphical
TabIndex = 1
Top = 120
Width = 1455
End
Begin MapObjects2.Map Map1
Height = 3135
Left = 1680
TabIndex = 0
Top = 120
Width = 5055
_Version = 131072
_ExtentX = 8916
_ExtentY = 5530
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Projector.frx":0000
End
Begin VB.Label LabCSMap
BackColor = &H0080FFFF&
Caption = "Map CoordSys:"
Height = 4935
Left = 3480
TabIndex = 10
Top = 4920
Width = 3255
End
Begin VB.Label LabCSLyr
BackColor = &H00FFFF80&
Caption = "Layer CoordSys:"
Height = 4935
Left = 120
TabIndex = 9
Top = 4920
Width = 3135
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ShpLayer As New MapObjects2.MapLayer
Dim StrsGCS As New MapObjects2.Strings
Dim StrsPCS As New MapObjects2.Strings
Dim CSfile As Object
Dim CSCompo As New MapObjects2.ProjCoordSys
Private Sub CmdExport_Click()
'Exports the layer (along with it's PRJ file) to the coordinate system of the map
'Set up the dialog to allow the user to save the shapefile out
CommonDialog1.Filter = "ESRI Shapefiles (*.shp)|*.shp"
'Set cancel error so that if cancel is used then we can trap it and exit
CommonDialog1.CancelError = True
On Error GoTo ErrorTrap
CommonDialog1.ShowSave
If Len(CommonDialog1.filename) = 0 Then Exit Sub
Screen.MousePointer = vbHourglass
'Export the layer's records to the Coordinatesystem currently set for the map
ShpLayer.Records.Export CommonDialog1.filename, Map1.CoordinateSystem
Screen.MousePointer = vbDefault
Exit Sub
ErrorTrap:
If Err.Number <> 32755 Then 'Error is something other than Cancel
MsgBox Err.Description, vbCritical
End If
Exit Sub
End Sub
Private Sub CmdFullExt_Click()
Map1.Extent = Map1.FullExtent
End Sub
Private Sub CmdReadPRJ_Click()
Dim DC As New MapObjects2.DataConnection
' Dim StrPath As String
Dim strCSType As String
CommonDialog1.CancelError = True
On Error GoTo ErrorTrap
CommonDialog1.Filter = "PRJ Files (*.prj)|*.prj|AI PRJ Files (prj.adf)|prj.adf|All Files (*.*)|*.*"
CommonDialog1.ShowOpen
DC.Database = CurDir & "\"
If Not DC.Connect Then
MsgBox "Could not connect to database" & Chr(13) & DC.ConnectError
Else
If Right(CommonDialog1.FileTitle, 3) = "adf" Then
Set CSfile = DC.FindArcInfoCoordinateSystem(CommonDialog1.FileTitle)
Else
Set CSfile = DC.FindCoordinateSystem(CommonDialog1.FileTitle)
End If
If CSfile Is Nothing Then
MsgBox "Not a valid projection file", vbExclamation
OptCS(2).Enabled = False
Else
If CSfile.IsProjected Then
strCSType = "Projected Coordinate System"
Else
strCSType = "Geographic Coordinate System"
End If
MsgBox "Created new " & strCSType & vbNewLine & vbNewLine & "Name: " & CSfile.Name & vbNewLine & "Type: " & CSfile.Type
OptCS(2).Enabled = True
OptCS(2).Value = True
End If
End If
Exit Sub
ErrorTrap:
If Err.Number <> 32755 Then 'Error is something other than Cancel
MsgBox Err.Description, vbCritical
End If
Exit Sub
End Sub
Private Sub CmdRemoveLyr_Click()
' Clear all map layers from map
Map1.Layers.Clear
CmdAddLyr.Enabled = True
LabCSLyr.Caption = "Layer CoordSys: "
LabCSMap.Caption = "Map CoordSys: "
End Sub
Private Sub CmdSetLyrCS_Click()
'Check to see if custom type has been selected
If OptCS.Item(2).Value = True Then
ShpLayer.CoordinateSystem = CSfile
Else 'Otherwise create a new CS
'Dim an object which can later be set to either a ProjCoordSsys or a GeoCoordSys
Dim CSLayer As Object
'Has the user selected GeoCoordsys or ProjCoordSys
If OptCS.Item(0).Value = True Then
Set CSLayer = New MapObjects2.ProjCoordSys
Else
Set CSLayer = New MapObjects2.GeoCoordSys
End If
'Set the type of the Coordsys based upon a predefined value (from the CboCS - combobox)
CSLayer.Type = stripProj(CboCS.Text)
'Set the coordsys for the Layer
ShpLayer.CoordinateSystem = CSLayer
End If
'Enable the user to specify the Coordsys for the map, but prevent them from changing the layer's
CmdSetMapCS.Enabled = True
CmdExport.Enabled = True
Map1.Refresh
'CmdSetLyrCS.Enabled = False
ReportLyrCS ShpLayer.CoordinateSystem
End Sub
Private Sub CmdSetMapCS_Click()
'Check to see if custom type has been selected
If OptCS.Item(2).Value = True Then
Map1.CoordinateSystem = CSfile
Else 'Otherwise create a new CS
'Dim an object which can later be set to either a ProjCoordSsys or a GeoCoordSys
Dim CSMap As Object
'Has the user selected GeoCoordsys or ProjCoordSys
If OptCS.Item(0).Value = True Then
Set CSMap = New MapObjects2.ProjCoordSys
Else
Set CSMap = New MapObjects2.GeoCoordSys
End If
'Set the type of the Coordsys based upon a predefined value (from the CboCS - combobox)
CSMap.Type = stripProj(CboCS.Text)
'Set the coordsys for the Map (this will cause the map to refresh)
Map1.CoordinateSystem = CSMap
End If
'Allow the user to export the Map's CS
ReportMapCS Map1.CoordinateSystem
End Sub
Private Sub Form_Load()
'This takes a while - let me entertain you...
Form2.Show
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -