Crates.io | geoprox |
lib.rs | geoprox |
version | 0.5.0 |
source | src |
created_at | 2024-05-01 16:22:04.515567 |
updated_at | 2024-08-23 20:59:43.391094 |
description | Standalone CLI for running the Geoprox service |
homepage | |
repository | https://github.com/ezrasingh/geoprox |
max_upload_size | |
id | 1226520 |
size | 105,966 |
A standalone runtime for the Geoprox project.
Geoprox is an in-memory geospatial search engine designed for efficient real-time location-based pairing.
It helps quickly identify users or entities near a specific location, making it ideal for applications that need to match contracts with nearby users. Whether it's for ride-sharing services like Uber and Lyft or delivery platforms like Grubhub, Geoprox provides the speed and accuracy needed to enhance geo-aware interactions.
Discussed @ May 2024 Rust Indy.rs meetup
This crate offers a command-line tool for launching and managing the Geoprox server.
To install geoprox
, use the following command:
cargo install geoprox
Geoprox provides several commands to start the server and work with geohashes:
geoprox help
Usage: geoprox [COMMAND]
Commands:
run Start Geoprox server
encode Hash latitude/longitude into geohash
decode Decode geohash into approximate longitude/latitude
spec Generate an OpenAPI specification file
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
To start using Geoprox, you can run the following command to start the server:
geoprox run
You can also encode and decode geohashes directly from the CLI:
# Encode latitude and longitude into geohash
geoprox encode --lat=37.7749 --lng=-122.4194 --depth=5
# Decode geohash into latitude and longitude
geoprox decode 9q8yy
For detailed help on any command, use the help command:
geoprox help encode
Geoprox allows specifying a configuration file using the -c
or --config
option or set the GEOPROX_CONFIG
environment variable. This file can contain various settings to customize the behavior of the Geoprox server and commands. The configuration can be provided in any common format such as YAML
, TOML
, JSON
, or INI
.
Specify config using -c
flag:
# from current working directory
geoprox run -c geoprox.toml
# from absolute path
geoprox run -c /my/custom/config.yaml
or using environment variables:
export GEOPROX_CONFIG='/my/custom/config.json'
geoprox run
Here's an example configuration file in TOML
format:
# All settings are optional; these are the default values.
[server]
# The address the server will bind to
http_addr = '0.0.0.0'
# The port the server will listen on
http_port = 5000
# Request timeout
timeout = '10s'
[shard]
# Determines the default geohash length for inserts
insert_depth = 6
# Determines the default geohash length for searches
search_depth = 6
# Specifies the default number of results returned in range queries
default_count = 100
# Toggles the default sorting behavior for query results
default_sorted = false
[server.snapshots]
# Toggle snapshot usage
disabled = false
# Directory where snapshots will be stored
path = '/var/lib/geoprox/snapshots'
# How often snapshots will be taken
every = '30s'
These are the currently supported environment variables. They will take precedence over settings defined in the configuration file.
Environment Variable | Description | Default Value |
---|---|---|
GEOPROX_CONFIG |
Specifies the configuration file path. | |
GEOPROX_HTTP_ADDR |
The address the server will bind to. | 0.0.0.0 |
GEOPROX_HTTP_PORT |
The port the server will listen on. | 5000 |
Geohashes divide the world into a grid of cells, each with a unique identifier (encoded in base 32). The precision of the geohash can be adjusted by changing its length:
Geohash Length | Lat Bits | Lng Bits | Lat Error | Lng Error | Km Error |
---|---|---|---|---|---|
1 | 2 | 3 | ±23 | ±23 | ±2,500 km (1,600 mi) |
2 | 5 | 5 | ±2.8 | ±5.6 | ±630 km (390 mi) |
3 | 7 | 8 | ±0.70 | ±0.70 | ±78 km (48 mi) |
4 | 10 | 10 | ±0.087 | ±0.18 | ±20 km (12 mi) |
5 | 12 | 13 | ±0.022 | ±0.022 | ±2.4 km (1.5 mi; 2,400 m) |
6 | 15 | 15 | ±0.0027 | ±0.0055 | ±0.61 km (0.38 mi; 610 m) |
7 | 17 | 18 | ±0.00068 | ±0.00068 | ±0.076 km (0.047 mi; 76 m) |
8 | 20 | 20 | ±0.000085 | ±0.00017 | ±0.019 km (0.012 mi; 19 m) |
For example, a depth of 6 corresponds to a geohash precision of approximately 1km x 1km. This is the default depth and generally recommended, as greater precision (smaller depths) may not be necessary for most use cases.
The insert_depth
and search_depth
settings control the precision of geohashing and impact the performance of distance calculations and search queries.
insert_depth
Higher Insert Depth:
Lower Insert Depth:
search_depth
Higher Search Depth:
Lower Search Depth:
Contributions are welcome! Please see the contributing guidelines for more information.
This project is licensed under the Apache 2.0 or MIT License (your choice).