-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Description
related tot this item #290 :
when I have:
library(tidyverse)
library(sf) # lates dev version
# toy df
df <- data.frame(
id=c("A","A","B","B","B","C"),
x=c(1,2,4,3,3,5),
y=c(1,2,4,3,5,5))
# note C !
I like to make a 'MULTIPLELINESTRING' object based on id and calculate length
df %>% st_as_sf(coords=c('x','y'),crs=4326) %>%
group_by(id) %>%
summarize() %>%
st_cast() %>% # this needs to be here, makes multipoint
st_cast('MULTILINESTRING') %>%
ggplot(aes(color=id)) + geom_sf()
this looks good (disregard the legend):
I need length of line segments but this obvouisly fails because "C" is a multilinestring geometry with
only one point
df %>% st_as_sf(coords=c('x','y'),crs=4326) %>%
group_by(id) %>% summarize() %>% st_cast() %>% st_cast('MULTILINESTRING') %>%
st_cast() %>% st_length()
#Error in p[1, ] : subscript out of bounds
checking geometry with st_is_valid and st_make_valid reveals some unexpected results ....
# st_is_valid
df %>% st_as_sf(coords=c('x','y'),crs=4326) %>%
group_by(id) %>% summarize() %>% st_cast() %>% st_cast('MULTILINESTRING') %>%
st_cast() %>% st_is_valid()
[1] TRUE TRUE NA
#
# st_is_valid should return a logical vector (i guess)
# I expected FALSE on the third item.....
#st_make_valid
df %>% st_as_sf(coords=c('x','y'),crs=4326) %>%
group_by(id) %>% summarize() %>% st_cast() %>% st_cast('MULTILINESTRING') %>%
st_cast() %>% st_make_valid()
Error in CPL_make_valid(x) :
st_make_valid requires compilation against liblwgeom
# how do I get liblwgeom?
# also st_is_simple chokes on this ....
#st_is_simple
df %>% st_as_sf(coords=c('x','y'),crs=4326) %>%
group_by(id) %>% summarize() %>% st_cast() %>% st_cast('MULTILINESTRING') %>%
st_cast() %>% st_is_simple()
Error in CPL_geos_is_simple(st_geometry(x)) :
IllegalArgumentException: point array must contain 0 or >1 elements
#
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7600)
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252
[3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.10.4 sf_0.4-2 mapview_1.2.0
[4] leaflet_1.0.1 sp_1.2-4 dplyr_0.5.0
[7] purrr_0.2.2 readr_1.0.0 tidyr_0.6.0
[10] tibble_1.2 ggplot2_2.2.1.9000 tidyverse_1.1.1
loaded via a namespace (and not attached):
[1] reshape2_1.4.2 haven_1.0.0 lattice_0.20-34
[4] colorspace_1.3-1 htmltools_0.3.5 stats4_3.3.1
[7] viridisLite_0.1.3 R.oo_1.21.0 foreign_0.8-67
[10] DBI_0.6-1 R.utils_2.5.0 RColorBrewer_1.1-2
[13] modelr_0.1.0 readxl_0.1.1 foreach_1.4.3
[16] plyr_1.8.4 stringr_1.2.0 munsell_0.4.3
[19] gtable_0.2.0 rvest_0.3.2 raster_2.5-8
[22] R.methodsS3_1.7.1 htmlwidgets_0.8 codetools_0.2-15
[25] psych_1.6.12 latticeExtra_0.6-28 forcats_0.2.0
[28] parallel_3.3.1 gdalUtils_2.0.1.7 broom_0.4.1
[31] Rcpp_0.12.10 geosphere_1.5-5 udunits2_0.13
[34] scales_0.4.1 satellite_0.2.0 webshot_0.4.0
[37] jsonlite_1.3 mnormt_1.5-5 hms_0.3
[40] png_0.1-7 digest_0.6.12 stringi_1.1.2
[43] grid_3.3.1 rgdal_1.2-5 tools_3.3.1
[46] magrittr_1.5 lazyeval_0.2.0 xml2_1.1.1
[49] lubridate_1.6.0 assertthat_0.1 httr_1.2.1
[52] iterators_1.0.8 R6_2.2.0 units_0.4-3
[55] nlme_3.1-128
Metadata
Metadata
Assignees
Labels
No labels