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

anglr breaks for sf geometry with no attributes #55

Closed
MilesMcBain opened this issue Dec 14, 2017 · 3 comments
Closed

anglr breaks for sf geometry with no attributes #55

MilesMcBain opened this issue Dec 14, 2017 · 3 comments

Comments

@MilesMcBain
Copy link
Contributor

Not sure if this is an anglr or silicate bug:

# Create an extent to triangulate
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.1, proj.4 4.9.3
library(anglr)
library(raster)
#> Loading required package: sp
my_extent <- st_as_sf(as(extent(c(153.185183093, 153.19443135, -27.705328446, -27.6967222119999)), 
                             "SpatialPolygons"))
anglr(my_extent, max_area = 0.008)
#> Error in .subset2(x, i, exact = exact): subscript out of bounds

my_extent$z <- 0
anglr(my_extent, max_area = 0.008)
#> $o
#> # A tibble: 1 x 2
#>       z  object_
#>   <dbl>    <chr>
#> 1     0 ea325999
#> 
#> $v
#> # A tibble: 4 x 3
#>         x_        y_    vertex_
#>      <dbl>     <dbl>      <chr>
#> 1 153.1852 -27.69672 biNoCfx5Fh
#> 2 153.1852 -27.70533 hetHjZASSt
#> 3 153.1944 -27.70533 UuxkFDs2E3
#> 4 153.1944 -27.69672 a66xCRKwTD
#> 
#> $meta
#> # A tibble: 1 x 2
#>    proj               ctime
#>   <chr>               <chr>
#> 1  <NA> 2017-12-14 04:43:32
#> 
#> $t
#> # A tibble: 2 x 2
#>    triangle_  object_
#>        <chr>    <chr>
#> 1 HHrECKtVDM ea325999
#> 2 auYuKm0Fbw ea325999
#> 
#> $tXv
#> # A tibble: 6 x 2
#>    triangle_    vertex_
#>        <chr>      <chr>
#> 1 HHrECKtVDM biNoCfx5Fh
#> 2 HHrECKtVDM hetHjZASSt
#> 3 HHrECKtVDM UuxkFDs2E3
#> 4 auYuKm0Fbw UuxkFDs2E3
#> 5 auYuKm0Fbw a66xCRKwTD
#> 6 auYuKm0Fbw biNoCfx5Fh
#> 
#> attr(,"class")
#> [1] "trimesh"

I traced the error to silicate:::sc_object.sf() which doesn't handle this case, it creates a data.frame with 0 columns.

@mdsumner
Copy link
Member

Thanks! An important silicate bug. It also needs more careful treatment because I use this faster_as_tibble hack in a few projects now. There's probably a better solution as per hypertidy/silicate#39

I haven't forced anglr to require a later version, but I'll try to synch these two soonish.

@mdsumner
Copy link
Member

And now really fixed.

@mdsumner
Copy link
Member

mdsumner commented Mar 6, 2018

It's fixed but also has changed:

library(sf)
library(anglr)
library(raster)
my_extent <- st_as_sf(as(extent(c(153.185183093, 153.19443135, -27.705328446, -27.6967222119999)), 
                         "SpatialPolygons"))
DEL(my_extent, max_area = 0.008)
## to pass z down use copy_down
copy_down(DEL(my_extent, max_area = 0.008), z = 1)

Also fwiw spex has this, which saves juggling a bit

spex::spex(extent(0, 1, 0, 1), crs = "+proj=laea")

I'll close this but feel free to re-open or pursue otherwise if you have problems!

@mdsumner mdsumner closed this as completed Mar 6, 2018
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

2 participants