Web Feature Services(WFS) in TIBCO Spotfire

How to use R and TERR to access geospatial features via WFS in Spotfire

Bobby Neelon
Coach Neelon
6 min readSep 9, 2020

--

Disclaimer: I am not a GIS professional…but I did stay at a Holiday Inn Express last night!

TIBCO Spotfire is one of my favorite BI/analytics tools and is particularly great at geospatial analytics. That said, one “hole” it does have in that arena is the lack of support for Web Feature Services(WFS) as a data source. Luckily, Spotfire provides the TERR engine to run R data functions in the background. I’ll show you how to utilize TERR to overcome TIBCO’s lack of direct WFS support.

What is supported?

The core methods for adding geospatial data to Spotfre are importing shapefiles(.shp) or querying spatial objects from Microsoft SQL, Oracle, or PostGIS databases. TIBCO also makes it possible to integrate web map services(WMS) and tiled map services(TMS) as visual layers on your map(s).

Shapefiles are great and all, but there are some limitations which you can learn more about here. The limitations I want to focus on for this post are that shapefiles are static, column names can only be 10 characters long, and there is a size limit of 2GB. It should be noted that Shapefiles can be updated regularly by automated processes, but another problem I’ve encountered in the past is that for others to use your analysis, they’ll also need access to the file system and exact path where the shapefile is referenced by your Spotfire project. If network drives are mapped differently from user to user, that can cause issues.

Querying from the aforementioned databases is an excellent option if the data you’re requiring is available in that fashion. That may not always be the case, though, especially outside your organization.

WMS and TMS are very good options if you just need a visual reference on your maps, but unlike the previous 2 options, WMS/TMS don’t provide access to the underlying features. You just get the map that the provider has created with no option to customize the appearance or manipulate the underlying data.

What about Web Feature Services?

There is another option out there, but it is not directly supported by Spotfire. That option is WMS’ sibling, the Web Feature Service(WFS). While they are both Open Geospatial Consortium(OGC) compliant web services, WFS is concerned with direct access to your data — reading, writing, and updating features whereas WMS is concerned with transforming data into a map (image). Connecting to a WFS will allow us to always get the most updated version of the data from a consistent endpoint.

Thankfully, there are tools in R that will allow us to take advantage of WFS in Spotfire.

Assumptions

The user should have at least basic experience with Spotfire, R, and GIS.

If you’re not familiar with WFS, this tutorial helped me very much to understand how to use WFS in R.

What We’ll Do

To create a reproducible example, we will connect to NOAA’s Monthly Precipitation Outlook via a public WFS and replicate the map below…but in Spotfire!

https://www.cpc.ncep.noaa.gov/products/predictions/30day/

R Script

Below, you will see the short R script we will implement. While this request looks simple, and it is, I am making a lot of assumptions that you know how and where to get the query parameters you will need. Also note the last line where we convert the geometry feature to a well-known binary (WKB). This will be essential for getting the code to work in Spotfire.

Spotfire

Note: This example has been tested on TIBCO Spotfire Versions 7.13 and 10.8.

First, you will need to register a new data function and add the R code. Also, ensure that the 3 required libraries (sf, httr, ows4R) have been installed in TERR tools.

Then, make sure that requestedData is added within the Output Parameters tab.

After that, click “Run” and ensure requestedData is showing up as an output and the Output Handler indicates it will be a Data Table. Click OK.

YOU’RE NOT DONE!!! If everything went well, Spotfire has imported the data into a table, and the geometry column is of a binary type. We will need to make sure Spotfire recognizes the column as a “Geometry” type, and we’ll also need to calculate the envelope(bounding box) for the features using Spotfire’s Spatial Functions.

To make sure Spotfire recognizes the geometry column as a “Geometry” type, go to Column Properties, click the row containing ‘geometry’, open the Properties tab, and edit Content Type and MapChart.ColumnTypeId to have the values application/x-wkb and Geometry, respectively. Click OK.

To calculate the envelope, add 6 calculated columns ( XCenter, XMax,XMin,YCenter,YMax,YMin) via Insert Transformations using the Spatial Functions mentioned earlier.

(It should be noted that this can also be done with the writeEnvelope() function from the ‘wkb’ package in R which is maintained by TIBCO. In my experience, it was a bit of a performance bottleneck, so I chose to build the envelope directly in Spotfire.)

At this point, you should be able to open a “Table” visualization and see the actual shapes in each row and also the columns we calculated!

If you simply right-click that table and “Switch visualization to” > “Map Chart”, your table should turn into a map with the polygons displayed appropriately. You could also build this directly with the “Map Chart” visualization.

At this point, we have accomplished the core of what we set out to do. Now we can harness the power of Spotfire as we would a Shapefile or database.

To match the appearance of the NOAA map, let us create a calculated column, Probability, for us to “Color By” using the expression:

Concatenate([prob],"% - ", [cat])

I also set a custom Sort Order for that column and roughly matched the coloring schemes.

This yields our fully-interactive, finished product of:

I hope this helps you in your journey using Spotfire for geospatial analytics. I’d love to hear how you could utilize this in your work!

--

--

Bobby Neelon
Coach Neelon

Data Analytics Professional, Cloud Enthusiast, Sports Nerd