logo

img

Knowledgebase Home | Contact Knowledgebase Home | Contact
Search the Knowledgebase Browse by Category
Do you have an example in Python?
User Opinions
100% thumbs up 0% thumbs down

How would you rate this answer?
Helpful
Not helpful

Surfer can be called from a Python script.  Below are some examples.

 

1.     Here is an example that shows how to start Surfer:

import win32com.client

def main():

    app = win32com.client.Dispatch("Surfer.Application")

    plot = app.Documents.Add(1)

    app.Visible = True

main()

 

2.     Here is another example that shows how to call Surfer:

  import win32com.client

 

  Surfer = win32com.client.Dispatch("Surfer.Application")

  Grid = Surfer.NewGrid()

  Grid.LoadFile("c:/test/test.grd", HeaderOnly=True)

 

  print "BlankValue" + str(Grid.BlankValue)

  print "NumCols" + str(Grid.NumCols)

  print "NumRows" + str(Grid.NumRows)

 

3.     Here is a customer example:

from win32com.client import constants, Dispatch, CastTo
import os.path

def rgb(r, g, b): return b << 16 / g <<8> 0:
level.ShowLabel = True
mapframe = plot.Shapes.AddVectorMap(GridFileName1=grid2, GridFileName2=grid3, CoordSys=constants.srfVecPolar, AngleSys=constants.srfVecAngle)
vectormap = CastTo(mapframe.Overlays(1), 'IVectorMap')
orange = rgb(255, 102, 0)
vectormap.ColorMap.SetNodes(Positions=[0.0, 1.0], Colors=[orange]*2)
vectormap.ColorScaleMethod = constants.srfVecMagnitude
plot.Shapes.SelectAll()
plot.Selection.OverlayMaps()
plot.SaveAs(output)
plot.Export(exportfile)

 

4.     Here is another customer example:

import win32com.client

import glob

import datetime

#call this script like this:

#\programs\python25\python.exe krig_data.py #get an instance of the Surfer application Surfer = win32com.client.Dispatch('Surfer.Application')

lFile = glob.glob('wl*.csv')

for i in range(len(lFile)):

  #the min and max listed below are center coordinates while gdal_grid uses edge

  #coordinates

  sFilePrefix = lFile[i][:lFile[i].index('.')]

  Surfer.GridData(DataFile = lFile[i], xCol = 1, yCol = 2, zCol = 3, NumCols = 4133, NumRows = 3017, xMin = 455355, xMax = 579315, yMin = 1954585, yMax = 2045065, ShowReport = False, DupMethod = win32com.client.constants.srfDupAvg, OutFmt = win32com.client.constants.srfGridFmtBinary, OutGrid = '%s.grd' %

sFilePrefix)

  print 'finished kriging %s at %s' % (lFile[i], datetime.datetime.strftime(datetime.datetime.now(), '%a, %d %b %Y

%H:%M:%S'))


 

Visitor Comments
No visitor comments posted. Post a comment
Related Questions
No related questions were found.
Attachments
No attachments were found.
Products