Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triangulating a pslg with attributes #17

Open
roth-mh opened this issue Aug 19, 2020 · 4 comments
Open

triangulating a pslg with attributes #17

roth-mh opened this issue Aug 19, 2020 · 4 comments

Comments

@roth-mh
Copy link

roth-mh commented Aug 19, 2020

when I am triangulating a pslg object with attributes, the triangulate function seems to (kind of) transpose the attribute matrix.
in the example below i would expect PA to stay the same from the pslg object to the DT object. Am I misunderstanding the intended functionality?

sp_pts <- as.data.frame(matrix(nrow=4,ncol = 2))
colnames(sp_pts) <- c("latitude", "longitude")
sp_pts$latitude <- c(41,42,43,44)
sp_pts$longitude <- c(-120,-121,-122,-123)

att <- as.data.frame(matrix(nrow=4,ncol = 3))
colnames(att) <- c("att1", "att2", "att3")
att$att1 <- c(1, 1.1, 1.11, 1.111)
att$att2 <- c(2, 2.2, 2.22, 2.222)
att$att3 <- c(3, 3.3, 3.33, 3.333)

att
p <- pslg(P = sp_pts, PA = att)
p$PA[1,]

DT <- RTriangle::triangulate(p)
DT$PA[1,]

p$PA
DT$PA
@DOSull
Copy link

DOSull commented May 15, 2021

I am seeing the same behaviour, where I expect PA to emerge unscathed from the triangulation it ends up 'row-wise' in the output not 'column-wise':

tri <- pslg(P = tpts, PA = tattrs) %>%
  triangulate()

> head(tattrs)
           x       y
1  -428675.9 1520344
2 -1197290.8 7794188
3 -1120150.7 7234575
4 -1048583.9 6613223
5  -973499.6 5945572
6  -892969.4 5242144
> head(tri$PA)
           [,1]       [,2]
[1,]  -428675.9 -1197290.8
[2,] -1120150.7 -1048583.9
[3,]  -973499.6  -892969.4
[4,]  -807038.3  -716485.6
[5,]  -622414.4  -526061.0
[6,] -1524302.5 -1417125.3

@DOSull
Copy link

DOSull commented May 15, 2021

For what it's worth, I can untangle the attributes matrix with this function, but obviously would be a lot better to fix it at source!

untangle <- function(triPA) { 
  return ( matrix( c( t( triPA ) ), ncol = dim(triPA)[2] ) );
}

or with pipes

untangle <- function(triPA) {
  nc <- dim(triPA)[2]
  return (triPA %>% 
            t() %>%               # transpose
            c() %>%               # vectorise
            matrix(ncol = nc))    # column-wise repopulate the original shape
}

@davidcsterratt
Copy link
Owner

Sorry for the delay in looking at this. It would indeed be desirable to fix the issue. I have been very busy, but I hope to have some time next week (during my holiday) to look at it properly.

@DOSull
Copy link

DOSull commented May 18, 2021

This isn't more important than your holiday (at least not for me)! I assume the issue is some kind of index inversion when you are populating the output PA matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants