Jump to content

Spotfire Analyst 14.4 The data function '[Geospatial] Distance Matrix' could not be executed.


Go to solution Solved by Gaia Paolini,

Recommended Posts

I have a customer who was upgraded to 14.4 yesterday and his previously working dxp (which FYI also runs OK in my 14.3) is throwing  the following error in 14.4

Spotfire Enterprise Runtime for R returned an error (2)

The data function '[Geospatial] Distance Matrix' could not be executed.

Error in .package.execute.initialization.function(ns, ".onLoad", dirn : error executing function '.onLoad' from package 'glue' loaded from C:/Users/jedga/DOCUME~1/TERR/x86_64-w64-mingw32-library/6.1 : 
Error in registerS3method(generic, class, fun, envir = asNamespace(pk... : object 'vec_ptype2' not found 

I have checked his Managed Trust and the Required packages for R:  `geosphere`, `dplyr`, `tidyr` are installed.  

Thoughts/Ideas - looks to me like a 14.4 TERR library issue from the upgrade

Link to comment
Share on other sites

Hi Jonathan,

An update from our side, after a bit more testing. It seems that the dplyr and tidyr packages won't upgrade. That might be a good thing to add in the ticket.

Also, would an alternative, using Python for instance, also be a workable solution for you and your customer?

Kind regards,

David

Link to comment
Share on other sites

  • Solution

We have a Python option in the newly released spotfire-dsml library.
What you need to do is install spotfire-dsml via Spotfire (Menu > Tools > Python Tools > Package Management).

Then use the following data function (the only slight modification I made to the code is to de-duplicate any id vector, as it expects unique ids):
The distance method could be: 'haversine' (similar to the old TERR version), 'haversine_r' (slightly slower but more accurate) or 'geodesic' (slowest and most accurate).
If buffer is not None, it applies a buffer cutoff to the returned distance matrix.
Other than that, the inputs are the latitude, longitude and id for each dataset (lat1,lon1,id1,lat2,lon2,id2).
 

# Import modules
from spotfire_dsml.geo_analytics import distances, crs_utilities
import pandas as pd


# Make sure ids are not duplicated
def deduplicate_id(id):
    id_list = list(id)
    map_list = map(lambda x: x[1]+ "_" + str(id_list[:x[0]].count(x[1]) + 1) if id_list.count(x[1]) > 1 else x[1], enumerate(id_list))
    return list(map_list)

id1 = deduplicate_id(id1)
id2 = deduplicate_id(id2)
distance_method='haversine'
crs='EPSG:4326'
unit='m'
buffer=None

distance_matrix = distances.calculate_distance_matrix(crs,unit,buffer,distance_method,lat1,
                             lon1,id1,lat2,lon2,id2)

 

Link to comment
Share on other sites

Completely removed my Spotfire Analyst 14.3 installation including the Appdata Spotfire directory and did a clean install of Spotfire Analyst 14.4

Following the 14.4 install I looked to install geosphere, dplyr, tidyr for the R [Geospatial] Distance Matrix function  - those packages were already there.  The R data function still errors with the same object 'vec_ptype2' not found  error as before.

Moving to the Python packages I saw that spotfire-dsml was already there.  Plumbed in the data function code provided by Gaia - thank you - and it is working. 

One question - I am assuming the haversine in the spotfire-dsml returns the distance in meters as did the R version.  Is this correct?

[Geospatial Python] Distance Matrix.sfd

Link to comment
Share on other sites

Excellent!


Yes, I set unit='m' in the code I gave you; you can set units in meters, kilometers or miles or feet (with various spelling and abbreviations).

It's all pretty new so documentation examples etc are still being processed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...