Buffer lines or paths in Tableau | Buffer Linestring enhancement | New in tableau 2024.1
Tableau 2024.1 quietly lets you buffer line strings, not just points, so let's build distance zones around the London Marathon route.
- The 2024.1 buffer enhancement extends the existing function from working on geometry points to also working on line strings and polygons
- The BUFFER function takes three arguments: the geometry, a numeric distance, and a unit in speech marks such as "m" for metres
- You can connect to a GPX trace converted into a shapefile, but you must connect to the .shp file with all its constituent parts present
- Stack multiple buffer calculations as map layers and reorder them in the marks pane so smaller zones sit on top of larger ones
- Buffer distances are not pinpoint accurate due to background maths, but over marathon distances the distortion is negligible
0:00In Tableau 24.1, there's a new feature that
0:02allows you to use the buffer function on
0:04line string geometry objects inside of
0:06Tableau Desktop.
0:07There's also a bit of a non-story to this
0:09feature, so as ever, let's get stuck in.
0:12So the non-story here is that this feature
0:13doesn't actually appear anywhere in the
0:15product marketing.
0:16If you go to the Tableau features release
0:18page and you go to Tableau Desktop or Table
0:20au Web Authoring, you can just go ahead and
0:21filter this over here.
0:23Select Tableau Desktop as an example. You
0:25won't see this being mentioned here.
0:27But when Tableau 24.1 came out, I saw a
0:30post by Mark Reid, and Mark always does a
0:32fantastic job.
0:33If you want to learn everything there is to
0:35know about spatial capabilities inside of
0:37Tableau, Mark Reid's blog and Mark Reid's
0:40video channel is the place to go.
0:42YouTube channel even. And he posted this
0:44little feature and I thought, "This is
0:45interesting. I thought the buffer function
0:47already existed."
0:48And it does. The buffer function previously
0:51was able to do this specifically with data
0:53points.
0:53So in essence, what we're talking about are
0:56geometry points rather than geometry, lines
0:58, strings, and polygons.
1:00So in this specific case, what this feature
1:02actually is is an enhancement.
1:04And I've made a big deal about the fact
1:06that a lot of features in Tableau in the
1:07past have just been enhancements, not
1:09really features.
1:10And it's kind of interesting because on
1:12this particular case, Tableau themselves
1:14acknowledge this as an enhancement.
1:16So if you go to the Tableau release navig
1:18ator, it says that for Tableau 24.1, this
1:21specific enhancement is actually just an
1:23update to the existing capabilities.
1:25It wasn't possible to do this before. Now
1:27it is possible. So is this an enhancement
1:29or a new feature?
1:31You tell me. Let me know in the comments
1:32below.
1:33Anyway, the feature is here and I'm going
1:35to show you how to use this with a specific
1:37dataset for the London Marathon.
1:39If I go over to my file system here, you'll
1:41see that I have a shapefile.
1:42What I did is I actually downloaded the
1:44London Marathon route as a GPX file.
1:46GPX file is essentially what's created when
1:48you do a run on your smartwatch or any
1:50sports tracking watch.
1:52And I turned it into a shapefile using
1:53website.
1:54You could probably do the same thing with
1:56your own GPS trace.
1:56Having done that, I downloaded that onto my
1:58computer and you can see that these are the
2:00base files here.
2:01Now a shapefile is kind of interesting
2:03because you actually need all the
2:04constituent parts.
2:05But the actual file that we connect to is
2:08this one, .shp file.
2:09I'll put a link to these files so you can
2:11follow along in this video if you want to.
2:13And I'll also publish this visualization
2:15that I'm going to build on Tableau Public
2:16as well.
2:17So let's go ahead and head to Tableau
2:19Desktop where we can actually start working
2:20with this.
2:21So to do this, we're going to hit on this
2:23spatial data type here when we go and
2:25connect to a file.
2:26This actually is something you can do on
2:28Tableau Public as well. Absolutely fine.
2:30We'll go ahead to my desktop here and we'll
2:32go ahead to the London Marathon page.
2:34You can see here we have the shapefile. Let
2:36's go ahead and select that straight away.
2:38Once we've done that, you'll see that we
2:40connect to it here.
2:41Now I'm just going to move my face up to
2:42the right because what I want to highlight
2:43to you
2:44is that this geometry is indeed a line
2:46string.
2:47So to show you that, we have to go and look
2:49for the geometry column in our dataset.
2:51The way shapefiles work means that the
2:53geometry column actually carries a lot more
2:55information
2:56than just one row of data. But you can see
2:58here just on the right hand side that it is
3:00actually
3:01a geometry on the far right hand side. So
3:03that's exactly what we're looking for.
3:04Now we can go ahead and use this inside of
3:06Tableau. We'll go ahead and click on sheet
3:09one.
3:09If you're wondering where that is, that's
3:11on the bottom left here.
3:11So let's go ahead and click on that. And
3:13now we're ready to visualize our chart.
3:16Now this function is super easy to use. I
3:17've actually done a video on this function
3:19already.
3:20If we go ahead and double click the
3:21geometry, you'll see that it draws the
3:23geometry straight
3:24away. Let's put my face down here so it's
3:25out of the way. Let's hide the show me
3:27function on
3:27the right. And you can see that it's
3:29already there. It's dead easy. That's
3:30almost all we
3:31need to do. Now to make this map a little
3:33bit nicer, just going to spend a little bit
3:35of time
3:35formatting this. So I can never remember if
3:37it's background layers or map options,
3:39but I think it's background layers. Yes,
3:41that's the one you can go ahead and choose
3:43something
3:43a little bit nicer. Let's choose streets.
3:46It gives us a much richer, nicer chart.
3:48We can actually make this a little bit more
3:49interesting. Let's see if I can
3:51dial up the size of this path as well, just
3:53to make it a little bit brighter. And
3:55because this
3:55is a route, let's make it red. Let's make
3:58it a really rich red and make it stand out
4:00compared
4:00to the chart. And then what we can do is we
4:02can wash out the map a little bit more,
4:04just so that
4:04it's a little bit more obvious. So there we
4:06go, done some formatting, we've made this
4:07look nicer.
4:08Now we can actually get back to the agenda,
4:10which is to do the buffer function. So to
4:12do this,
4:13I'm just going to go ahead to the top right
4:14here, and I'm going to create a calculated
4:16field.
4:16You don't have to do that, you could do it
4:18another way. But this is the way I like to
4:19do it.
4:19And here you can see we've got this
4:21calculation window that's modal modal just
4:24means that it's
4:24floating. So we can go ahead and sort of go
4:26ahead and start typing the function. So if
4:29you're new to
4:30functions in Tableau, go ahead and check
4:32out my functions playlist, I have over 30
4:34videos and
4:34functions there. But we just go ahead and
4:36type buffer and you'll see that Tableau
4:38gives us a
4:38hint for the function. And it immediately
4:41shows us how to use that function. It wants
4:43the geometry,
4:44and it wants the number, then it wants the
4:46units. And what a buffer does is it draws a
4:48boundary
4:49around the object. So the units are going
4:51to be distances, meters, feet, kilometers,
4:54you can use
4:55other factors as well, Mars as an example.
4:57So for this one, the geometry want is
4:59actually called
5:00geometry, you can see that that's this
5:02field right here. So let's go ahead and
5:04just go back in here
5:05and just type geometry. You'll see the auto
5:07complete comes up geometry selected, then
5:09we can
5:10hit a comma, we're going to want to add 100
5:12meters to this geometry. So I want to
5:14create 100 meter
5:16boundary around the London marathon route
5:18for the purpose of maybe creating zones
5:20that are going to
5:21be used for specific activities around the
5:23event. So let's go ahead and type 100. We
5:26'll then go ahead
5:26and type M and to do this M on its own is
5:28not enough, you have to put this in speech
5:31marks.
5:32So we'll go ahead and delete that and just
5:34type in M. And now that's actually ready,
5:36you'll see that
5:36Tableau tells us that this function is
5:38correct, it tells us down here that the
5:40calculation is valid.
5:41We're now ready to go ahead and use this
5:43and we'll call this 100 meter zone. So let
5:47's call this
5:48zone. And we'll hit apply. Okay, now I'm
5:50actually going to duplicate this straight
5:53away. And I'm
5:53just going to go create another zone
5:55because the great thing about this is you
5:57can you can actually
5:58do a couple of things with it, we'll create
6:00a five 500 meter zone. That's about right.
6:03And we'll call
6:03this as such. So we'll see Tableau complain
6:05, then I'm using the same name. And then we
6:07'll go ahead
6:08and change that to five. And now it's
6:10absolutely fine. And then we'll do a
6:12kilometer zone. That's
6:13the last one that we'll do. So we're going
6:15to stack all three of these geometries on
6:16top of each other
6:17to create a sort of layered visualization
6:20of zones around the particular specific
6:22route. This is super
6:23handy. And one of the things you can do, of
6:26course, is you can sort of merge this with
6:28other functions
6:29inside of the spatial capabilities in Table
6:31au. So we'll go ahead and hit apply, hit OK.
6:34And now
6:34we've got the different zones, I didn't
6:36actually name that as zone. So let's go
6:38ahead and just
6:39rename that in here. So we'll go ahead and
6:41type zone. Perfect. Now what we can do is
6:43we can start
6:44dragging those zones onto the map. So let's
6:46go ahead and drag 100 meters zone and you
6:48'll see
6:48that a zone appears around the map, we can
6:51of course go and change the color. So we
6:53can make
6:54it yellow. Let's do that as an example, you
6:56can see that it's right there. Now is a
6:58critical thing,
6:58because we're using the map players
7:00capability in Tableau, you'll see that the
7:02geometry zone we
7:03started with is at the bottom. And the 100
7:06meters zone here is at the top. And if we
7:08want to layer
7:08these so that the layering actually works,
7:10what we want to do is actually change the
7:12order of the
7:13surround. So I'm going to go ahead and drag
7:15the other zones that we need here onto the
7:17chart,
7:17then we'll reorganize things in the way
7:19that makes sense. You'll see what I mean in
7:21a very
7:21brief moment. So let's go ahead and drag
7:23500 meters and onto the chart, you'll see
7:25that layers in.
7:26And then let's go ahead and drag a kilomet
7:29er on top. And so what you can see here is
7:31that we've
7:31actually got the zones quite clearly laid
7:34out here and almost sort of going in
7:36descending order. So
7:37it actually should be the other way around
7:39what we actually want is to go in this
7:40direction over
7:41here. So let's go ahead and start doing
7:43that. So what I'll do is I'll just go ahead
7:45and drag it.
7:46And you can see that I'm dragging it up and
7:47down the marks pane, geometry goes to the
7:49top, the red
7:50line comes through. Now that's starting to
7:52work nicely. Let's go ahead and put the 100
7:54meter one
7:54next and the 500 meter one. Now you can
7:57kind of start to see these layers working.
7:59The next thing
8:00we probably need to do is to sort of make
8:02the formatting a little bit nicer because
8:04it's
8:04absolutely awful right now. And so what we
8:06do as we go further out, we'll make the
8:08zones probably
8:09less interesting just that it's super clear
8:11. And there you go, we've kind of got this
8:13really strange
8:14layered effect going on. Now, what you can
8:16do is you can start to wash out specific
8:18details. So if
8:19you don't want them to be sort of so over
8:21bearing, you go into the color change, play
8:23around with the
8:24sort of different markings, and then go
8:27ahead and just apply the formatting that
8:29you want to really,
8:30really dial this in. Now don't forget that
8:32once you've done this, you can of course
8:35play around
8:35with this with parameters and actions. And
8:38so you can make this a truly interactive
8:40sort of
8:41capability that you're working with. So
8:43here we have the route. And now as we use
8:45this map,
8:45if I just zoom into specific parts of
8:47London, we can use this to start to
8:49identify areas visually
8:51here on the map that we maybe need to be
8:53prepared to do specific types of activities
8:55. And we can
8:56just quickly use this. Now, there is a
8:58little bit of theory here in that these
9:00zones, these distances
9:02are not exactly pinpoint accurate, there's
9:04a little bit of maths going on behind the
9:06background,
9:07which means that you have to sort of factor
9:08that in. But over this kind of distance is
9:10perfectly
9:11fine, you're not going to get any
9:12distortion that's going on. So that's it.
9:14That's pretty much
9:15a feature in a nutshell. And we've got a
9:17bit further show to you a few more other
9:18capabilities
9:19around mapping. If you've enjoyed this
9:21video, you know what to do hit subscribe,
9:23like let me know
9:24what you'd like to see next in the comments
9:26below. We've hit 100,000 subscribers, that
9:28is absolutely
9:29incredible. But you know, a lot of people
9:31who watch the channel still unsubscribe, so
9:33keep hitting that subscribe button. I
9:35really appreciate it. I'll catch you in the
9:37next one.
Previous video on Buffer: https://youtu.be/Z5QiATfk47g
Timestamps 0:00 Intro 0:12 Feature or Enhancement 1:40 Connect to our data 3:17 Format the map 4:10 Buffer linestring function
Join this channel to get access to perks: https://www.youtube.com/channel/UC7HYxRWmaNlJux-X7rNLZyw/join