A rust crate for building zones

It is an in-progress project to implement the functionality in the

zonebuilder

.

zonebuilder R package in the systems programming language Rust.

Why?

  • It should eventually enable more people to benefit from free and open source software for creating zoning systems because Rust enables the creation of binaries for Windows, Mac and the free and open source Linux operating system on which the package was originally developed
  • To enable deployment of the zonebuilder techniques online, as demonstrated in the web folder (Rust can also compile to WASM enabling complex applications such as A/B Street to run in browser — the thinking being if that can run in browser surely as simple application to build zones can!)
  • Computational efficiency: the process of building zones is not particularly computationally intensive but this Rust crate may eventually be fast and quick to install and use, possibly from higher level languages such as R using Rust interfaces such as extendr
  • For fun and education: as a simple crate it serves as a good way to show how Rust code is organised and how it works

Installation

Installation with cargo

To reproduce the example shown here you need to have the rust toolchain installed.

Assuming you do, you can install the crate as follows:

cargo install --git https://github.com/zonebuilders/zonebuilder-rust --branch main

Download and run binaries

Rust can create binaries for all major operating systems. Watch this space for how to run zonebuilders using a binary (no compilation or Rust toolchain required).

Running zonebuilder from the system command line

The zonebuilder binary has a command line interface. Assuming you are installing the crate locally, you can build the binary for Windows, Mac and Linux system shells as follows:

cargo build
##     Finished dev [unoptimized + debuginfo] target(s) in 0.02s

You can see instructions on using the tool with the following command:

./target/debug/zonebuilder -h
## zb 0.1.0
## Configures a clockboard diagram
## 
## USAGE:
##     zonebuilder [FLAGS] [OPTIONS]
## 
## FLAGS:
##     -h, --help         Prints help information
##         --projected    Is the data projected?
##     -V, --version      Prints version information
## 
## OPTIONS:
##     -d, --distances <distances>...
##             The distances between concentric rings. `triangular_sequence` is useful to generate these distances
##             [default: 1.0,3.0,6.0,10.0,15.0]
##     -s, --num-segments <num-segments>
##             The number of radial segments. Defaults to 12, like the hours on a clock [default: 12]
## 
##     -v, --num-vertices-arc <num-vertices-arc>
##             The number of vertices per arc. Higher values approximate a circle more accurately [default: 10]
## 
##     -p, --precision <precision>
##             The number of decimal places in the resulting output GeoJSON files. Set to 6 by default. Larger numbers mean
##             more precision, but larger file sizes [default: 6]

Let’s try making zones with fewer segments and circles (specified by the -s and -d arguments respectively):

./target/debug/zonebuilder -s 3 -d 1.0,3.0 > zones.geojson

The The result looks like this:

You can also set the precision of outputs. The default is 6 decimal places, as shown in the output below:

head(sf::st_coordinates(z))
##             X        Y L1 L2
## [1,] 0.000000 0.009043  1  1
## [2,] 0.001867 0.008846  1  1
## [3,] 0.003653 0.008261  1  1
## [4,] 0.005280 0.007316  1  1
## [5,] 0.006675 0.006051  1  1
## [6,] 0.007779 0.004521  1  1

Let’s see the output when a precision of 2 decimal places is used:

./target/debug/zonebuilder --precision 2 > zones.geojson

That results in this:

You can run the crate as follows (note the use of -- to pass the arguments to the zonebuilder binary not cargo run):

cargo run -- --precision 3 > zones.geojson
##     Finished dev [unoptimized + debuginfo] target(s) in 0.02s
##      Running `target/debug/zonebuilder --precision 3`

Take a look at the output:

head -n 20 zones.geojson
## {
##   "features": [
##     {
##       "geometry": {
##         "coordinates": [
##           [
##             [
##               0.0,
##               0.009
##             ],
##             [
##               0.0,
##               0.009
##             ],
##             [
##               0.0,
##               0.008
##             ],
##             [
##               0.001,

Then read in the GeoJSON file with another tool, e.g. R (this step runs from an R console that has the sf library installed):

zones = sf::read_sf("zones.geojson")
plot(zones)

# interactive version:
# mapview::mapview(zones)
file.remove("zones.geojson")
## [1] TRUE

You can generate the same plot in R with the zonebuilder package as follows:

zones = zonebuilder::zb_zone(x = "london", n_circles = 5)
## Loading required namespace: tmaptools
plot(zones$geometry)

Issues

Collection of the latest Issues

Robinlovelace

Robinlovelace

0

Currently the outputs are unprojected. You can set the centrepoint, e.g. as shown in the example:

https://github.com/zonebuilders/zonebuilder-rust/blob/34438a38bec06010db5d0f4eb57cb6cb2c7f9e9d/examples/clockboard-example.rs#L9

That creates a distorted zoning system in unhelpful units of decimal degrees, which looks decidedly egg-like, as illustrated in the reproducible example below:

Created on 2021-05-01 by the reprex package (v2.0.0)

Here's the output with a base-map, even more egg-like.

image

dabreegster

dabreegster

1

There are different approaches for programatically verifying the clockboard code produces the correct output. The extreme example would generate the results for some input, then we would manually inspect it, and check it in as a "golden file." The unit test would just assert the output is exactly the same. This is a brittle test, and not too interesting in this case.

But there are some basic properties in the output we could check -- like that the number of polygons generated corresponds to the radii and num_segments. And we could check the points in the polygon are within the correct distance of the center point.

dabreegster

dabreegster

1

Not sure if the R zb has this yet, but it seems like another obvious scheme people use. This one has much easier math, of course. If the number of parameters isn't as overwhelming -- maybe it's just center, the square grid size, and an optional boundary -- then probably a separate Options struct with Default is overkill.

Versions

Find the latest versions by id

Information - Updated Feb 24, 2022

Stars: 10
Forks: 3
Issues: 8

wasm-bindgen-console-logger

This small utility crate integrates the wasm-bindgen

wasm-bindgen-console-logger

Command Line Argument Parser for Rust

It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcommands when writing command line, console or terminal applications

Command Line Argument Parser for Rust

Simple console tool for macOS, that helps to store your passwords in a cryptocontainer

The cryptocontainer is encrypted using AES-256 cipher

Simple console tool for macOS, that helps to store your passwords in a cryptocontainer

A logger that routes messages to the browser's console

Rust's log levels map to the browser's console log in the following way

A logger that routes messages to the browser's console

This library helps you interact with the MoC (Music on Console) server running on

your system thru the binary, which in the case of arch linux (and manjaro) is

This library helps you interact with the MoC (Music on Console) server running on

console_error_panic_hook

This crate lets you debug panics on wasm32-unknown-unknown by providing a

console_error_panic_hook

Rust bindings for the Newt console UI library

Newt is a small and simple to use UI library providing widgets and

Rust bindings for the Newt console UI library

A rust crate for managing multiple consoles from one windows application

Normaly a program running on windows can only use one console

A rust crate for managing multiple consoles from one windows application

A Rust library for parsing Smash Ultimate XMB files

The binary application prints an XMB file to the console in JSON format

A Rust library for parsing Smash Ultimate XMB files

Command-line interface (CLI) to display a Shiba Inu whenever needed, by just running shiba on...

Command-line interface (CLI) to display a Shiba Inu whenever needed, by just running shiba on the terminal/console

Command-line interface (CLI) to display a Shiba Inu whenever needed, by just running shiba on...
Facebook Instagram Twitter GitHub Dribbble
Privacy