Closed dankelley closed 3 years ago
This is built-in to sf, too:
line <- sf::st_sfc(
sf::st_linestring(rbind(c(179, 2), c(-179, 2))),
crs = "OGC:CRS84"
)
sf::st_wrap_dateline(line)
#> Geometry set for 1 feature
#> Geometry type: MULTILINESTRING
#> Dimension: XY
#> Bounding box: xmin: -180 ymin: 2 xmax: 180 ymax: 2
#> Geodetic CRS: WGS 84
#> MULTILINESTRING ((179 2, 180 2), (-180 2, -179 2))
Created on 2021-09-21 by the reprex package (v2.0.1)
Thanks, we'll look into the speed! You're great, D!
I see how to do it (altered code). @j-harbin will try out some speed examples later today.
linesPossiblySplit <- function(x, y, ...)
{
jump <- which(abs(diff(x)) > 300)
if (length(jump)) {
x[jump] <- NA
y[jump] <- NA
}
lines(x, y, ...)
}
x <- c(seq(150, 180, 5), seq(-180, -150, 5))
y <- sin(x * pi/180)
plot(x, y, type="o", pch=20, col="gray", lwd=4)
abline(v=c(-180, 180), col=4, lwd=2)
linesPossiblySplit(x, y, col="red", lwd=2)
xy2 <- sf::st_sfc(sf::st_linestring(cbind(x,y)), crs="OGC:CRS84")
xy3 <- sf::st_wrap_dateline(xy2)[[1]]
for (segment in seq_along(xy3)) {
lines(xy3[[segment]][,1], xy3[[segment]][,2], col="magenta", lwd=5)
}
Created on 2021-09-21 by the reprex package (v2.0.1)
I'll look at this. I need to study up a bit on how to slice and dice the sf objects (e.g. to see if they have been split up). I can fiddle with objects to learn the structure but I do hope to find docs that tell me how I should slice and dice using an API.
It seems to me that unsplit items inherit from LINESTRING
and that split ones inherit from MULTILINESTRING
. I'll use that to decide what to do.
@j-harbin I think I have this working now in "develop". Below is a screenshot with year-to-date. It is slow, but I think that's better than unusable. On my machine, it took maybe 1 to 2 minutes to render this. Of course, a year of data is a fair bit to handle.
Please have a check of this. If you think it's OK, let me know and I'll merge into "master". (I will be offline for 2 to 3 hours now.)
PS. the bottom of the pic is cut off because I use a big font on a small screen.
Hi Dan,
The path looks great. I just went in and played around with to make sure the settings tab, etc. was still working and it was. One thing I will note, and I'm not sure if this was just introduced, or if we just didn't noticed it, but when you do the following steps, we see no profiles. This could be a new separate issue.
Note that if you do the same above steps but don't click to see the path, then the double click operation works as we would expect.
I wonder if we could Z sometime so I can see? I'm about to go to my 2nd class now.
Please see discussions in https://github.com/ArgoCanada/argoFloats/issues/504 about the double click problem. I was wrong and this is not specific to when "path" is on. This is a completely separate issue. In conclusion, I will close this issue (since I opened it) and we can focus further discussions in https://github.com/ArgoCanada/argoFloats/issues/504
Whoops! I didn't open this issue :) . I'll reopen.
Done (verified in f2f).
The screenshot below shows this. I won't bother explaining since @j-harbin and I will talk about this in a meeting this morning. I know how to fix this kind of thing in C (looking through the elements of vectors at high speed, interpolating to boundaries, inserting a point on one boundary, then a NA line, then an interpolated point on the other boundary) but I don't want argoFloats to require compilation, and doing that in R will be very slow.
There is a crude way: just replace big jumps with NA values. This will mean losing a point or two, but that's certainly better than having these ugly lines, and it's a stop-gap measure unless I can find a fast way to do it in R (or decide to bite the bullet and make the package require compilation).
Snapshot
Reprex illustrating crude solution
Created on 2021-09-21 by the reprex package (v2.0.1)