Giter Club home page Giter Club logo

points-within-polygons's Introduction

points-within-polygons

A points in polygons spatial join for Rust and WebAssembly.

Background

🌵See my blog post about this experiment 2019-11-12

I modeled this after the Turf.js pointsWithinPolygon function and implemented (approximately) the same function signature in Rust. I tried to implement the same algorithm as well, to make a fair comparison of the GeoRust crates which are utilized by this crate. The Rust function signature therefore is:

pub fn points_within_polygons(
  points_fc: geojson::FeatureCollection,
  polygons_fc: geojson::FeatureCollection,
) -> Option<geojson::FeatureCollection>

Requirements

To build

git clone https://github.com/guidorice/points-within-polygons.git
cd points-within-polygons
cargo build

Run Rust unit and integration tests

cargo test

Run Rust native benchmark tests

Note: the native benchmarks also unfortunately include .clone() calls, so are not really measuring the performance of the function.

cargo +nightly bench

Run Node.js benchmarks to compare Turf.js vs this Rust crate as WebAssembly

cd wasm
rm -rf pkg
wasm-pack build --target nodejs
# See below about optimizing the .wasm file. Do this before running yarn in js/.
cd ../js
rm -rf node_modules
yarn # installs packages into node_modules/
yarn run benchmark # runs benchmark script from package.json

Recommended: run binaryen's wasm-opt optimizer

TODO: This may now be an option in wasm-pack's Cargo.toml? If so, get rid of manual steps

cd wasm/pkg
wasm-opt -O4 -o optimized.wasm points_within_polygons_wasm_bg.wasm
mv points_within_polygons_wasm_bg.wasm original.wasm
mv optimized.wasm points_within_polygons_wasm_bg.wasm
cd ../..
# now continue with js/ directory above

Example benchmark

$ yarn run benchmark
yarn run v1.19.1
$ node_modules/typescript/bin/tsc benchmark.ts && node benchmark.js
turf.js/pointsWithinPolygon on simple polygons x 10 points x 69.87 ops/sec ±15.31% (52 runs sampled)
rust-wasm pointsWithinPolgons on simple polygons x 10 points x 81.44 ops/sec ±12.67% (51 runs sampled)
turf.js/pointsWithinPolygon on simple polygons x 100 points x 8.88 ops/sec ±15.98% (25 runs sampled)
rust-wasm pointsWithinPolgons on simple polygons x 100 points x 62.52 ops/sec ±8.61% (64 runs sampled)
turf.js/pointsWithinPolygon on simple polygons x 1000 points x 1.16 ops/sec ±8.90% (7 runs sampled)
rust-wasm pointsWithinPolgons on simple polygons x 1000 points x 12.72 ops/sec ±8.40% (35 runs sampled)
turf.js/pointsWithinPolygon on complex polygons x 10 points x 10.68 ops/sec ±5.37% (31 runs sampled)
rust-wasm pointsWithinPolgons on complex polygons x 10 points x 1.82 ops/sec ±6.67% (9 runs sampled)
turf.js/pointsWithinPolygon on complex polygons x 100 points x 1.07 ops/sec ±7.52% (7 runs sampled)
rust-wasm pointsWithinPolgons on complex polygons x 100 points x 1.18 ops/sec ±5.33% (8 runs sampled)
turf.js/pointsWithinPolygon on complex polygons x 1000 points x 0.12 ops/sec ±12.22% (5 runs sampled)
rust-wasm pointsWithinPolgons on complex polygons x 1000 points x 0.24 ops/sec ±11.19% (5 runs sampled)
✨  Done in 216.71s.

points-within-polygons's People

Contributors

guidorice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

code4history

points-within-polygons's Issues

Any updates on this ?

Hello,

I've find your work really interesting ! Unfortunatelly, the blog post about your research is not available anymore. Will it ever be again ?

Did georust hadn't enough interest compared to turf.js ?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.