arrange_isobole_internal: Reorder rows of data.frame such that the shortest line is...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Isobole_gridRefinementAlgorithm.R

Description

Tests with TSP (traveling salesman problem) packages outputted nonsense, therefore this function needed to be implemented anew.

Usage

1
arrange_isobole_internal(iso_unordered, method = "euclidean")

Arguments

iso_unordered

A data.frame with columns xp and yp possibly in unfavourable order

method

handed to [stats::dist()] to calculate distance

Details

Order should be: xp: 0 ... xp(yp=0) yp: yp(xp=0) ... 0

Idea of the algorithm: Isoboles should be rather well behaved. Start by arranging x and y coordinates and then reorder such that one always goes to the next closest point

Value

Arranged isobole

Author(s)

Daniel Lill, IntiQuan daniel.lill@intiquan.com

See Also

Other Grid refinement functions for isoboles: fastIsoboles_iteration0(), fastIsoboles_iteration(), fastIsoboles(), get_gridlens(), get_isobole_path()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(data.table)
library(ggplot2)

iso_unordered <- data.frame(
  xp = c(00, 10, 10, 20, 30, 40, 50, 50, 50, 50, 60, 60, 60, 50, 50, 50),
  yp = c(80, 80, 70, 60, 60, 70, 70, 60, 50, 40, 30, 40, 20, 20, 10, 0)
)
iso_unordered <- iso_unordered[sample(1:nrow(iso_unordered), nrow(iso_unordered)),]
iso_unordered <- data.table(iso_unordered)
iso_ordered <- populationIsoboles:::arrange_isobole_internal(iso_unordered)
grid <- data.table(expand.grid(x = populationIsoboles:::seqminmax(0,100,10),
                               y = populationIsoboles:::seqminmax(0,100,10)))
grid[,`:=`(inpoly_unordered = as.numeric(as.logical(sp::point.in.polygon(
  x, y,
  c(iso_unordered[,xp], max(x), max(x), 0     , iso_unordered[,xp][1]),
  c(iso_unordered[,yp], 0,      max(y), max(y), iso_unordered[,yp][1]),
  TRUE))),
           inpoly_ordered = as.numeric(as.logical(sp::point.in.polygon(
  x, y,
  c(iso_ordered[,xp], max(x), max(x), 0     , iso_ordered[,xp][1]),
  c(iso_ordered[,yp], 0,      max(y), max(y), iso_ordered[,yp][1]),
  TRUE))))]
ggplot()  + geom_tile(aes(x,y, fill = inpoly_unordered), grid) +
  geom_path(aes(xp,yp),iso_unordered, color = "white")
ggplot()  + geom_tile(aes(x,y, fill = inpoly_ordered), grid) +
  geom_path(aes(xp,yp),iso_ordered, color = "white")

IntiQuan/populationIsoboles documentation built on Jan. 13, 2022, 8:29 p.m.