The power of the Geometry Engine

Sean McGee
4 min readSep 1, 2019

--

I’m a GIS Developer at Esri UK and I’ve had quite a lot of exposure to Esri’s Geometry Engine. It was only after a good few months of working with the tool I understood how powerful it actually is.

This blog post is mostly aimed at people that do not know/have a brief understanding of what the geometry engine is. It’s a compilation of a few samples and demos I have put together.

What is the Geometry Engine?

The geometry engine is built in functionality to the ArcGIS API for JavaScript that lets you work with shapes on a map in 2D & 3D. It can do things like: nearest vertices, length of a line and cutting multiple objects from another.

Showcase mouse movement + nearest vertex/coordinate

This .gif above shows off the nearest function. All of these requests are happening on mouse move. It’s a nice little showcase of the performance, it’s doing 4 geometry engine calls every time the cursor moves.

It generally works like this…

var exampleA = geometryEngine.overlaps(geometry1, geometry2);
var exampleB = geometryEngine. geodesicLength(geometryC, “meters”);

exampleA showcases when performing a task (in this case overlaps) against 2 objects. It’s pretty simple. exampleA in this case will return true or false.

exampleB is one of the calculation functions. Instead of multiple geometries, we would pass in a paramater like “meters” to work out the length in meters.

It’s very simple to get started working with the geometry engine.

What can it be used for?

There’s so many really useful things you can do with it. After all, a lot of data is spatial (has location). Knowing you have the ability to work with that data in this way can be a game changer.

Here’s just a few sample quirkier ideas and use cases of the geometry engine that I have used over time.

  1. Working out the average speed of a vehicles using live/time enabled data.
Point data with GPS and timestamp

Here’s an example with just point data with a time stamp. With JavaScript, I could have purely just drawn a line between them all. It’d look like this.

Simple line drawn between each point

The blue point is a car. A car should be only able to drive along roads. So we would need to do some simple drive time analysis (point a to point b) to fix this. Then, we calculate the length of the new analysis layer. This looks more like this:

Using routing and geometry engine to calculate distance

It’s pretty simple math to be able to calculate the time traveled if we have the start time, end time and now the length because we’re able to calculate that using the Geometry Engine

2. Animating data! I use the geometry engine A LOT when doing any sort of animations with the ArcGIS API for JavaScript.

Animating some bike data in London

There’s a feature in the geometry engine called “densify”. What this basically does it create extra vertices in a line to create “frames” in the animation.

3. Subtracting geometries from one another.

.gif from my “buying a house with js” talk/app

This sample above I am performing a 15 minute drive time buffer. But, instead of the buffer itself being a polygon/colour, I faded the rest of the world out/make it darker. I coined this an “inverse polygon”. In summary, I am just cutting the drive time buffer (shape) out of another shape (the world). It works really quick and it’s a neat little trick that people have often asked about.

Complex geometry engine tasks

Everything I’ve shown above is using the client side version of the GeometryEngine. But, there is infact a server side Geometry Engine task that can be called via REST. Especially useful for calculating much larger tasks or when building custom geoprocessing tools.

It really depends on your use case. I would strongly recommend look at something called RBush. In summary, you’re able to create your own client side spatial index of your geometries. Think of it as… creating a local REST api to the geometries that you have loaded. This allows you to basically only retrieve data in the users extent/the geometry you want to query.

There was a project I worked on last year where I was performing nearly well over 5,000 calls a second. I was doing a query against thousands of building footprints. That footprint data is could have been the size of the UK with millions of lines… This project would not have been possible without RBush. I managed to get the speed of the geometry engine calls over x100 faster.

I hope this blog helped! I thought I’d start to share some of my findings and thoughts when it came to the stuff I do on a nearly daily basis.

Other useful links & demos

A geonet technical blog using geometry engine
Farming demo using the GeometryEngine
Calculating water created from dam

--

--