Hi.
All right, great.
Hello, everybody.
My name is Brian Duggan, and I will be talking today about connecting the geospatial
dots with Raku.
This is a fast talk, only 10 minutes.
So I'm going to go through things quickly,
but the slides will all be available afterwards.
But quick, quick poll.
How many people here have used Raku?
Oh, good.
One, two, three.
So I'm going to go through a lot of Raku syntax in this talk.
But again, you can check out the slides afterwards if it doesn't make sense.
Okay, so my name is Brian.
I work at a company called Instacart in the US.
We're a grocery technology company.
We do grocery deliveries among other things.
And we use geospatial data a lot.
We have kind of a bottom-up geospatial culture there,
where we use whatever tool is best to get the job done.
Okay, so I'm going to go through a few different aspects of Raku,
and how it can be used for a geospatial work.
I'm going to talk a little bit about managing data with it,
getting some open street map data,
and then some visualization.
I'm going to leaflet, which we just heard about in the last talk,
and then a little bit of analysis with Dr.DB and Geos.
And there will be some AI also, I promise.
Okay, so a little bit about the Raku philosophy.
One of our core community members, Damien Conway,
had these things to say about the philosophy of the language.
You know, we used to say there's more than one way to do it.
With Raku, we say there's always more than one way to do it,
but some ways are a little more equal than others.
So we try to encourage better programming without forcing it.
We used to say easy things should be easy and hard things should be possible,
but now we say easy things should be trivial.
Hard things should be easy and impossible things should just be hard.
And then to be more a little more formal,
we seek to support developers without getting in their way,
so that whatever mental model works for you,
you can translate into code.
Okay, so let's start with making the easy things trivial.
Anybody here use nominatum to get open street map data?
Okay, so here's how you use it in Raku.
You say use web service, nominatum, nom gives you an object.
You say it's called nom.search.
You put a colon after it.
You can either use colon or parentheses for method calls,
and then you get back data structure.
Now let's use leaflet.
Also pretty simple.
We say use map leaflet and make a map object like that.
And then we have a little for loop here.
And if you look closely, you might notice that something's missing
from the for loop, a variable.
We have an implicit variable.
It's called the topic variable.
It's called its dollar underscore.
It's implied.
So this is actually iterating through a list,
and then it's extracting latitude and longitude
from the elements of the hashes in the list.
Okay, let's talk about bounding boxes.
B bounding boxes can be kind of annoying
because you never know which order the numbers are in.
And so here's an example where we get the bounding box
from the OSM response, and we get four numbers,
but what we really want is two coordinate pairs.
We can make those coordinate pairs with this slice syntax,
which you can not only reorder the elements in your list,
but you can also restructure them.
So if you put a nested data structure within your brackets,
you get back a nested data structure.
So this takes the bounding box and turns it into two coordinates.
So in the map leaflet project,
we're basically mimicking all of the class hierarchies
that are found on the JavaScript side.
So all the attributes you have inheritance,
just like you do in leaflet.
The only difference is that we also have gradual typing in Raku.
So we have a numeric type and a string type and a Boolean type.
So that will give you a little bit more to work with
to enforce some type constraints on your code.
Okay, here's the AI.
So let's draw a line from Philadelphia to Brussels.
You can use LLM-DWIM, which stands for a do what I mean.
You can configure it to use your large language model of choice.
Put that string in.
The at JSON gets expanded to a prompt that tells the LLM,
please write everything as JSON.
It's over and over again, so there really makes it into JSON.
And then M. Show, and you can run this.
So if you lines long, it will actually generate a line on your map.
Overpass, anybody use overpass?
Okay, cool.
So it's got its own language.
You do the same thing, use web service overpass,
OP, and then you can send statements to it,
get back JSON or XML.
So here's, so if you thought bounding boxes were annoying,
let's talk about coordinates.
So for multi polygon, you have an array of polygons,
where each polygon is an array of linear rings.
Each linear ring is an array of coordinates.
Each coordinate is an array of decimals.
Okay, so you start off with this.
GeoJSON, but what you really want to send it to overpass
is also the latitude and longitude of switch.
So you need to flatten them, and then you need to make a string
and then concatenate them.
Okay, so this is pretty easy.
Again, the slides will be available afterwards,
but essentially there are some very,
there are some tourist constructs that you can use
in order to, for instance, extract a vector from a multi-dimensional array.
You can also call the double arrows or a hyperoperator,
which is like map.
It operates on every element of the array.
You say array hyper dot reverse.
It flips the coordinate pairs for you.
You're getting your latitude and longitude in the right order.
And finally, the star star at the end,
you're familiar with list flattening,
but what if you have a really nested structure,
you want to not just flatten a little, but flatten everything?
So we call that bulldozing.
And the double star in a row will flatten everything out,
so you have polygons that you can send to your query.
And so this is the end result.
This gets all the OSM nodes on the U.O.B campus.
I'm going to go a little faster here.
I get through the rest.
Does this building look familiar?
Okay, so this is the building that we're in right now.
It actually has an inner linear ring,
which I discovered when I was making the slides.
And deck GL is very nice.
Anybody use deck GL.
Very nice library for rendering things in 3D.
If you pass a little bit of JavaScript to one of your attributes,
then you can compute the height, and you can conditionally color it.
So it's pretty straightforward.
The previous code will render all the buildings on the U.O.B campus in 3D.
So it's pretty handy.
And let's go through a few things about analysis,
really quickly.
Anybody use deck TV?
Okay, also great.
It's geospatial tool.
You can use duct TV from Raku.
You say it's called Duckie.
You say use Duckie.
And then D will give you an object.
And then you can say D dot query.
You can set an SQL back.
And then you get your rows.
It's also column oriented.
So you can just extract a column from your results set.
It's got really great spatial features.
So let's look at another example here.
Again, on the U.O.B campus, we get the campus in a G.O.J.
Sun file.
You can actually query the G.O.J. Sun file from DuckDB.
And then you can use all these spatial operators
to basically calculate the square meters for every building on campus and sort.
But if you don't want to use DuckDB,
you can also use the underlying library geos directly.
Anybody use geos?
Any chance?
Okay.
So geos, amazing library has a C plus plus API.
And Raku supports the native call interface.
Basically bindings to that API.
So here's an example of loading some WKT data into an object.
That's dollar point.
And then looking at the X.
And you can see it gets the type of the geometry.
Here's a little bit of a bigger example.
So in this case, we're getting all of the points on the polygon
that are surrounding the city of Brussels.
And then we're trying to find the two points that are farthest apart from each other.
So not super complicated, but just complicated enough that it takes a few seconds.
And so here's an example of how to do that.
You can call at points.commonations of two to get all the pairs of points.
And then you can find all the distances just by doing, you know,
node pairs dot map, A dot distance to B.
But what's also nice is that if you have a lot of CPUs,
and you're doing a lot of points, then you might want to use all your CPUs
and do this in parallel.
So to do that, you just add this word hyper.
And hyper takes your sequence and turns it into a hyper sequence
and fans it out across all of your threads,
multi-threaded and multi core operations.
You can send parameters like the batch size and the degree.
And there's another similar one if you want to preserve the order.
Okay, so that was a quick intro to Raku.
How you might like to use it.
We saw some useful modules.
We saw gradual typing, hash and list slices.
We saw some class hierarchies generated JavaScript.
We were able to call C using native call.
We did some parallel operations.
So it's pretty good for like what looks like a scripting language.
It's got a lot of stuff going on.
There's a lot more stuff that I didn't cover, including all the different ways
to run external processes, connect with the standard in,
or standard out.
There's a lot, by the way, the coordinates that we loaded.
Those were actually rational numbers.
So you can do precise rational arithmetic on them.
0.01 plus 0.02 is actually equal to 0.03.
But you can also do floats.
And in the final example with GOS, we're actually using native types.
Those are doubles that take up 64 bits.
So you can do anything in between.
And there's a lot more concurrency besides just,
besides hyper.
So that's it.
And there's also grammars, which is a topic for another day.
If you are interested in learning more or want to chat with us,
come stop by the Pro and Rockus stand and visit the website,
Rockus.org.
Thank you very much.
Good.
Time for a question?
One question.
Is it faster?
You know, fast depends on the problem that you're trying to solve.
So if you're using, it has support for concurrency.
So those operations that are using like the GOS,
the limiting factor that is going to be the GOS operations.
But otherwise, there's definitely,
there's a little bit of overhead for sure.
All right.