Attribute VB_Name = "Module2" ' Script3.bas creates several maps from a single data file. The data ' file is organized with columns corresponding to X, Y, Z1, Z2, etc. ' A contour map is created for each set of data: X,Y,Z1, X,Y,Z2, etc. ' The first row of the data file contains column headings. This is ' extracted and used to title the corresponding map. Sub Main On Error GoTo Err_Handlering Dim SurferApp As Object Dim Doc As Object Dim Plotwindow As Object Dim Map As Object Dim MapTitle1 As Object Dim MapTitle2 As Object Dim MethodLabel As Variant Dim retValue As Boolean Dim Data As String Dim Grid As String Dim Path As String Dim Method As Integer Dim GifFileName As String Data = "data.dat" Grid = "RAINRT\RAINRT.grd" MethodLabel = Array("Kriging", "Inverse Distance", "Minimum Curvature", _ "Modified Shepard's Method", "Natural Neighbor", "Nearest Neighbor", _ "Polynomial Regression", "Radial Basis Functions", _ "Triangulation with Linear Interpolation") 'Creates an instance of the Surfer Application object and assigns it to the 'variable named "SurferApp" Set SurferApp = CreateObject("Surfer.Application") 'Assigns the location of the data and grid files to the variable named "Path" Path = "C:\Inetpub\wwwroot\AUTORUN\" 'Disables Plotwindow's AutoRedraw to speed up the script 'Plotwindow.AutoRedraw = False Method =2 Dim j As Integer For j = 3 To 11 Step 1 'Grids the specified data file using the Kriging algorithm and 'assigns the return value to the variable named "retValue" retValue = SurferApp.GridData(DataFile:=Path+"RAINRT\MonthData.xls",xcol:=1,ycol:=2,zcol:=j ,xmin:=97.2,xmax:=105.8, _ ymin:=5.4,ymax:=20.6,numcols:=800,numrows:=1000,Algorithm:=Method, _ ShowReport:=False, OutGrid:=Path + Grid) SurferApp.GridBlank(InGrid:=Path+Grid , _ BlankFile:=Path+"SURFDATA\thailand.bln" , _ OutGrid:=Path+"SURFDATA\out.grd" , _ OutFmt:=srfGridFmtS7) 'Creates a contour map from the gridded data and assigns it to the variable 'named "Map" Dim Plot As Object Set Plot = SurferApp.Documents.Add(srfDocPlot) 'Declares Shapes as an object Dim Shapes As Object 'Assigns the Shapes collection to the variable named "Shapes" Set Shapes = Plot.Shapes 'Declares MapFrame as an object Dim BaseMap As Object 'Creates a base map and assigns the map coordinate system to the 'variable named "MapFrame" Set MapFrame1 = Shapes.AddContourMap(GridFileName:=Path+"SURFDATA\out.grd") For Each Axis In MapFrame1.Axes Axis.ShowLabels = True If axis="Top Axis" Or axis="Bottom Axis" Then Axis.LabelOffset = -0.03 End If axis.MajorTickLength = 0.03 axis.LabelFont.Face = "AngsanaUPC" axis.LabelFont.Size = 8 Next Axis Dim Rectangle As Object Set Rectangle = Shapes.AddRectangle(Left:=2.18, Top:=8.98, Right:=6.09, Bottom:=2.7) Dim ContourMap As Object 'Assigns the contour map properties to the variable named "ContourMap" Set ContourMap = MapFrame1.Overlays(1) 'Declares Levels as an object Dim Levels As Object Dim LevelFileName,TextDate As String 'Assigns the Levels collection to the variable named "Levels" Set Levels = ContourMap.Levels TextDate = MonthName(Month(Date()-1)) &" "& Year(Date()-1)+543 If j =3 Then LevelFileName ="LEVELCOLOR\temp_travel1.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิสูงสุดเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ") GifFileName="MONTHMAX" & Month(Date()-1) ElseIf j = 4 Then LevelFileName ="LEVELCOLOR\temp_travel1.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิต่ำสุดเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ") GifFileName="MONTHMIN" & Month(Date()-1) ElseIf j = 5 Then LevelFileName ="LEVELCOLOR\temp_travel1.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ") GifFileName="MONTHMEAN" & Month(Date()-1) ElseIf j = 6 Then LevelFileName ="LEVELCOLOR\dtemp.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิสูงสุดเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25,"ที่ต่างจากค่าปกติ ") GifFileName="MONTHDepMAX" & Month(Date()-1) ElseIf j = 7 Then LevelFileName ="LEVELCOLOR\dtemp.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิต่ำสุดเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ที่ต่างจากค่าปกติ ") GifFileName="MONTHDepMin" & Month(Date()-1) ElseIf j = 8 Then LevelFileName ="LEVELCOLOR\dtemp.lvl" Set TextUnit = Shapes.AddText(4.88,6.12,"องศาเซลเซียส") Set TextTitle = Shapes.AddText(4.13,9.5,"อุณหภูมิเฉลี่ยเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ที่ต่างจากค่าปกติ ") GifFileName="MONTHDepMean" & Month(Date()-1) ElseIf j = 9 Then LevelFileName ="LEVELCOLOR\rain.lvl" Set TextUnit = Shapes.AddText(5,6.12,"มิลลิเมตร") Set TextTitle = Shapes.AddText(4.13,9.5,"ปริมาณฝนรวมเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25," ") GifFileName="MONTHRAIN" & Month(Date()-1) ElseIf j = 10 Then LevelFileName ="LEVELCOLOR\rainyeardep.lvl" Set TextUnit = Shapes.AddText(5,6.12,"มิลลิเมตร") Set TextTitle = Shapes.AddText(4.13,9.5,"ปริมาณฝนรวมเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25,"ที่ต่างจากค่าปกติ ") GifFileName="MONTHDepRAIN" & Month(Date()-1) Else LevelFileName ="LEVELCOLOR\rainyeardep.lvl" Set TextUnit = Shapes.AddText(5,6.12,"เปอร์เซ็นต์") Set TextTitle = Shapes.AddText(4.13,9.5,"เปอร์เซ็นต์ของปริมาณฝนรวมเดือน " & TextDate) Set TextSubTitle = Shapes.AddText(4.13,9.25,"ที่ต่างจากค่าปกติ ") GifFileName="MONTHDepRAINPercent" & Month(Date()-1) End If With TextUnit.Font .Face = "AngsanaUPC" .Size = 14 .Bold =True .Color=srfColorDarkBlue End With With TextTitle.Font .Face = "AngsanaUPC" .Size = 18 .Bold =True .HAlign=srfTACenter .Color=srfColorDarkBlue End With With TextSubTitle.Font .Face = "AngsanaUPC" .Size = 18 .Bold =True .HAlign=srfTACenter .Color=srfColorDarkBlue End With Levels.LoadFile(Path+LevelFileName) Dim ColorScale As Object Set ColorScale=ContourMap.ColorScale ContourMap.ShowColorScale = True ContourMap.FillContours=True Dim DiscreteColorScale As Object 'Assigns the color scale properties to the variable named 'DiscreteColorScale" Set DiscreteColorScale = ContourMap.ColorScale DiscreteColorScale.Left=5.12 DiscreteColorScale.Top=5.75 DiscreteColorScale.Width=0.5 DiscreteColorScale.Height=2.25 DiscreteColorScale.LabelFont.Face = "AngsanaUPC" DiscreteColorScale.LabelFont.Size = 16 Set BaseMap = Shapes.AddBaseMap(ImportFileName:=Path+"SHAPEFILE\thai_asia.shp") Set Plot = BaseMap.Parent Set baseMap1=BaseMap.Overlays(1) 'baseMap1.Line.ForeColor=srfColorBabyBlue Set PostMap = Shapes.AddClassedPostMap(Path+"SURFDATA\postmap.xls", _ xCol:=1, yCol:=2, zCol:=4,labcol:=5) PostMap.BackgroundFill.ForeColor = srfColorWhite PostMap.BackgroundFill.Pattern = "Solid" Set clpost1 = PostMap.Overlays("Classed Post") clPost1.NumClasses = 3 clpost1.ShowLegend = False clpost1.LabelFont.Face = "AngsanaUPC" clpost1.LabelFont.Size = 7 For i = 1 To 3 With clpost1.BinSymbol(i) .Set = "GSI Default Symbols" .Index = 11 .Size = 0.02 End With Next i clpost1.BinSymbol(1).Color =srfColorRed clpost1.BinSymbol(2).Color =srfColorDarkBlueGreen clpost1.BinSymbol(3).Color =srfColorBlue ' Clear all selections and then select the two MapFrame objects Set TextMet = Shapes.AddText(4.75,3.35,"กลุ่มวิชาการอุตุนิยมวิทยาเกษตร ") With TextMet.Font .Face = "AngsanaUPC" .Size = 10 .Color=srfColorDarkGreen End With Set TextMet = Shapes.AddText(4.9,3.2,"สำนักพัฒนาอุตุนิยมวิทยา ") With TextMet.Font .Face = "AngsanaUPC" .Size = 10 .Color=srfColorDarkGreen End With Plot.Selection.DeselectAll BaseMap.Selected = True MapFrame1.Selected = True PostMap.Selected=True Dim TextTitleDate As Object Dim DateString As String 'Overlay the selected maps Plot.Selection.OverlayMaps Plot.Export(FileName:=Path+"PERIODMAP\" + GifFileName + ".gif", Options:="Width=500, height=871") Plot.SaveAs (FileName:=Path+"MONTHLY\" + GifFileName + ".srf") 'Save the map Next j 'SurferApp.Visible=True Err_Handlering: Exit Sub End Sub