Vortex grid clipping script example - HydrologicEngineeringCenter/Vortex GitHub Wiki
The Vortex API is written in java allowing access via jython scripting. The following example demonstrates batch clipping gridded DSS records via a jython script.
This batch script example uses two scripting files:
- A *.py file that contains the scripting logic
- A *.bat file that sets the environment and executes the python script
In addition to the script files, two jars were used:
The jython script my_batch_clip.py clips all records in a DSS file using the Vortex Java API. Note the internal API uses the nomenclature "subsetting" rather than "clipping" since the perimeter raster cell size is maintained during the operation.
from mil.army.usace.hec.vortex.geo import BatchSubsetter
from mil.army.usace.hec.vortex.geo import WktFactory
path_to_input = 'C:/Temp/truckee_2016.dss'
clip_ds = 'C:/Temp/Truckee_River_Watershed_5mi_buffer.shp'
destination = 'C:/Temp/myPythonImport.dss'
write_options = {'partF': 'my script import'}
myImport = BatchSubsetter.builder() \
.pathToInput(path_to_input) \
.selectAllVariables() \
.setEnvelopeDataSource(clip_ds) \
.destination(destination) \
.writeOptions(write_options) \
.build()
myImport.process()
The batch script my_batch_clip.bat sets the environment and executes the script:
set "VORTEX_HOME=C:\Programs\vortex-0.10.16"
set "PATH=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal;%PATH%"
set "GDAL_DATA=%VORTEX_HOME%\bin\gdal\gdal-data"
set "PROJ_LIB=%VORTEX_HOME%\bin\gdal\projlib"
set "CLASSPATH=%VORTEX_HOME%\lib\*"
C:\Programs\jython2.7.2\bin\jython.exe -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal my_batch_clip.py