Imports System.IO
Imports AxMapWinGIS
Imports MapWinGIS
Imports System
Imports System.Text
Imports System.IO.FileInfo
Public Class Form1
Dim fileName As String
Dim objReader As StreamReader
Dim i As Integer
Private fdlg As OpenFileDialog = New OpenFileDialog()
Private Sub AxMap1_MouseDownEvent(sender As System.Object, e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
End Sub
Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged
AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomIn
End Sub
Private Sub RadioButton2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton2.CheckedChanged
AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomOut
End Sub
Private Sub RadioButton3_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton3.CheckedChanged
AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan
End Sub
Private Sub AddData_Click(sender As System.Object, e As System.EventArgs) Handles AddData.Click
'fdlg.Title = "Open File"
'fdlg.InitialDirectory = "c:\"
'fdlg.Filter = "ESRI Shapesfile (*.shp)|*.shp|All files (*.*)|*.*"
'fdlg.FilterIndex = 2
'fdlg.RestoreDirectory = True
'If fdlg.ShowDialog() = DialogResult.OK Then
Dim sf As New MapWinGIS.Shapefile
Dim grd As New MapWinGIS.Grid
Dim img As New MapWinGIS.Image
Dim fdlg As New OpenFileDialog
Dim k As String
Dim l As String
Dim p() As String = Split(fdlg.FileName, "\")
Dim a As Integer
Dim i As Integer
fdlg.Filter = "All Files (*.*)|*.*|" & sf.CdlgFilter & _
"|" & grd.CdlgFilter & "|" & img.CdlgFilter
If fdlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
'If the user didn't cancel the dialog, try to open the file.
'First, determine what kind it was:
Dim extension As String = _
IO.Path.GetExtension(fdlg.FileName).ToLower()
Split(fdlg.FileName)
'l = fdlg.FileName.Substring(fdlg.FileName.LastIndexOf(".") + 1)
'k = fdlg.FileName.Substring(fdlg.FileName.LastIndexOf("\") + 1)
'p = k.Substring(k.LastIndexOf(".") + 1)
If sf.CdlgFilter.ToLower().Contains(extension) Then
'It's a shapefile
sf.Open(fdlg.FileName)
'i = Left(fdlg.FileName, Len(fdlg.FileName) - InStrRev(fdlg.FileName, "\"))
For i = 0 To p.Length - 1 Step 1
If p(i) <> "" Then
'LastNonEmpty += 1
'TestArray(LastNonEmpty) = TestArray(i)
MessageBox.Show(p(i))
End If
'TextBox1.Text = TestArray(i)
Next
CheckedListBox1.Items.Add(fdlg.FileName, True)
'CheckedListBox1.Items.Add(fdlg.FileName, True)
'Split(fdlg.FileName, "\", ".")
AxMap1.AddLayer(sf, True)
'OpenFileDialog1.ShowDialog()
'Process.Start(CheckedListBox1.Text)
'Zoom to all visible layers
AxMap1.ZoomToMaxExtents()
Return 'Done
ElseIf grd.CdlgFilter.ToLower().Contains(extension) Then
'NOTE: a .tif can be a GeoTIFF (a grid)
'or an image. Check this, if the file
'is a shp:
If fdlg.FileName.ToLower().EndsWith("shp") Then
If Not AxMap1.IsTIFFGrid(fdlg.FileName) Then
'It's an image, not a grid.
'Open it as an image.
img.Open(fdlg.FileName)
AxMap1.AddLayer(img, True)
'Zoom to all visible layers
AxMap1.ZoomToMaxExtents()
Return 'Done
End If
End If
'Open the grid:
grd.Open(fdlg.FileName)
'Define a coloring scheme to color this grid:
Dim sch As New MapWinGIS.GridColorScheme
'Use a predefined coloring scheme "Fall Leaves"
sch.UsePredefined(grd.Minimum, grd.Maximum, _
MapWinGIS.PredefinedColorScheme.FallLeaves)
'Convert it to an image that can be displayed:
Dim u As New MapWinGIS.Utils
Dim gridimage As MapWinGIS.Image
gridimage = u.GridToImage(grd, sch)
'Add the generated image to the map:
AxMap1.AddLayer(gridimage, True)
'Zoom to all visible layers
AxMap1.ZoomToMaxExtents()
Return 'Done
ElseIf img.CdlgFilter.ToLower().Contains(extension) Then
'It's a plain image
img.Open(fdlg.FileName)
AxMap1.AddLayer(img, True)
'Zoom to all visible layers
AxMap1.ZoomToMaxExtents()
Return 'Done
End If
End If
'End If
End Sub
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Shell("Notepad.exe", AppWinStyle.NormalNoFocus, False, -1)
Dim dlg As New OpenFileDialog
For i = CheckedListBox1.Items.Count - 1 To 0 Step -1
If (CheckedListBox1.GetItemChecked(i)) Then
OpenFileDialog1.ShowDialog()
'TextBox1.Text = OpenFileDialog1.FileName
CheckedListBox2.Items.Add(OpenFileDialog1.FileName)
'TextBox1.Text = fdlg.FileName - ".shp" + ".dbf"
'TextBox1.Text = OpenFileDialog1.FileName
'OpenFileDialog1.ShowDialog()
'If (CheckedListBox1.GetItemChecked(i)) Then
'Process.Start(TextBox1.Text)
End If
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Dim TestString As String = "test 117"
'Dim TestArray() As String = Split(fdlg.FileName, "/")
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
'Dim LastNonEmpty As Integer = -1
'For i As Integer = 0 To TestArray.Length - 1
'If TestArray(i) <> "" Then
'LastNonEmpty += 1
'TestArray(LastNonEmpty) = TestArray(i)
'End If
'TextBox1.Text = TestArray(i)
'MessageBox.Show(TestArray(i))
'Next
CheckedListBox2.Text = OpenFileDialog1.FileName
'ReDim Preserve TestArray(LastNonEmpty)
End Sub
Private Sub OpenFileDialog1_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
'TextBox1.Text = OpenFileDialog1.FileName
'CheckedListBox2.Text = OpenFileDialog1.FileName
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
'Dim sf As New MapWinGIS.Shapefile
'Dim grd As New MapWinGIS.Grid
'Dim img As New MapWinGIS.Image
'Dim fdlg As New OpenFileDialog
Dim i As Integer
For i = (CheckedListBox1.Items.Count - 1) To 0 Step -1
If (Not CheckedListBox1.GetItemChecked(i)) Then
'AxMap1.RemoveLayer(CheckedListBox1.SelectedIndex)
AxMap1.RemoveLayer(i)
CheckedListBox1.Items.RemoveAt(i)
'CheckedListBox1.Items.RemoveAt(CheckedListBox1.SelectedIndex)
End If
If (CheckedListBox1.Items.Count = 0) Then
AxMap1.RemoveAllLayers()
End If
Next
'Dim a As Integer
'CheckedListBox1.SelectedItem = True
'If CheckedListBox1.SelectedIndex = False Then
'AxMap1.RemoveLayer(CheckedListBox1.SelectedIndex)
'Else
'AxMap1.AddLayer(sf, True)
'End If
End Sub
Private Sub CheckedListBox1_SelectedValueChanged(sender As Object, e As System.EventArgs)
Dim sf As New MapWinGIS.Shapefile
Dim grd As New MapWinGIS.Grid
Dim img As New MapWinGIS.Image
Dim fdlg As New OpenFileDialog
Dim a As String = CheckedListBox1.SelectedItem
'For Each a In CheckedListBox1.SelectedItems
'AxMap1.AddLayer(sf, True)
'Next
'If CheckedListBox1.SelectedItem = False Then
'AxMap1.RemoveLayer(Left(fdlg.FileName, InStr(1, fdlg.FileName, "(", 1)))
'End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = (CheckedListBox1.Items.Count - 1) To 0 Step -1
If (Not CheckedListBox1.GetItemChecked(i)) Then
'AxMap1.RemoveLayer(CheckedListBox1.SelectedIndex)
AxMap1.RemoveLayer(i)
'CheckedListBox1.Items.RemoveAt(i)
'CheckedListBox1.Items.RemoveAt(CheckedListBox1.SelectedIndex)
End If
If (CheckedListBox1.Items.Count = 0) Then
AxMap1.RemoveAllLayers()
End If
'If (CheckedListBox1.CheckedItems.Count = 0) Then
'AxMap1.RemoveAllLayers()
'End If
Next
End Sub
Private Sub CheckedListBox1_Click(sender As Object, e As System.EventArgs) Handles CheckedListBox1.Click
Dim i As Integer
For i = (CheckedListBox1.Items.Count - 1) To 0 Step -1
If (Not CheckedListBox1.GetItemChecked(i)) Then
'AxMap1.RemoveLayer(CheckedListBox1.SelectedIndex)
AxMap1.RemoveLayer(i)
CheckedListBox1.Items.RemoveAt(i)
'CheckedListBox1.Items.RemoveAt(CheckedListBox1.SelectedIndex)
Else
' Dim lyrType As MapWindow.Interfaces.eLayerType
'lyrType = m_MapWin.Layers(Handle).LayerType
'If MapWindow.Interfaces.eLayerType.PolygonShapefile Or _
' MapWindow.Interfaces.eLayerType.PointShapefile Or _
' MapWindow.Interfaces.eLayerType.LineShapefile Then
End If
'AxMap1.get_GetObject(i)
'OpenFileDialog1.ShowDialog()
'TextBox1.Text = "C:\Users\X\Desktop\Shape file\line.dbf"
'TextBox1.Text = OpenFileDialog1.FileName
'Process.Start(TextBox1.Text)
'End If
If (CheckedListBox1.Items.Count = 0) Then
AxMap1.RemoveAllLayers()
End If
Next
End Sub
Private Sub CheckedListBox2_Click(sender As Object, e As System.EventArgs) Handles CheckedListBox2.Click
Dim i As Integer
For i = 0 To CheckedListBox2.Items.Count - 1 Step 1
If (CheckedListBox2.GetItemChecked(i)) Then
Process.Start(CheckedListBox2.Text)
End If
Next
End Sub
End Class