Jump to content
  • Changing Image Layer Extents Programatically in Spotfire® using IronPython Scripting


    5f9d1564-e0b6-41c0-a936-45135731d7ec-0.jpg.2553db2e96ee02c6dd96d32c8a1297b4.jpg

     

    Introduction

    The following provides an example of how to change the extents for an Image Layer in Map Visualizations using IronPython. Credit to Shandilya Peddi for this solution.

    Code Sample

    # Copyright © 2019. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    # Author - Neil Kanungo & Shandilya Peddi, TIBCO Software, January 2019
    
    from Spotfire.Dxp.Application.Visuals import *
    from Spotfire.Dxp.Application.Visuals.Maps import *
    from Spotfire.Dxp.Application.Visuals import PieMarker
    
    # Set 'v' as your map visualization in Script Parameters
    map=v.As[MapChart]()
    
    # Set Extents (input your own here)
    Xmin=-150 #West
    Xmax=-50 #East
    Ymin=20 #South
    Ymax=50 #North
    
    # Find Image Layer and apply extents
    i = -1 
    for layer in map.Layers:
        i = i+1
        if layer.Title == "Image Layer":
            imageLayer=Application.GetService(Maps.ImageLayer)
            imageLayer=layer
    
            # Use 'Projection.None' for no CRS projection
            # Use 'Projection.WebMercator' for EPSG 3857 projection
            # Use 'Projection.Wgs84' for EPSG 4326 projection
            myExtent = GeographicExtent.Create(Projection.Wgs84, Xmin, Ymin, Xmax, Ymax)
            imageLayer.SetExtent(myExtent)
     

    Bonus

    Set extents through Document Properties to easily adjust values with sliders, input fields, etc. Create a Document Property for Xmin, Xmax, Ymin, Ymax and then replace lines 9-13 in code with:

    # Set Extents
    Xmin=Document.Properties["Xmin"]
    Xmax=Document.Properties["Xmax"]
    Ymin=Document.Properties["Ymin"]
    Ymax=Document.Properties["Ymax"]
     

    snag_3b38ffd.png.dc1ee345c8ae96667cd892895b014ce6.png

    References

    None

    License: TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...