Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/statnmap/GeoDist
Constrained distance calculation and associated geotools
https://github.com/statnmap/GeoDist
Last synced: about 2 months ago
JSON representation
Constrained distance calculation and associated geotools
- Host: GitHub
- URL: https://github.com/statnmap/GeoDist
- Owner: statnmap
- License: gpl-3.0
- Created: 2017-11-01T21:21:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T16:44:17.000Z (over 4 years ago)
- Last Synced: 2024-05-21T02:53:25.267Z (4 months ago)
- Language: R
- Size: 95.7 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# GeoDist: Constrained distance calculation and associated geotools
**Work in progress**
This R-package allows the calculation of distances that are contrained by frontiers, islands, mountains,... Distances are calculated from a raster grid of the area.
_From A to B_
A XXX
| XXXXXX
| XXXXXXXX
|XXXXXXXX
\ XXXXXX
\_XX_ _ BThese distances can then be implemented in classical geotools like inverse distance interpolation (`idw.dist`) or kriging with a modified version of `geoR` functions that accept custom calculated distances (`variog.dist`, `likfit.dist`, `krige.conv.dist`).
Currently distances are calculated using library `igraph`, but library `Rvcg` would be much more efficient (I keep that in mind for one day...).
# Download and Install
To download the development version of the `GeoDist` package, type the following at the R command line:
```r
install.packages("devtools")
devtools::install_github("statnmap/GeoDist")
```Note that spatial libraries like `rgdal` and `sp` may require additional softwares to be installed on your computer if you work with Mac or Linux. Look how to install `proj4`, `geos` and `gdal` on your system.
## Example
```{r example}
library(GeoDist)
library(raster)
library(sp)## basic example code
crs_merc <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m"
# Create raster
r <- raster(ncol = 20, nrow = 20,
crs = crs_merc)
values(r) <- 1
values(r)[125:127] <- NA
values(r)[145:147] <- NA
values(r)[165:167] <- NA
plot(r)# Create points
from_coords <- cbind(-150, 40)
from_sp <- SpatialPointsDataFrame(coords = from_coords,
data = data.frame(label = "start"),
proj4string = CRS(crs_merc))to_coords <- matrix(c(50, 0, 100, -50), byrow = TRUE, ncol = 2)
to_sp <- SpatialPointsDataFrame(coords = to_coords,
data = data.frame(label = c("end1", "end2")),
proj4string = CRS(crs_merc))plot(r)
points(from_sp, pch = 20, col = "blue")
points(to_sp, pch = 20, col = "red")# For "from" and "to" being SpatialPoints
allpath <- dist.obstacle(from = from_sp, to = to_sp, r.ref = r, keep.path = TRUE)# All path from "from[1,]" to all "to"
lines(allpath$listLines)
```Please note that the 'GeoDist' project is released with a
[Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.