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

file vagaries #1

Open
mdsumner opened this issue Jun 16, 2016 · 0 comments
Open

file vagaries #1

mdsumner opened this issue Jun 16, 2016 · 0 comments

Comments

@mdsumner
Copy link
Member

Running intersection tests between boxes and their related faces

bgmfiles/extdata/bgm/VMPA_setas.bgm Box1 has a non-coincident face

bgmfiles/extdata/bgm/Nordic02.bgm gives a similar problem

Run this code to see it

library(testthat)
context("round-trip of BGM links")

#devtools::install_github("mdsumner/rbgm")
library(rbgm)
library(dplyr)
library(spdplyr)
#bfile <- grep("antarctica_99", bgmfiles::bgmfiles(), value = TRUE)
for (bfile in bgmfiles::bgmfiles()[-10]) {
  context(sprintf("reading file %s", basename(bfile)))
  bgm <- bgmfile(bfile)
  polybgm <- rbgm::boxSpatial(bgm)
  linebgm <- rbgm::faceSpatial(bgm)

  ## note the minus one on seq
  for (abox in (seq(nrow(polybgm)) -1)) {
    aline <- linebgm %>% filter(.fx0 %in% (bgm$facesXboxes %>% dplyr::filter(.bx0 == abox))$iface)
    poly <- polybgm %>% filter(.bx0 == abox) 
#    plot(poly)
#    plot(aline, add = TRUE, col = "red")

    #scan("", 1)
    test_that("round tripping works to get the right box and faces", {
      expect_true(rgeos::gIntersects(aline, poly))
      expect_true(rgeos::gCovers(poly, aline))
      expect_true(rgeos::gCoveredBy(aline, poly))

    })
  }
}
> poly
class       : SpatialPolygonsDataFrame 
features    : 1 
extent      : 4005592, 4181372, 1128505, 1253285  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=134 +x_0=3000000 +y_0=6000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
variables   : 10
Source: local data frame [1 x 10]

  label nconn  botz       area vertmix horizmix insideX insideY  .bx0 boundary
  (chr) (int) (int)      (dbl)   (dbl)    (int)   (dbl)   (dbl) (dbl)    (lgl)
1  Box1     5  -110 7921941564   1e-06        1 4100100 1176682     1    FALSE
> aline
class       : SpatialLinesDataFrame 
features    : 5 
extent      : 4095246, 4279136, 1128505, 1451038  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=134 +x_0=3000000 +y_0=6000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
variables   : 7
Source: local data frame [5 x 7]

      cosine       sine  left right    length  .fx0  label
       (dbl)      (dbl) (int) (int)     (dbl) (dbl)  (chr)
1  0.9994038 0.03452719     3     6 51182.712     1  face1
2 -0.6711783 0.74129596     2     1  5381.563    10 face10
3 -0.3809517 0.92459493     1     2 13499.151    11 face11
4  0.5837790 0.81191258     2     1 61123.723    13 face13
5  0.9362980 0.35120648     1     2 53875.333    17 face17
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

1 participant