09 January 2020

Advanced Spatial Awareness

Today we’re pleased to give a preview of the upcoming release of our new Spatial Service, a brand new component of Pelias which provides advanced geospatial features not available in Elasticsearch.

Many developers are familiar with PostGIS, a geospatial extension for PostgreSQL, but not many are aware that there is also an amazing geographic extension for SQLite called SpatiaLite!

The Spatial Service inherits the exhaustive list of geospatial functions provided by SpatiaLite, which can then be used with any geometries imported into the spatial database.

Right now we have support for importing OpenStreetMap, WhosOnFirst and ZCTA boundary data, but it’s simple enough to write a javascript function to import data from other sources.

I’m going to demonstrate a few of my favourite geospatial operations to give you a small taste of what’s to come and hopefully enthuse you to follow along with the development as it progresses throughout the year.


Tessellation

Partition a geometry into equally sized tiles.
Tesselation
SELECT AsGeoJson(
    ST_Transform(
        ST_HexagonalGrid(
            ST_Transform(
                geom, /* Boundary Polygon */
                3857 /* Pseudo-Mercator projection */
            ),
            200 /* Hexagon edge size */
        ),
        4326 /* WGS 84 projection */
    )
)
FROM spatial.geometry
WHERE source = 'osm'
AND id = 'relation:2567806'

Buffering

Broaden geometries so that they cover a wider area.
Buffering
SELECT AsGeoJson(
    ST_Union(
        ST_Buffer(
            geom, /* Point | LineString | Polygon */
            0.0001, /* Buffer Distance */
            30 /* Quadrant Segments */
        )
    )
)
FROM spatial.geometry

Simplification

Reduce the complexity and file size of a geometry.
Simplification
SELECT AsGeoJson(
    ST_SimplifyPreserveTopology(
        geom, /* Boundary Polygon */
        0.0045 /* Tolerance */
    )
)
FROM spatial.geometry
WHERE source = 'wof'
AND id = '102079339'

That’s all for today folks, please 🌟 the repo on Github to show you’re interested in seeing more.

We’re able to help your organization import your own data into the Spatial service, send us an email!