| BlueSpray - Help © SchoonerTurtles, Inc. 2012-2015
Introduction
Contents
Getting Started
Download
Navigating
Tutorials
Scripting
Advanced
About
| # Getting Started Scripting BlueSpray interfaces with the Python programming language through Py4J. You'll want to install this package first. Then, you can access the full capabilities of the Java Virtual Machine. Finially, we'll show you how to access BlueSpray. ## Installing Py4J To script BlueSpray from Python, you'll need to install Py4j for your version of Python. Fortunately, Py4j and the approach it uses, is largely immune the to version compatibility problems we often see with Python libraries. ## Accessing the Java Virtual Machine To call BlueSpray, you'll first need to gain access to the Java Virtual Machine. This is done with the following two lines of code:
    # Import the gateway to access the java virtual machine (JVM)
    from py4j.java_gateway import JavaGateway

    # Create a Gateway object to talk to the JVM
    gateway = JavaGateway(auto_field=True)

    # Obtain objects to communicate with BlueSpray's packages
    BlueSpray = gateway.jvm.com.SchoonerTurtles
Now we can access any of the standard libraries through the gateway and BlueSpray through the "BlueSpray" object: gateway.jvm.System.out.println("Hello World"); ## Accessing BlueSpray Now you can try the following code to access raster data and save a copy of it to a new file format.
    #############################################################
    # Perform basic raster operations
    #############################################################

    TheRaster=BlueSpray.Raster.STRaster() # Create a raster object to load the raster into

    # Load the raster from a file
    BlueSpray.File.STFileManager.LoadFromFile("C:/Temp/rmnp_dem30.tif",TheRaster)

    # Display information about the raster
    print("Width In Pixels:"+format(TheRaster.GetWidthInPixels()))
    print("Height In Pixels:"+format(TheRaster.GetHeightInPixels()))
    print("Number of Bands:"+format(TheRaster.GetNumBands()))
    print("Size in Bytes:"+format(TheRaster.GetSizeInBytes()))
    print("Data Type:"+format(TheRaster.GetDataType()))

    TheBounds=TheRaster.GetBounds();
    print("The Bounds:"+format(TheBounds))

    # Save the raster into a new file
    BlueSpray.File.STFileManager.SaveToFile("C:/Temp/Copy.img",TheRaster)
##