Polygon Support
munterfi opened this issue · 1 comments
munterfi commented
Add support for geometry type "POLYGON"
in encode_sf()
and decode_sf()
.
In the coordinates matrix of polygons the last row is idental with the first row. This property will be used to check for polygons.
munterfi commented
The package now supports the geometry types "POINT"
and "POLYGON"
, which can be encoded and decoded using encode_sf()
and decode_sf()
.
- Create example geometries:
library(flexpolyline)
(point3d <- sf::st_point(
matrix(c(8.69821, 50.10221, 10), ncol = 3, byrow = TRUE), dim = "XYZ"))
#> POINT Z (8.69821 50.10221 10)
(line3d <- sf::st_linestring(
matrix(c(8.69821, 50.10222, 10,
8.69567, 50.10203, 20,
8.68752, 50.09874, 30), ncol = 3, byrow = TRUE), dim = "XYZ"))
#> LINESTRING Z (8.69821 50.10222 10, 8.69567 50.10203 20, 8.68752 50.09874 30)
(poly3d <- sf::st_polygon(list(
matrix(c(8.69821, 50.10221, 10,
8.69567, 50.10204, 20,
8.69150, 50.10065, 30,
8.69821, 50.10221, 10), ncol = 3, byrow = TRUE)), dim = "XYZ"))
#> POLYGON Z ((8.69821 50.10221 10, 8.69567 50.10204 20, 8.6915 50.10065 30, 8.69821 50.10221 10))
- Encoding simple feature geometries of type
"POINT"
,"LINESTRING"
and"POLYGON"
:
encode_sf(point3d)
#> [1] "B1V6y5xJ67i1Bgkh9B"
encode_sf(line3d)
#> [1] "B1V8y5xJ67i1Bgkh9BlB7Pgkh9BxU9yBgkh9B"
encode_sf(poly3d)
#> [1] "B1V6y5xJ67i1Bgkh9BhB7Pgkh9B1Ihagkh9B4J-pB_ni6D"
- Decoding flexible polyline encoded strings to simple feature geometries of type
"POINT"
,"LINESTRING"
and"POLYGON"
:
decode_sf("B1Voz5xJ67i1Bgkh9B")
#> Simple feature collection with 1 feature and 2 fields
#> geometry type: POINT
#> dimension: XYZ
#> bbox: xmin: 8.69821 ymin: 50.10228 xmax: 8.69821 ymax: 50.10228
#> z_range: zmin: 10 zmax: 10
#> CRS: NA
#> id dim3 geometry
#> 1 1 ELEVATION POINT Z (8.69821 50.10228 10)
decode_sf("B1Voz5xJ67i1Bgkh9B1B7Pgkh9BlU9yBgkh9B")
#> Simple feature collection with 1 feature and 2 fields
#> geometry type: LINESTRING
#> dimension: XYZ
#> bbox: xmin: 8.68752 ymin: 50.09878 xmax: 8.69821 ymax: 50.10228
#> z_range: zmin: 10 zmax: 30
#> CRS: NA
#> id dim3 geometry
#> 1 1 ELEVATION LINESTRING Z (8.69821 50.10...
decode_sf("B1V6y5xJ67i1Bgkh9BhB7Pgkh9B1Ihagkh9B4J-pB_ni6D")
#> Simple feature collection with 1 feature and 2 fields
#> geometry type: POLYGON
#> dimension: XYZ
#> bbox: xmin: 8.6915 ymin: 50.10065 xmax: 8.69821 ymax: 50.10221
#> z_range: zmin: 10 zmax: 30
#> CRS: NA
#> id dim3 geometry
#> 1 1 ELEVATION POLYGON Z ((8.69821 50.1022...
- Mixed geometries:
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
(mixed <- st_sfc(list(point3d, line3d, poly3d)))
#> Geometry set for 3 features
#> geometry type: GEOMETRY
#> dimension: XYZ
#> bbox: xmin: 8.68752 ymin: 50.09874 xmax: 8.69821 ymax: 50.10222
#> z_range: zmin: 10 zmax: 30
#> CRS: NA
#> POINT Z (8.69821 50.10221 10)
#> LINESTRING Z (8.69821 50.10222 10, 8.69567 50.1...
#> POLYGON Z ((8.69821 50.10221 10, 8.69567 50.102...
(encoded <- encode_sf(mixed))
#> [1] "B1V6y5xJ67i1Bgkh9B"
#> [2] "B1V8y5xJ67i1Bgkh9BlB7Pgkh9BxU9yBgkh9B"
#> [3] "B1V6y5xJ67i1Bgkh9BhB7Pgkh9B1Ihagkh9B4J-pB_ni6D"
decode_sf(encoded)
#> Simple feature collection with 3 features and 2 fields
#> geometry type: GEOMETRY
#> dimension: XYZ
#> bbox: xmin: 8.68752 ymin: 50.09874 xmax: 8.69821 ymax: 50.10222
#> z_range: zmin: 10 zmax: 30
#> CRS: NA
#> id dim3 geometry
#> 1 1 ELEVATION POINT Z (8.69821 50.10221 10)
#> 2 2 ELEVATION LINESTRING Z (8.69821 50.10...
#> 3 3 ELEVATION POLYGON Z ((8.69821 50.1022...
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os macOS Catalina 10.15.7
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Zurich
#> date 2020-11-25
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
#> backports 1.2.0 2020-11-02 [1] CRAN (R 4.0.2)
#> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.2)
#> class 7.3-17 2020-04-26 [1] CRAN (R 4.0.2)
#> classInt 0.4-3 2020-04-07 [1] CRAN (R 4.0.0)
#> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
#> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
#> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> dplyr 1.0.2 2020-08-18 [1] CRAN (R 4.0.2)
#> e1071 1.7-4 2020-10-14 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
#> flexpolyline * 0.1.1.9000 2020-11-25 [1] local
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> KernSmooth 2.23-18 2020-10-29 [1] CRAN (R 4.0.2)
#> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
#> processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
#> ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> rlang 0.4.8 2020-10-08 [1] CRAN (R 4.0.2)
#> rmarkdown 2.5 2020-10-21 [1] CRAN (R 4.0.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0)
#> sf * 0.9-6 2020-09-13 [1] CRAN (R 4.0.2)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> testthat 3.0.0 2020-10-31 [1] CRAN (R 4.0.2)
#> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0)
#> units 0.6-7 2020-06-13 [1] CRAN (R 4.0.2)
#> usethis 1.6.3 2020-09-17 [1] CRAN (R 4.0.2)
#> vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2)
#> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)
#> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library