| BlueSpray - Help © SchoonerTurtles, Inc. 2012-2015
Introduction
Contents
Getting Started
Download
Navigating
Tutorials
Scripting
Advanced
About
| # Sample: Projecting to GoogleMercator ## Projecting Coordinates The sample below will project individual coordinates to GoogleMercator and back to geographic.
    ##########################################################################
    # Script to project coordinates to the GoogleMaps projection and back again
    # Date: 4/12/2016
    # Author: Jim Graham
    ##########################################################################

    # Setup the gateway to BlueSpray (remember that BlueSpray must be running)

    from py4j.java_gateway import JavaGateway

    gateway = JavaGateway(auto_field=True)

    BlueSpray = gateway.jvm.com.SchoonerTurtles

    # Create the projector object from the GoogleMaps projector object

    TheGCS=BlueSpray.SRS.STGCS.WGS_84

    TheInputSRS=BlueSpray.SRS.STSRS.NewGeographic(TheGCS)

    TheOutputSRS=BlueSpray.SRS.STSRS.NewGoogleMercator()

    # Project a geographic coordinate (WGS 84) to GoogleMaps
    Lat=40.0
    Lon=-120.0

    Values=BlueSpray.SRS.STProjectorManager.Project(Lon,Lat,TheInputSRS,TheOutputSRS)

    # Get the result and project it back to geographic
    Easting=Values[0]
    Northing=Values[1]

    Values=BlueSpray.SRS.STProjectorManager.Project(Easting,Northing,TheOutputSRS,TheInputSRS)

    # Print the result
    Lon2=Values[0]
    Lat2=Values[1]

    print("Original Lat,Lon= "+format(Lat)+", "+format(Lon))

    print("Projected Easting, Northing= "+format(Easting)+", "+format(Northing))

    print("Back-projected Lat,Lon= "+format(Lat2)+", "+format(Lon2))
## Projecting Rasters This sample will project a raster to GoogleMercator:
    ##########################################################################
    # Script to project rasters to the GoogleMaps projection
    # Date: 4/12/2016
    # Author: Jim Graham
    ##########################################################################

    # Setup the gateway to BlueSpray (remember that BlueSpray must be running)

    from py4j.java_gateway import JavaGateway

    gateway = JavaGateway(auto_field=True)

    BlueSpray = gateway.jvm.com.SchoonerTurtles

    # Create the projector object from the GoogleMaps projector object

    TheOutputSRS=BlueSpray.SRS.STSRS.NewGoogleMercator()

    # Project a geographic coordinate (WGS 84) to GoogleMaps

    TheRaster=BlueSpray.Raster.STRaster()

    BlueSpray.File.STFileManager.LoadFromFile("C:/Temp/W100N40_4.img",TheRaster)

    BlueSpray.SRS.STProjectorManager.ProjectTo(TheRaster,TheOutputSRS)

    BlueSpray.File.STFileManager.SaveToFile("C:/Temp/Projected.png",TheRaster)
## Projecting Shapefiles The following code will project a shapefile to GoogleMercator:
    ##########################################################################
    # Script to project shapefiles to the GoogleMaps projection
    # Date: 4/12/2016
    # Author: Jim Graham
    ##########################################################################

    # Setup the gateway to BlueSpray (remember that BlueSpray must be running)

    from py4j.java_gateway import JavaGateway

    gateway = JavaGateway(auto_field=True)

    BlueSpray = gateway.jvm.com.SchoonerTurtles

    # Create the projector object from the GoogleMaps projector object

    TheOutputSRS=BlueSpray.SRS.STSRS.NewGoogleMercator()

    # Project a geographic coordinate (WGS 84) to GoogleMaps

    TheLayer=BlueSpray.Scene.STLayerRegions()

    BlueSpray.File.STFileManager.LoadFromFile("C:/Temp/ne_110m_admin_0_countries.shp",TheLayer)

    BlueSpray.SRS.STProjectorManager.ProjectTo(TheLayer,TheOutputSRS)

    BlueSpray.File.STFileManager.SaveToFile("C:/Temp/Projected.shp",TheLayer)