Okay, hello, my name is Brian, and we're going to do something a little bit different.
And also a little bit the same.
This talk is called Keeping Spatial Scripting Sane, with Samake and Raku, something a little
new.
I'm a logistics engineer at Instacart in the U.S., we do grocery technology and delivery.
We have a lot of fun and interesting spatial problems.
I'm also a contributor to the Raku ecosystem.
Anybody heard of the Raku programming language?
Okay, a few people, good.
First of all, I'll talk about the motivation.
I'm going to talk about Samake, something that I've written to help with spatial scripting.
Some examples had to extend it and then a little bit about the choice of Raku as a programming
language.
So if you're here for the first talk today, you sort of saw some of this about what it's
like with the ecosystem of spatial data and tools, there's a lot of tools, a lot of data.
It gets messy.
Also, if you're writing scripts, one of the challenges is that you want to do visualization
while you're writing your code.
So you can't just sort of write something compile it, run it, you have to sort of iterate.
Data is nice when it's local and it's small, sometimes it's big and it's far, and
there are a lot of different languages.
So the goal of Swahili is to be able to integrate a lot of different programming languages
together at the same time, and it has some aspects of Rapples and some aspects of notebooks,
like Jupiter notebooks, so yeah, so let's just drive right in.
So the basic concept is like this, you have all your languages in a single file.
You use two dashes to separate them into cells, so you might have some Python, some
duck DB, you might have some R, anybody who's R here, you might use an LLM, first AI
of the day in this talk, in this room, so these are cells, I'm going to talk a little
bit about plug-ins and plug-outs for visualization.
So each cell has a type like Python, and it has a name like location, and then JSON is the
output format, you might generate JSON, you might generate CSV files, you might generate
images, so you sort of put them all here together, and then you might want to share information
between your different cells, so that can get tricky, so that's what way we introduce
these angle brackets here, this is the Unicode angle bracket, they're not used in a lot
of programming languages, so they probably won't get in your way, and you can interpolate
Raku expressions there, so right here we find a location, generate JSON, and then take
the latitude and longitude, and then put it here inside of the SQL that we can send
off to duck DB.
You can also put a little bit of code at the beginning, you can say, you know, a variable
has dollar country, and then you can do something with it later on, so they all sort of
share the same execution context.
So summary, cells like this, two dashes is the beginning of the cell, the type comes
at is before the colon, then you have a name, then you have an extension, the lines that
start with dashes, separate the cells, the first plugin that matches the type will be used
to execute the cell, and then the first plugin that matches the extension will be used
to generate the data, but you can use the other types if there's multiple matches, and
then you can interpolate data into your code with angle brackets, so this is basically
how it works.
There's an interface, so here we have a little text editor, if you don't use BI, you can
also set your editor and use another one, or it can watch for changes to your files.
You edit your file like this, and then you start up this console user interface, it'll
highlight the parts that are getting interpolated, it'll highlight your rocko code, and
then you can basically change between this, where you're editing, and then you can make
it be in evaluation mode, where you'll fill in your data for you, so you can see what
you're going to execute, then the bottom will have the outputs.
So we run our CSV, it returns, it runs, I use Postgres here, so we could use a geography
type, we are just going to buffer this point, then we can select our output file, CSV
file, choose one of the plugin, plug out, that mentions it, okay, so CSV Geo, then we'll
launch a web browser, and then we get to see our data.
So that's how it works, so you define your input types, your output types, you kind of write
some code, run some cells, share data between cells, visualize, and keep going, so let's
see if we can get through a few examples in five minutes, so we're going to Geo code here,
generate a CSV, then put it into Postgres, and then visualize it, so this is the what
we just saw, okay, let's do a little Python and R sort of mashed up together here, so
here we'll use a little Python, the slides are online, by the way, so you don't have
to read everything now, so generate a bounding box with Python, and then put it into R with
tidyverse, and then, and then when we, it'll basically launch the R-reple, and then you'll
see that you can see the output below, and then R will spawn its own window, and you get
a little map-nick tile suitable for experimenting with the tiles that you're generating.
When you configure them, this is how you make a plugin, it's really simple, you have
a regular expression that matches the type, and then you have a method that's called Execute,
and Execute basically takes the data and runs something.
There are some common ones, the ones we saw are processes and repulse of process, cake,
standard in, prints just standard out, or maybe uses a temporary file, Raku has built
in support for pseudo-TTYs, like, expect us, but if you don't want to use Execute, you
can use this instead, so it can also do things like parse streaming, UTF8, and antsy escape
sequences, so it can take care of all that stuff, and you can put a definition of a class
right into the configuration file, so basically the grass, the grass plugin we saw, it
just looks like this, so it's plugin, colon, colon, repule, command, grass, and that actually
generates a class that has an Execute method that runs the grass command.
Similarly, you can make a process like that, command is called Claude, send the arg, say
you standard in, instead of a temp file, so this is actually a way of defining a class
in Raku by using a roll, a roll defines an interface, and if you pass it some parameters,
you can turn the interface into a class.
There are a lot of plug-outs and plug-ins that come with it, I'm not going to go through
all of them, but you saw a few already, the plug-outs got to work the same way, basically
you define something called Execute, it gets dollar path, which is the name of the file,
this is the thing that will basically show an image, you just say shell, and then open,
and it'll use the system open command.
So it's really easy to add things for your own tooling, and see, so yeah, so these are all
the different things that are included, you know, you can generate Markdown, you have
GeoJSON, if you use T-mux, there's also a way to spawn a command in a separate T-mux
pane, and then it'll use the T-mux control API to send and receive data from it, so you
can interact with things that way if you want to also.
Sometimes people say, why are you using Raku instead of another language, I'll just give
you a few reasons here, that some of which I've already mentioned, so it has really good
process interactions, pseudo-T2Is built in, talked to me more at the Raku and Pearl stand,
and I think that's it, and if you, for more information, check the slides, and also you
can just Google for Raku, so Marky, thank you.