Specify the spatial reference file format during export via Surfer automation
You can now specify the spatial reference file format when saving a grid via automation! Previously this option was only available via GridConvert2. In Surfer 21 and newer, it is available for all methods where you save grids. Detailed specifications can be found in Surfer's help for each object and method:
- GridAssignNoData
- GridCalculus2
- GridExtract2
- GridFilter2
- GridMath3
- GridMosaic3
- GridProject
- GridSplineSmooth2
- GridTransform2
- GridConvert2
- GridData6
Remarks
- The OutGridOptions/Options parameters are able to specify both the spatial references file that the user would like to save along with their output grid file, as well as the export options for the output grid format (such as .grd, .gxf, etc.).
- These are the same values that can be used when exporting a bitmap (see the 'Image (Bitmap) Export Automation Options' page in Surfer's help for further documentation of these options). For the export options for specific grid formats, see the 'Grid Export Options String' page in Surfer's help for more details.
Sample:
Sub Main Dim Surfer As Object Set Surfer = GetObject(, "Surfer.Application") Debug.Clear Debug.Print Surfer.Version Set InGridPath = Surfer.Path + "\Samples\" Set OutGridPath = "C:\Users\Kari\Downloads\SpatialReference\" 'Options: 'SaveRefInfoAsInternal=1; NOT FOR GRIDS 'SaveRefInfoAsBlueMarbleRSF=1; NOT FOR GRIDS 'SaveRefInfoAsESRIWorld=1; NOT FOR GRIDS 'SaveRefInfoAsESRIPrj=1 'SaveRefInfoAsGSIREF=1 'SaveRefInfoAsGSIREF2=1 'SaveRefInfoAsAUXXML=1 'SaveRefInfoAsTAB=1; NOT FOR GRIDS '1. SAVE FILE (PRJ, XML) Always creates GSR2 also, SRF-9401 Set Grid = Surfer.NewGrid Grid.LoadFile2(InGridPath+"Conifer.grd") Grid.CoordinateSystem = "Bonne Projection" Grid.SaveFile2(OutGridPath + "SaveFile.grd", Options:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsGSIREF2=0, SaveRefInfoAsESRIprj=1,SaveRefInfoAsAUXXML=1") '2. GRID BLANK (RSF, World = NONE) Surfer.GridBlank2(InGrid:=InGridPath+"Diablo.grd", BlankFile:=Surfer.Path + "\Samples\DemoSlice.bln", OutGrid:=OutGridPath + "Blank.grd", _ OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsBlueMarbleRSF=1, SaveRefInfoAsESRIWorld=1") '3. GRID CALCULUS (GSR1, GSR2) Surfer.GridCalculus2(InGrid:=InGridPath+"Conifer.grd", Operation:=srfGCSlope, OutGrid:=OutGridPath + "Calculus.grd", OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsGSIREF=1, SaveRefInfoAsGSIREF2=1") '4. GRID EXTRACT (XML, TAB=None) Surfer.GridExtract2(InGrid:=InGridPath+"Golden.grd", rFreq:=2, cFreq:=3, OutGrid:=OutGridPath + "Extract.grd", OutGridOptions:= "UseDefaults=1, ForgetOptions=1, SaveRefInfoAsAUXXML=1, SaveRefInfoAsTAB=1" ) '5. GRID FILTER (XML) Surfer.GridFilter2(InGrid:=InGridPath+"diablo.grd", Filter:=srfFilterAvg, OutGrid:=OutGridPath + "Filter.grd", OutGridOptions:= "UseDefaults=1, ForgetOptions=1, SaveRefInfoAsAUXXML=1") '6. GRID MATH (TAB=None) Dim InGrids(1 To 1) As IGridMathInput Set InGrids(1) = Surfer.NewGridMathInput(GridFileName:= InGridPath+"Diablo.grd", VariableName:="A") Surfer.GridMath3(Function:="A * 2", InputGrids:=InGrids, OutGrid:=OutGridPath + "Math.grd", OutFmt:=srfGridFmtS7, OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsTAB=1") '7. GRID MOSAIC (GSR1) Dim Grids2(1 To 1) As String Grids2(1) = InGridPath+"Diablo.grd" Surfer.GridMosaic3(InGrids:=Grids2, ResampleMethod:=srfNearest, OutGrid:=OutGridPath + "Mosaic.grd", OutFmt:=srfGridFmtS7, OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsGSIREF=1") '8. GRID PROJECT (GSR2) Surfer.GridProject(InGridPath+"Telluride.grd", OutCS:="WORLD_ECKERT4", OutGrid:=OutGridPath + "Project.grd", OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsGSIREF2=1") '9. GRID SPLINE SMOOTH (World = NONE) Surfer.GridSplineSmooth2(InGrid:=InGridPath+"diablo.grd", nRow:=3, nCol:=2, OutGrid:=OutGridPath + "SplineSmooth.grd", OutFmt:=srfGridFmtS7, OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsESRIWorld=1") '10. GRID TRANSFORM (PRJ) Surfer.GridTransform2(InGrid:=InGridPath+"telluride.grd", Operation:=srfGridTransRotate, Rotation:=180, OutGrid:=OutGridPath + "Transform.grd", _ OutFmt:=srfGridFmtAscii, OutGridOptions:="UseDefaults=1, ForgetOptions=1, ValuesPerLine=7, BlankLinePerGridRow=1, NumericFormatType=1, NumericFormatDigits=1, SaveRefInfoAsESRIprj=1") '11. WATERSHED SAVE FILLED GRID (PRJ, XML) Doesn't create files, SRF-9360 Set Doc = Surfer.Documents.Add Set Map = Doc.Shapes.AddWatershedMap(InGridPath+"Golden.grd") Map.Overlays.Item(1).SaveFilledGrid2(OutGridPath + "WatershedSaveFilledGrid.grd", Format:=srfGridFmtS7, Options:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsESRIprj=1, SaveRefInfoAsAUXXML=1") '12 GRID CONVERT (PRJ, XML) Surfer.GridConvert2(InGrid:=InGridPath+"Telluride.grd", OutGrid:=OutGridPath + "Convert.grd", OutFmt:=srfGridFmtAscii, _ OutGridOptions:="ValuesPerLine=5, BlankLinePerGridRow=1, NumericFormatType=1, NumericFormatDigits=5, ForgetOptions=1, SaveRefInfoAsESRIprj=1, SaveRefInfoAsAUXXML=1") '13 GRIDDATA6 (GSR1) Surfer.GridData6(DataFile:=InGridPath+"Diablo Example.dat", Algorithm:=1, ShowReport:=False, OutGrid:=OutGridPath + "GridData6.grd", OutGridOptions:="UseDefaults=1, ForgetOptions=1, SaveRefInfoAsGSIREF=1") End Sub
Note: saving as Internal, BlueMarbleRSF, ESRIWorld and TAB will not create a file or save the spatial reference information when saving in a grid format. These spatial references sources are only applicable for raster images (not grids).
Updated November 2021
Comments
0 comments
Please sign in to leave a comment.