Giter Site home page Giter Site logo

rsgeo's Introduction

rsgeo

Build Status crates.io

rsgeo is a geography tool which is written with Rust.

简体中文

Installation

Add it to your Cargo.toml

[dependencies]
rsgeo = "0.1.3"

Usage

Create two points with latitude and longitude,and get distance between two points

use rsgeo::prelude::*;
let p1 = Point::new(30.12, 125.26).unwrap(); 
let p2 = Point::new(32.54, 107.15).unwrap();
println!("{}",p1.distance(&p2)); //1740784.4 

Get the degree from p1 to p2(the degree to north)

println!("{}",p1.degree(&p2)); //-82.38877

Create a Location

let p = Point::new(35.12,46.15).unwrap();
let loc = Location::new(p,232500);
// a location is a point with a unix timestamp

Get the distance of location and point.

println!("{}",loc.distance_from_point(&p1)); //7237628.5

Get the speed of two locations

let loc1 = Location::new(Point::new(25.12,110.15).unwrap(),100);
let loc2 = Location::new(Point::new(25.119,109.995).unwrap(),3700);
assert!(loc1.speed(&loc2) - 4.3396673 < 1e-6); // m/s

Create Area and test if the point is in it.

let ra = RecArea::new(35.0, 36.0, 110.0, 115.0).unwrap();
let pa = Point::new(32.0,112.0).unwrap();
let pb = Point::new(35.1,112.0).unwrap();
assert!(!ra.contains(&pa));
assert!(ra.contains(&pb));
let ca = CircleArea::new(Point::new(35.0, 110.0).unwrap(), 350_000.0);
let pa = Point::new(32.0, 112.0).unwrap();
let pb = Point::new(35.1, 112.0).unwrap();
assert!(!ca.contains(&pa));
assert!(ca.contains(&pb));

Create a polygon and test if the point is in it.

let pa = Point::new(32.0,112.0).unwrap();
let pb = Point::new(35.1,112.0).unwrap();
let pc = Point::new(35.3,112.5).unwrap();
let pg = Polygon::new(vec![pa,pb,pc]);
assert!(pg.is_err());
// polygon must have more than 3 points.The first point must be the same with the last point.
// the polygon can be convex or concave whatever
let pg = Polygon::new(vec![pa,pb,pc,pa]);
assert_eq!(pg.unwrap().len(),4);
let pt1 =  Point::new(35.0,112.2).unwrap();
let pt2 =  Point::new(34.29,110.3).unwrap();
assert!(pg.contains(&pt1));
assert!(!pg.contains(&pt2));

Create a Trajectory

// A trajectory is a vector of some locations which must be chronological order.
let mut t = Trajectory::new();
let mut t = Trajectory::with_capacity(); // like a vector
let loc1 = Location::new(Point::new(25.11,120.98).unwrap(),0);
let loc2 = Location::new(Point::new(26.2,121.1).unwrap(),7200);
let loc3 = Location::new(Point::new(26.3,121.3).unwrap(),14400);
t.push_location(&loc1);
t.push_location(&loc2);
t.push_location(&loc3);
let mut t = Trajectory::from(vec![loc1,loc2,loc3].as_slice()).unwrap(); // or initialize with a slice of locations

Get the num of locations in Trajectory

assert_eq!(t.len(),3);

Test if the trajectory passes area or polygon

let area1 = RecArea::new(25.07,27.12,119.9,125.0).unwrap();
assert!(t.pass_rec_area(&area1));

Get the speed of a trajectory

let loc1 = Location::new(Point::new(25.11,120.98).unwrap(),0);
let loc2 = Location::new(Point::new(26.2,121.1).unwrap(),7200);
let loc3 = Location::new(Point::new(26.3,121.3).unwrap(),14400);
let mut t = Trajectory::with_capacity(3);
t.push_location(&loc1);
t.push_location(&loc2);
t.push_location(&loc3);
assert!((t.max_speed().unwrap() - 16.9352).abs() < 1e-3);
assert!((t.mean_speed().unwrap() - 10.055225).abs() < 1e-6);

Get the sum of distance of a trajectory

assert!((t.sum_distance() - 144795.25).abs() < 1e6);

Compare two trajectories and return the similarity of two trajectories.

use rsgeo::prelude::*;
use rsgeo::measure::stlc_trajectory_similarity;
assert!((stlc_trajectory_similarity(&t, &t, 0.5).unwrap()-1.0).abs() < 1e-6);
// stlc is spatiotemporal linear combin distance
// the function returns similarity which is in (0,1]

rsgeo's People

Contributors

chuxiuhong avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rsgeo's Issues

issue with remotes::install_dev("rsgeo")

Hi, Josiah

I encountered the following error while installing the Dev version of "rsgeo" on Windows 11.

remotes::install_dev("rsgeo")
Downloading GitHub repo JosiahParry/rsgeo@HEAD
── R CMD build ─────────────────────────────────────────────────────────────────────────────────────remotes::install_dev("rsgeo")
Downloading GitHub repo JosiahParry/rsgeo@HEAD
── R CMD build ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file 'C:\Users\wangz\AppData\Local\Temp\RtmpwRRYK7\remotes32bc412f7374\JosiahParry-rsgeo-ef1ea1c/DESCRIPTION'
─  preparing 'rsgeo': (1.3s)
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building 'rsgeo_0.1.6.9000.tar.gz'
   Warning: file 'rsgeo/configure' did not have execute permissions: corrected
   
Installing package into 'C:/Users/wangz/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
* installing *source* package 'rsgeo' ...
** using staged installation
** libs
Warning: this package has a non-empty 'configure.win' file,
so building only the main architecture

using C compiler: 'gcc.exe (GCC) 12.2.0'
rm -Rf rsgeo.dll ./rust/target/x86_64-pc-windows-gnu/release/librsgeo.a entrypoint.o
gcc  -I"C:/PROGRA~1/R/R-43~1.1/include" -DNDEBUG     -I"c:/rtools43/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c entrypoint.c -o entrypoint.o
# uncompress vendored deps
if [ -f ./rust/vendor.tar.xz ]; then \
        tar xf rust/vendor.tar.xz && \
        mkdir -p /c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo && \
        cp rust/vendor-config.toml /c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo/config.toml; \
fi
mkdir -p ./rust/target/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch ./rust/target/libgcc_mock/libgcc_eh.a
# CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2
if [ "" != "true" ]; then \
        export CARGO_HOME=/c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo; \
fi && \
        export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="x86_64-w64-mingw32.static.posix-gcc.exe" && \
        export LIBRARY_PATH="${LIBRARY_PATH};/c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/./rust/target/libgcc_mock"; \
        cargo build -j 2 --offline --target=x86_64-pc-windows-gnu --lib --release --manifest-path=./rust/Cargo.toml --target-dir ./rust/target && \
        echo `cargo --version` && echo `rustc --version`;
   Compiling autocfg v1.1.0
   Compiling scopeguard v1.2.0
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:192:1
    |
192 | extern crate core as std;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    |
    = note: the `x86_64-pc-windows-gnu` target may not be installed
    = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error: cannot find macro `stringify` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:487:24
    |
487 |         f.debug_struct(stringify!(ScopeGuard))
    |                        ^^^^^^^^^

error: cannot find attribute `derive` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:212:3
    |
212 | #[derive(Debug)]
    |   ^^^^^^

   Compiling semver v1.0.18
error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:306:8
    |
306 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:317:8
    |
317 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:377:8
    |
377 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Sync` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:435:22
    |
435 | unsafe impl<T, F, S> Sync for ScopeGuard<T, F, S>
    |                      ^^^^ not found in this scope

error[E0405]: cannot find trait `Sync` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:437:8
    |
437 |     T: Sync,
    |        ^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:438:8
    |
438 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:445:8
    |
445 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:457:8
    |
457 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Drop` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:465:15
    |
465 | impl<T, F, S> Drop for ScopeGuard<T, F, S>
    |               ^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:467:8
    |
467 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:483:8
    |
483 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

Some errors have detailed explanations: E0405, E0463.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `scopeguard` (lib) due to 16 previous errors
warning: build failed, waiting for other jobs to finish...
make: *** [Makevars.win:26: rust/target/x86_64-pc-windows-gnu/release/librsgeo.a] Error 101
ERROR: compilation failed for package 'rsgeo'──────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file 'C:\Users\wangz\AppData\Local\Temp\RtmpwRRYK7\remotes32bc412f7374\JosiahParry-rsgeo-ef1ea1c/DESCRIPTION'
─  preparing 'rsgeo': (1.3s)
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building 'rsgeo_0.1.6.9000.tar.gz'
   Warning: file 'rsgeo/configure' did not have execute permissions: corrected
   
Installing package into 'C:/Users/wangz/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
* installing *source* package 'rsgeo' ...
** using staged installation
** libs
Warning: this package has a non-empty 'configure.win' file,
so building only the main architecture

using C compiler: 'gcc.exe (GCC) 12.2.0'
rm -Rf rsgeo.dll ./rust/target/x86_64-pc-windows-gnu/release/librsgeo.a entrypoint.o
gcc  -I"C:/PROGRA~1/R/R-43~1.1/include" -DNDEBUG     -I"c:/rtools43/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c entrypoint.c -o entrypoint.o
# uncompress vendored deps
if [ -f ./rust/vendor.tar.xz ]; then \
        tar xf rust/vendor.tar.xz && \
        mkdir -p /c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo && \
        cp rust/vendor-config.toml /c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo/config.toml; \
fi
mkdir -p ./rust/target/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch ./rust/target/libgcc_mock/libgcc_eh.a
# CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2
if [ "" != "true" ]; then \
        export CARGO_HOME=/c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/.cargo; \
fi && \
        export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="x86_64-w64-mingw32.static.posix-gcc.exe" && \
        export LIBRARY_PATH="${LIBRARY_PATH};/c/Users/wangz/AppData/Local/Temp/RtmpUzM082/R.INSTALL34b429a55ad/rsgeo/src/./rust/target/libgcc_mock"; \
        cargo build -j 2 --offline --target=x86_64-pc-windows-gnu --lib --release --manifest-path=./rust/Cargo.toml --target-dir ./rust/target && \
        echo `cargo --version` && echo `rustc --version`;
   Compiling autocfg v1.1.0
   Compiling scopeguard v1.2.0
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:192:1
    |
192 | extern crate core as std;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    |
    = note: the `x86_64-pc-windows-gnu` target may not be installed
    = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error: cannot find macro `stringify` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:487:24
    |
487 |         f.debug_struct(stringify!(ScopeGuard))
    |                        ^^^^^^^^^

error: cannot find attribute `derive` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:212:3
    |
212 | #[derive(Debug)]
    |   ^^^^^^

   Compiling semver v1.0.18
error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:306:8
    |
306 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:317:8
    |
317 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:377:8
    |
377 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Sync` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:435:22
    |
435 | unsafe impl<T, F, S> Sync for ScopeGuard<T, F, S>
    |                      ^^^^ not found in this scope

error[E0405]: cannot find trait `Sync` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:437:8
    |
437 |     T: Sync,
    |        ^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:438:8
    |
438 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:445:8
    |
445 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:457:8
    |
457 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Drop` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:465:15
    |
465 | impl<T, F, S> Drop for ScopeGuard<T, F, S>
    |               ^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:467:8
    |
467 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

error[E0405]: cannot find trait `FnOnce` in this scope
   --> C:\Users\wangz\AppData\Local\Temp\RtmpUzM082\R.INSTALL34b429a55ad\rsgeo\src\vendor\scopeguard\src\lib.rs:483:8
    |
483 |     F: FnOnce(T),
    |        ^^^^^^ not found in this scope

Some errors have detailed explanations: E0405, E0463.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `scopeguard` (lib) due to 16 previous errors
warning: build failed, waiting for other jobs to finish...
make: *** [Makevars.win:26: rust/target/x86_64-pc-windows-gnu/release/librsgeo.a] Error 101
ERROR: compilation failed for package 'rsgeo'

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.