---
title: [FOSS4G Asia 2023] GEOS runs on web browsers - WebAssembly power for geospatial analysis
tags: 
author: [Ko Nagase](https://convert.docswell.com/user/sanak)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/YJ9N1448J3.jpg?width=480
description: 2023/11/29(Wed) FOSS4G Asia 2023 Online talk about GEOS-WASM. https://talks.osgeo.org/foss4g-asia-2023/talk/W8WCWX/
published: November 30, 23
canonical: https://convert.docswell.com/s/sanak/Z1JEL3-2023-11-30-100118
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/YJ9N1448J3.jpg)

GEOS runs on web browsers
WebAssembly power for geospatial analysis
2023/11/29(Wed) FOSS4G Asia 2023 Online Talk
Ko Nagase @sanak


# Page. 2

![Page Image](https://bcdn.docswell.com/page/GJ8K4QQZED.jpg)

Self Introduction
●
●
●
Georepublic Japan Developer
GitHub: @sanak
OSGeo: @Sanak
○
○
○
●
pgRouting contributor
pgRoutingLayer (QGIS Plugin) contributor
OSGeoLive Japanese translator, contributor
Regular work:
○
○
Main: Maintaining Redmine base system’s backend
side (Ruby/Ruby on Rails/PostGIS)
Sub: Maintaining the system’s frontend side
(ReactNative/Next.js/TypeScript)


# Page. 3

![Page Image](https://bcdn.docswell.com/page/LJLZ6XX17R.jpg)

Agenda
●
●
●
●
What is GEOS ?
What is GEOS-WASM ?
GEOS-WASM using library/app
Background
○
○
●
●
●
●
●
2D geospatial analysis libraries
WebAssembly
How the project started
Characteristics of GEOS-WASM
Recent related topics
Future possibilities of WebAssembly
Acknowledgements


# Page. 4

![Page Image](https://bcdn.docswell.com/page/47MV5LL57W.jpg)

What is GEOS ?
●
●
●
●
Website: https://libgeos.org/
C/C++ library for computational
geometry
Implements OGC Simple Features
geometry model and spatial
functions
Core dependency of PostGIS,
QGIS, GDAL, Shapely, etc.


# Page. 5

![Page Image](https://bcdn.docswell.com/page/P7R23KKZJ9.jpg)

What is GEOS-WASM ? (1/2)
●
●
●
●
Website:
https://chrispahm.github.io/geo
s-wasm/
WebAssembly build of the GEOS
library which can be used in
the browser and Node.js.
Exposes the low-level GEOS
C-API to JavaScript without any
abstractions.
Intended to be used as a
building block for higher-level
libraries and specific use
cases.


# Page. 6

![Page Image](https://bcdn.docswell.com/page/PJXD4LL1EX.jpg)

What is GEOS-WASM ? (2/2)
Usage
Installation
●
Node.js
npm install geos-wasm
●
Browser
&lt;script type=&quot;module&quot;&gt;
import initGeosJs from
&#039;https://cdn.skypack.dev/geos-wasm&#039;;
&lt;/script&gt;
import initGeosJs from &#039;geos-wasm&#039;
// initGeosJs returns a promise that resolves to a GEOS object
const geos = await initGeosJs()
// use the GEOS object to call GEOS functions
// Example: get the area of a polygon
// create a WKT reader
const reader = geos.GEOSWKTReader_create()
const wkt = &#039;POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))&#039;
// read the WKT string into a GEOS geometry -&gt; returns a pointer
const geomPtr = geos.GEOSWKTReader_read(reader, wkt)
// create a pointer where the area will be written to
const areaPtr = geos.Module._malloc(8)
// calculate the area of the geometry
geos.GEOSArea(geomPtr, areaPtr)
// read the area from the pointer into a JS number
const area = geos.Module.getValue(areaPtr, &#039;double&#039;)
console.log(area) // area = 1
// free the WKT reader, the geometry, and the pointer
geos.GEOSWKTReader_destroy(reader)
geos.GEOSGeom_destroy(geomPtr)
geos.GEOSFree(areaPtr)


# Page. 7

![Page Image](https://bcdn.docswell.com/page/3JKXZLLMED.jpg)

GEOS-WASM using library/app (1/2)
geotoolbox
●
●
●
●
●
GitHub: neocarto/geotoolbox
Developed by @neocarto.
Demo site:
https://observablehq.com/@neoca
rtocnrs/hello-geotoolbox
Various working examples
GEOS-WASM has been used in some
functions (Buffer, Clip,
Densify and Union) since v2.0


# Page. 8

![Page Image](https://bcdn.docswell.com/page/LE35D332J5.jpg)

GEOS-WASM using library/app (2/2)
GEOS WASM Tester
●
●
●
●
●
GitHub: sanak/geos-wasm-tester
Developed by me
Demo site:
https://sanak.github.io/geos-wa
sm-tester/
Inspired from JTS Test Builder
which works on Desktop
environment
GEOS-WASM is used as git
submodule


# Page. 9

![Page Image](https://bcdn.docswell.com/page/8EDDP446EG.jpg)

Background
●
●
2D geospatial analysis libraries
WebAssembly


# Page. 10

![Page Image](https://bcdn.docswell.com/page/V7PXNMVZE8.jpg)

Background - 2D geospatial analysis libraries
●
JTS Topology Suite(Java, LGPL=&gt;EPL, 2000~)
○
○
●
GEOS(C++, LGPL, 2002~)
○
Bindings: Shapely(Python), sf(R), RGeo(Ruby), GeoRust/GEOS(Rust),
GeoSwift(Swift), LibGEOS.jl(Julia), node-geos(JavaScript), .etc
App/DB: QGIS, PostGIS, SpatiaLite, .etc
○
DB: MySQL(&gt;=5.7)
○
●
●
●
●
Bindings: GEOS(C++), NetTopologySuite(C#), JSTS(JavaScript),
dart_jts(Dart)
App/Library: OpenJUMP, GeoTools
Boost.Geometry(C++, BSL, 2009~)
D3.js(JavaScript, BSD, 2011~)
Turf.js(JavaScript, MIT, 2013~)
GeoRust/Geo(Rust, MIT/Apache, 2015~)


# Page. 11

![Page Image](https://bcdn.docswell.com/page/2JVLK9ZM7Q.jpg)

Background - WebAssembly (1/3)
Summary: MDN, webassembly.org
●
●
●
●
●
Low-level assembly-like
language
Runs on modern web browsers
Near-native performance
Compiled from C/C++, Rust, etc.
Designed to complement and run
alongside JavaScript
History: Wiki
●
●
●
2015 Jun: First announced
2017 Nov: Supported on all
major browsers
2019 Dec: WebAssembly Core
Specification (v1) becomes W3C
standard


# Page. 12

![Page Image](https://bcdn.docswell.com/page/5EGXQZ4XJL.jpg)

Background - WebAssembly (2/3)
●
FOSS4G 2019:
○
●
FOSS4G 2021:
○
○
●
WebAssembly - a new technology and its potential for geospatial
application by Pirmin Kalberer (YouTube)
OSGeo in the browser: Advances in client-side WebAssembly-based
Geospatial Analysis and frontend visualization using jsgeoda and
Vis.gl by Dylan Halpern (YouTube)
Handling GeoTIFFs in client-side code with GDAL and Loam by Derek
Dohler (YouTube)
FOSS4G 2022:
○
○
Write once, run anywhere: safe and reusable analytic modules for
WebAssembly, Javascript, or more! by Stuart Lynn
WebAssembly4G: Where we are, and where we&#039;re heading by Michael
Schmuki


# Page. 13

![Page Image](https://bcdn.docswell.com/page/4JQ8KLG57P.jpg)

Background - WebAssembly (3/3)
●
Emscripten (C/C++)
○
○
○
○
●
ddohler/gdal-js (GDAL)
azavea/loam (GDAL)
bugra9/gdal3.js (GDAL, Demo)
jvail/spl.js (SpatiaLite, Demo)
Rust
○
dabreegster/route_snapper (Demo)
■ Draw routes in MapLibre snapped to a street network using
client-side routing
○
:


# Page. 14

![Page Image](https://bcdn.docswell.com/page/K742PD5VJ1.jpg)

How the project started (1/6)
The project idea itself started
from @tmcw’s braindump:
https://github.com/tmcw/geos-wasm
●
●
●
●
Turf is most comfortable for
web development.
But for robustness, it needs
other stable implementations
like JSTS which is port from
JTS.
Getting the same features/bugs
as GEOS is preferable.
Raise GEOS/WASM proposal.


# Page. 15

![Page Image](https://bcdn.docswell.com/page/LJ1M9ZW4EG.jpg)

How the project started (2/6)
@chrispahm found the repository,
then created the POC version with
GEOS using Emscripten: geos-wasm Is it worth the effort? · Issue #2
· tmcw/geos-wasm
●
●
●
Full working “buffer” demo and
very detailed documents.
Compiling process is based on
bugra9/gdal3.js.
Serialization performance issue
was mentioned.


# Page. 16

![Page Image](https://bcdn.docswell.com/page/GJW3Q96ZJ2.jpg)

How the project started (3/6)
@kylebarron wrote his blog:
Thoughts on GEOS in WebAssembly
●
●
●
●
Similarity with Apache Parquet
bindings.
Details of WebAssembly
performance concept.
Details of the serialization
performance issue.
GeoRust possibility for future
○
○
geoarrow/geoarrow-rs
Prototyping GeoRust + GeoArrow
in WebAssembly / Kyle Barron |
Observable


# Page. 17

![Page Image](https://bcdn.docswell.com/page/4EZVW9YLJ3.jpg)

How the project started (4/6)
I found @kylebarron’s blog, and
feel excited about the project.
●
●
●
Experience of GEOS COM Wrapper
for Windows+IE (ActiveX). Demo
(require DLL registration)
Tried node-geos contribution,
but gave up it because Node
(v8) C++ API is difficult for
me and it only supports Node,
and not web browsers.
Started contributions to the
project from PR #2 and #3.


# Page. 18

![Page Image](https://bcdn.docswell.com/page/Y765GKDMEV.jpg)

How the project started (5/6)
●
●
●
●
Preferred data transfer between
JS and WASM context → shouldn&#039;t
it be WKB? · Issue #4 ·
chrispahm/geos-wasm
Passing Geometries between
JavaScript and GEOS-WASM was
slow when using text-based
format (WKT (Well-Known-Text)
and stringified GeoJSON).
Using WKB (Well-Known-Binary)
format with @syncpoint/wkx
package increases performance.
(Later, helper methods were
added via PR #19.)


# Page. 19

![Page Image](https://bcdn.docswell.com/page/G75YVP3Q74.jpg)

How the project started (6/6)
●
●
●
●
API preferences? · Issue #5 ·
chrispahm/geos-wasm
Originally, it was designed
with mixing high-level function
(like “buffer”) which is
compatible with Turf.js.
Personally, I wanted to have
Shapely like API, but releasing
allocated memory seems to be
difficult in JavaScript Garbage
Collection…
From the discussion, now it
provides only low-level GEOS
C-API functions.


# Page. 20

![Page Image](https://bcdn.docswell.com/page/9J2G36ZWJR.jpg)

Characteristics of GEOS-WASM
●
Unique to compile C/C++ code by Emscripten in bindings of
GEOS
○
○
○
○
○
Unlike other GEOS bindings (Shapely, etc.) which are dynamic links to
GEOS C/C++ library.
JTS bindings (JSTS, dart_jts, NTS, etc.) port Java code to each
language, so GEOS-WASM is a bit similar to those.
GEOS patch version up requires full compilation to WebAssembly.
License is LGPL 2.1, same as GEOS.
Due to full compilation, the npm package size is bigger than Turf.js
and similar to JSTS
■ geos-wasm: 2.98 MB
■ jsts: 3.42 MB
■ @turf/turf: 658 kB


# Page. 21

![Page Image](https://bcdn.docswell.com/page/DEYV19R9EM.jpg)

Recent related topics
●
WebAssembly
○
○
●
The State of WebAssembly 2023
WebAssembly Garbage Collection (WasmGC) enabled by default in Chrome
■ Related Flutter news: Support for WebAssembly (Wasm) | Flutter
WebAssembly in FOSS4G
○
○
qgis/qgis-js (Demo)
■ QGIS runs on web browsers with Emscripten build
SotM EU 2023 workshop: Ungap the Map: designing moonshot cycling
networks by Dustin Carlino
● Client side routing with custom cost function (link)


# Page. 22

![Page Image](https://bcdn.docswell.com/page/VJNM2LDD78.jpg)

Future possibilities of WebAssembly
●
Shade routing with open 3D building data and client side
routing ?
○
○
●
From Rust existing resources (dabreegster/route_snapper) ?
Or pgRouting core C/C++ part can be exported as WebAssembly by
Emscripten ?
More interoperability across languages
○
“Component Model” which is mentioned in FOSS4G 2022 WebAssembly4G:
Where we are, and where we&#039;re heading slide’s p.20 and p.37 by
Michael Schmuki


# Page. 23

![Page Image](https://bcdn.docswell.com/page/YE9N14G8E3.jpg)

Acknowledgements
●
●
●
GEOS-WASM authors and contributors
GEOS community
And other all projects and persons in this slide


# Page. 24

![Page Image](https://bcdn.docswell.com/page/GE8K4QVZ7D.jpg)

Thank you!
●
●
GitHub: @sanak
Email: nagase@georepublic.co.jp


