' UTM2SVG.EXE source code ' Mike McCullough 2/28/03 'Public next_path As Integer 'Public m_line As Variant Public m_line As String Public OpenPath As Boolean Public centroids As String Public AtStart As Boolean Public min_x As Variant Public min_y As Variant Public max_x As Variant Public max_y As Variant Public m_x As Variant Public m_y As Variant Public CentroidSum As Variant Public coordSum As Variant Dim centroid() As String Dim coord() As String Public m_width As String Public m_height As String Private Sub Form_Load() DriveSourceLbl = DriveSource.Drive DriveTargetLbl = DriveTarget.Drive DirSourceLbl = DirSource.Path DirTargetLbl = DirTarget.Path FileSourceLbl = GetSourceFile.FileName ' next_path = 1 AtStart = True End Sub Private Sub DriveSource_Change() DriveSourceLbl = DriveSource.Drive DirSourceLbl = DriveSource.Drive DirSource.Path = DriveSource.Drive End Sub Private Sub DirSource_Change() GetSourceFile.Path = DirSource.Path DirSourceLbl = DirSource.Path End Sub Private Sub DriveTarget_Change() DriveTargetLbl = DriveTarget.Drive End Sub Private Sub DirTarget_Change() DirTargetLbl = DirTarget.Path End Sub Private Sub GetSourceFile_Click() m_filename = GetSourceFile.FileName If UCase(Right(m_filename, 5)) = "A.DAT" Then pos = InStr(m_filename, "a.dat") s_file = Left(m_filename, pos - 1) & ".dat" MsgBox "Please use " & s_file & " instead of " & m_filename & ". " & m_filename & " is the attribute file with legal or political unit numbers associated with each polygon. The next version of this utility will automatically incorporate this information into the 'id' attribute of each element. If you need these 'id' references now, edit the SVG document to include them." Else FileSourceLbl = GetSourceFile.FileName End If End Sub Private Sub MapMenu_Click() MsgBox "Directions:" & vbLf & vbLf & "1) Select the Source File Location and Source Filename by clicking on the appropriate boxes. The source file must be in ASCII/ungenerate format." & vbLf & vbLf & "2) Provide the Target File Location by clicking on the appropriate boxes. Type the name of the map file to be created into the 'Target Filename' box. (If you do not add the required .svg extension, it will be added automatically.) " & vbLf & vbLf & "3) Click the Make Map button." End Sub Private Sub cmdMakeMap_Click() Sum = 0 CentroidSum = 0 ReDim centroid(2, 0) ReDim coord(2, 0) If Right(DirSourceLbl.Text, 1) = "\" Then ' root directory m_SourceFile = DirSourceLbl.Text & FileSourceLbl.Text Else m_SourceFile = DirSourceLbl.Text & "\" & FileSourceLbl.Text End If Open m_SourceFile For Input Access Read As #1 Open "output.dat" For Append As #3 If UCase(Right(FileTargetLbl.Text, 4)) = ".SVG" Then Open DirTargetLbl.Text & "\" & FileTargetLbl.Text For Output As #2 Else Open DirTargetLbl.Text & "\" & FileTargetLbl.Text & ".svg" For Output As #2 End If 'Build centroid and coord arrays -- and calculations for viewbox Input #1, m_line 'MsgBox m_line & " outer len=" & Len(m_line) ParsePath (m_line) Do Until m_line = "END" Do Until m_line = "END" Input #1, m_line 'MsgBox m_line & " inner len=" & Len(m_line) ParseLine (m_line) Loop Input #1, m_line 'MsgBox m_line & " outer len=" & Len(m_line) ParsePath (m_line) Loop ' MsgBox Str(max_x) + " " + Str(max_y) + " " + Str(min_x) + " " + Str(min_y) m_width = Str(max_x - min_x) m_height = Str(max_y - min_y) viewBoxCoordinates = " " + Trim(Str(min_x)) + " -" + Trim(Str(max_y)) + " " + m_width + " " + m_height ' MsgBox viewBoxCoordinates ' Write the SVG file Print #2, "" Print #2, "" Print #2, "" rows = UBound(coord, 2) For n_row = 1 To rows If coord(1, n_row) = "PATH" Or coord(1, n_row) = "END" Then Print #2, coord(2, n_row) Else Print #2, " " + coord(1, n_row) + " -" + coord(2, n_row); End If Next n_row Print #2, "" Print #2, "" Close #1, #2 MsgBox "SVG Map has been created and saved. View it by loading into your browser." End Sub Function ParseLine(m_line) coordSum = coordSum + 1 ReDim Preserve coord(2, UBound(coord, 2) + 1) If m_line = "END" Then 'inner ENDs come here coord(1, coordSum) = "END" coord(2, coordSum) = "z' />" & vbCrLf ' MsgBox coord(2, coordSum) Else m_x = Val(Left(m_line, 14)) m_y = Val(Right(m_line, 14)) coord(1, coordSum) = m_x coord(2, coordSum) = m_y ' MsgBox coord(1, coordSum) + " " + coord(2, coordSum) End If If AtStart = True Then min_x = m_x max_x = m_x min_y = m_y max_y = m_y AtStart = False ' MsgBox Str(max_x) + " " + Str(max_y) + " " + Str(min_x) + " " + Str(min_y) End If If m_x < min_x Then min_x = m_x End If If m_x > max_x Then max_x = m_x End If If m_y < min_y Then min_y = m_y End If If m_y > max_y Then max_y = m_y End If ' MsgBox Str(max_x) + " " + Str(max_y) + " " + Str(min_x) + " " + Str(min_y) End Function Function ParsePath(m_line) If m_line = "END" Then 'final outer END comes here; ignore Else coordSum = coordSum + 1 ReDim Preserve coord(2, UBound(coord, 2) + 1) 'PathId = "P" + Trim(Left(m_line, 4)) PathId = idPrefixTxt.Text + Trim(Left(m_line, 4)) m_path = "