I think it would be useful to have an st_perimeter. Is it equivalent to have st_cast("MULTILINESTRING") %>% st_length?
(how) does it deal with holes in polygons?
library(sf)
#> Linking to GEOS 3.5.0, GDAL 2.1.1, proj.4 4.9.3
m <- rbind(c(0,0), c(1,0), c(1, 1), c(0,1), c(0,0))
n <- (m - 0.5) / 2 + 0.5
s <- matrix(c(2, 0), 5, 2, byrow = TRUE)
single <- list(m) %>% st_polygon()
multi <- list(list(m), list(m + s)) %>% st_multipolygon()
half <- list(n) %>% st_polygon()
hole <- st_difference(single, half)
single %>% st_cast("MULTILINESTRING") %>% st_length()
#> [1] 4
half %>% st_cast("MULTILINESTRING") %>% st_length()
#> [1] 2
hole %>% st_cast("MULTILINESTRING") %>% st_length()
#> [1] 6
multi %>% st_cast("MULTILINESTRING") %>% st_length()
#> [1] 8
seems like its the sum of all lengths - I don't think that justifies a separate function.
Ok, then I don't want to insist too much, but what about enabling st_length for polygons?, so it can be applied to all geometries (points are 0).
I believe this is a good solution.
This has been revisited; anything not a LINE (not having dimension 1) returns length 0.
This would indeed be conform to OGC specifications (and postgis). So you'd add a st_perimeter() ?
I don't see st_perimeter anywhere in the SFA standard doc. Is it part of PostGIS, and if yes, is it in liblwgeom?
You're right, I couldn't find it in the specification either. I took it from postgis st_length
- This method implements the OpenGIS Simple Features Implementation Specification for SQL 1.1. s2.1.5.1
- This method implements the SQL/MM specification. SQL-MM 3: 7.1.2, 9.3.4
It's available from lwgeom_length()
SQL MM (ISO/IEC 13249-3) defines st_perimeter, and postGIS has st_perimeter, and liblwgeom has it implemented. So, this can be added to lwgeom.
Most helpful comment
SQL MM (ISO/IEC 13249-3) defines st_perimeter, and postGIS has st_perimeter, and liblwgeom has it implemented. So, this can be added to lwgeom.