…or consuming the Google Directions API…
There are many functions available as cloud services that can be used within Alteryx. For instance, the Alteryx geocoder is fairly good, but sometimes people want more, or just want to try other options. Instead of asking Alteryx to do something about it (and waiting for a future release), many of the APIs can be utilized from directly inside of Alteryx. A quick search will find a variety of options, many of which could easily be wrapped by an App or Macro.
On a side note, I did not plan on writing 2 Alteryx blog entries this week. With all the flooding last night and this morning, very little was going on in the office and I had to be home much of the day to deal with a soggy basement. Somewhere in there I got distracted from real work and started playing with the Google Directions API. This is what I do to wind down I guess.
The next (9.0) version of Alteryx will include some new and updated tools to help with integrating with cloud services, such as: JSON parsing & building and expanded options in the download tool. That doesn’t mean that Alteryx 8.6 can’t use cloud services as well; there are various tools, such as Download, XML Parse, RegEx among many other tools and functions that make this possible.
Anyway – as purely a proof of concept – I wanted to see if I could wrap the Directions API in an Alteryx App. If you wish to consume this App for production purposes, make sure you review Google’s terms of service. The most difficult bit, and frankly the challenge that got me interested, was figuring out if I could crack the encoding for the points/lines that the API returns. The points are encoded such that a string like: _p~iF~ps|U_ulLnnqC_mqNvxq`@ represents the points: (38.5, -120.2) – (40.7, -120.95) – (43.252,-126.453).
I understand why Google chose to encode the points this way since it is very space efficient. However it was a little bit of a challenge to decode them. The good news is that Alteryx was up to the challenge. Most people probably don’t realize it, but the formula syntax in Alteryx provides binary ORs and ANDs as well as binary string conversions and other handy things for dealing with this sort of thing. In the attached module, you will find a macro called ParsePoints.yxmc that deals with turning that encoded text to an Alteryx line segment.
Once the spatial data was parsed, it was a simple matter to create a quick report that shows all the directions as well as a map. I purposefully kept the report very simple – this is not a post about reporting – I just wanted to show what was possible. Another minor note: I didn’t add any error checking so if you enter an origin or destination that Google doesn’t recognize, you’ll get some obscure error. I guess that all serves to remind this is a proof of concept and not something that is meant to stand alone as a product.
This app can be viewed directly in the Alteryx Public Gallery or can be downloaded to the desktop here.
Thanks for reading,
ned.
If you don’t yet have a copy of Alteryx yet, by all means go get one. Its free (for limited use)… http://www.alteryx.com/download
September 13, 2013 at 10:09 am
Great post! Is there a simple explanation you can give for the 3 expressions in the ParsePoints macro Formula tool (i.e., v, IsLast, vString)? More specifically, why you’re subtracting 63 in the ‘v’ expression, or why you use 32 & 31 as the comparison values in the other two.
September 13, 2013 at 10:32 am
I probably didn’t make the link clear enough in the article… https://developers.google.com/maps/documentation/utilities/polylinealgorithm describes how that data is encoded. I am just doing those same steps in reverse. Step 10 says add 63 to each value, so I need to subtract it out. 32 in decimal is the same as 0x20 in hex from step 8. 32 is added (or OR’d – same thing in this case) to every value except the last, hence why I can compare for it and subtract it.
Pingback: Month in Review: September | Ned Harding