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

📄 grd2arc.bas

📁 Surfer是地学中常用的一个软件
💻 BAS
字号:
'Grd2arc converts a Surfer GRD file to ArcView, ArcINFO, 
' Spatial Analyst ASC format.
' Converted from srf7_2aiGRD.frm from Johan.Kabout@MI.DHV.NL - TB Jan 00.
' TB - 19 Mar 00.
Sub Main
    Set srf = CreateObject("Surfer.application")
    Set plot = srf.Documents.Add(srfDocPlot)
    srf.Visible = True
    TempFile = Srf.Path+"\samples\temp.dat"

    SurferGrid = GetFilePath(srf.Path+"\samples\demogrid.grd","grd", _
      srf.Path+"\samples\","Open GRD File")

    'Mirror Y in Surfer GRD file, save to ASCII format.
    ok = srf.GridTransform(SurferGrid, srfGridTransMirrorY, _
      OutGrid:=TempFile,OutFmt:=srfGridFmtAscii)

    lengthstr = Len(SurferGrid)
    ArcGrid = Mid(SurferGrid, 1, Len(SurferGrid)-3) + "ASC"
    Open TempFile For Input As #1
    Open ArcGrid For Output As #2

    'Skip the first line of the file.
    Line Input #1,a

    'Read number of columns and rows.
    Line Input #1,a
    nCol = Left(a,InStr(a," "))
    nRow = Right(a,Len(a)-InStr(a," "))

    'Read X min max.
    Line Input #1,a
    xMin = Left(a,InStr(a," "))
    xMax = Right(a,Len(a)-InStr(a," "))

    'Read Y min max.
    Line Input #1,a
    yMin = Left(a,InStr(a," "))
    yMax = Right(a,Len(a)-InStr(a," "))

    'Read Z min max (not used in Arc grid file).
    Line Input #1,a
    zMin = Left(a,InStr(a," "))
    zMax = Right(a,Len(a)-InStr(a," "))

    xCellSize = ((Val(xMax) - Val(xMin)) / (Val(nCol) - 1))
    yCellSize = ((Val(yMax) - Val(yMin)) / (Val(nRow) - 1))
    Diff = 100*(xCellSize - yCellSize) / xCellSize
    'Debug.Print "xCellSize, yCellSize, Diff =";xcellsize;" ";ycellsize;" ";diff
    If (xCellSize - yCellSize) / xCellSize > 1e-3 Then
    	MsgBox("Cell dimensions are not square.  ("+Str(Diff)+ "%)." + _
    	  "Creating Arc grid with xCellSize: " + Str(xCellSize) )
    End If

    Print #2, "ncols         "; nCol
    Print #2, "nrows         "; nRow
    Print #2, "xllcorner     "; xMin
    Print #2, "yllcorner     "; yMin
    Print #2, "cellsize      "; xCellSize
    Print #2, "NODATA_value  1.70141e+038"
    Print #2, " "

    Do While Not EOF(1)
      Line Input #1, instring
      Print #2, instring
    Loop
    Close #1
    Close #2

    MsgBox ("The Arc grid file "+ArcGrid + " has been created.")
		srf.Quit

End Sub


⌨️ 快捷键说明

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