| BlueSpray - Help © SchoonerTurtles, Inc. 2012-2015
Introduction
Contents
Getting Started
Download
Navigating
Tutorials
Scripting
Advanced
About
| # Introduction to Scripting BlueSpray ### Querying Data from a Database and Inserting as a Layer
    importPackage(Packages.ST.Project);
    importPackage(Packages.ST.Scene);
    importPackage(Packages.ST.Raster);
    importPackage(Packages.ST.File);
    importPackage(Packages.ST.Vector);
    importPackage(Packages.ST.Table);
    importPackage(Packages.ST.Database);

    var TheLayer=new LayerGeometry();
    var TheScene=TheScenes.GetChild(0);

    var Query=
       "SELECT     TOP (200) TBL_SpatialLayerData.ID, TBL_SpatialLayerData.GeometryData.STAsBinary() AS Expr1 "+
       "FROM         TBL_SpatialLayerData INNER JOIN "+
       "                      TBL_Areas ON TBL_Areas.ID = TBL_SpatialLayerData.AreaID "+
       "WHERE     (TBL_Areas.AreaSubtypeID = 4) and (GeometryData.STIsValid()=1)";

    SQLServer.QueryToLayer("CWIS438_INVASIVE_SQL","sa","cheatgrass",
       Query,TheLayer);

    TheScene.AddChild(TheLayer);
    var TheRaster=ToRaster(TheLayer,.1,1,DataBuffer.BYTE);

    importPackage(Packages.ST.Project);
    importPackage(Packages.ST.Scene);
    importPackage(Packages.ST.Raster);
    importPackage(Packages.ST.File);
    importPackage(Packages.ST.Vector);
    importPackage(Packages.ST.Table);
    importPackage(Packages.ST.Database);
    importPackage(Packages.ST.RefSystem);

    var TheLayer=new LayerGeometry();

    var TheScene=TheScenes.GetChild(0);

    var Query=
    'SELECT TOP (200) TBL_SpatialLayerData.ID, TBL_SpatialLayerData.GeometryData.STAsBinary() AS Expr1 '+
    'FROM TBL_SpatialLayerData INNER JOIN '+
    '	TBL_Areas ON TBL_Areas.ID = TBL_SpatialLayerData.AreaID '+
    'WHERE (TBL_Areas.AreaSubtypeID = 4) and (GeometryData.STIsValid()=1)';

    SQL.ODBCExecute('CWIS438_INVASIVE_SQL','sa','cheatgrass',Query,TheLayer);

    ProjectorManager.ProjectToGoogleMaps(TheLayer);

    // create the zoomed layers

    for (var i=0;i<4;i++) // for each zoom level
    {
    	var TheLayer2

    	if (i==0) TheLayer2=TheLayer;
    	else
    	{
    		TheLayer2=new LayerGeometry();

    		var Factor=Math.pow(2,i);

    		println(Factor);

    		Simplify.Simplify(TheLayer,TheLayer2,1000*Factor,false,null);

    		TheLayer=TheLayer2;
    	}

    	// check for areas that have become ponits

    	TheScene.AddChild(TheLayer2);
    }

    /*
    Database
    - Query from database (Geometry or Lyaer?)
    - Project to GoogleMaps
    - Simplify
    - Intersect with rectangle
    - Update into Database
    */

    Simplify and tile:

    importPackage(Packages.ST.Project);
    importPackage(Packages.ST.Scene);
    importPackage(Packages.ST.Raster);
    importPackage(Packages.ST.File);
    importPackage(Packages.ST.Vector);
    importPackage(Packages.ST.Table);
    importPackage(Packages.ST.RefSystem);
    importPackage(com.vividsolutions.jts.geom);

    var TheLayer=new LayerGeometry();

    // do a query here to get the entire layer

    var Abort=FileManager.LoadFromFile("E:/GIS_Data/US/states.shp",TheLayer,false);

    // project the entire layer to googleMaps

    ProjectorManager.ProjectToGoogleMaps(TheLayer);

    // simplfy and tile each layer

    var NumFeatures=TheLayer.GetNumFeatures();
    println("NumFeatures="+NumFeatures);

    var TheTable=TheLayer.GetTable();

    var TheReader=new com.vividsolutions.jts.io.WKTReader();

    var Left=0;
    var Right=20000000;
    var Top=0;
    var Bottom=-25000000;

    var TheBox=TheReader.read("POLYGON(("+Left+" "+Top+","+Right+" "+Top+", "+Right+" "+Bottom+","+Left+" "+Bottom+", "+Left+" "+Top+"))");

    //NumFeatures=1;
    for (var i=0;i