Changing Image Layer Extents Programatically in TIBCO Spotfire® using IronPython Scripting

Last updated:
10:04am Apr 18, 2019

Back to main IronPython Scripting page

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"]

 

References

None

License: TIBCO BSD-Style License

Feedback (6)

Thanks Neil!

Is it possible to use a Projection other than the three you have listed in your script?

I would like to set a different projection (EPSG:3739), but i'm not sure how to set that in the script.

 

adam.midgley 11:04am Sep. 11, 2019

Thank you Neil. This reference guide was a tremendous help. Hopefully I found what I need to change: x and y in MapChartTransform.FromScales Method, as described in https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/?topic=html/M_Spotfire_Dxp_Application_Visuals_Maps_MapChartTransform_FromScales.htm

As you recommend I am now asking the community a separate question on the right script snippet to actually change it, as I have nil IronPython knowledge. https://community.tibco.com/questions/how-request-ironpython-change-x-and-y-ratios-map-appearance-property

 

dsurovtsev 12:56am Apr. 19, 2019

dsurovtsev,

Oh I see. I understand your question now. I looked on the Spotfire API but don't see ability to change ratio (though I may be looking in the wrong place): https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-a...

I would recommend going to the 'Answers' section of the Community and posting this as a Q&A so others may see the question and may know of a way.

Neil Kanungo 11:15am Apr. 18, 2019

Thank you Neil.

 

Actually I face a different challenge. I need to automate the following process that I can successfully do manually:

1.Open map visualization properties

2.Click on Appearance

3.Change the values for both Y ratio and X ratio to other than default 1:1

4.Ok & close

 

What would be an IronPython script to do it?

dsurovtsev 11:05am Apr. 18, 2019

Hi dsurovtsev,

Are you referring to the ability to change the background map? You cannot re-scale the default background map but you can bring in new TMS, WMS, or Image layers which have different ratios shown. Here is a video on the process for TMS and here is an article for positioning Image Layers.

You would need to find desired TMS/WMS/Image layers online. Here are a few TMS we have, but all are in the WGS 84 Coordinate Reference System.

Once you've picked a rescaled map backround, you may have to re-project your points so they align appropriately with the map. You do this by setting the Coordinate Reference System (link 1, link 2)

Neil Kanungo 9:57am Apr. 18, 2019

Thank you Neil.

Simultaneously with image layer extents I also need to change X and Y ratio settings in Map Chart Appearance. What would be a correct IronPython statement to do that?

dsurovtsev 7:43am Apr. 18, 2019