Skip to content

Commit

Permalink
z_range and m_range only added if exists - close #86
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Nov 15, 2020
1 parent 183f07e commit 6462efa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: sfheaders
Type: Package
Title: Converts Between R Objects and Simple Feature Objects
Date: 2020-10-31
Version: 0.3.0
Version: 0.3.0001
Authors@R: c(
person("David", "Cooley", ,"[email protected]", role = c("aut", "cre")),
person(given = "Michael", family = "Sumner", role = "ctb")
Expand All @@ -15,7 +15,7 @@ URL: https://dcooley.github.io/sfheaders/
BugReports: https://github.com/dcooley/sfheaders/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
SystemRequirements: C++11
LinkingTo:
geometries,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# v0.3.1

* `z_range` and `m_range` only created if those dimensions exist

# v0.3.0

* changed licence to MIT
Expand Down
9 changes: 7 additions & 2 deletions inst/include/sfheaders/sfc/sfc_attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ namespace sfc {
sfc.attr("bbox") = bbox;

sfheaders::zm::attach_z_range_attributes( z_range );
sfc.attr("z_range") = z_range;

if( !Rcpp::NumericVector::is_na( z_range[0] ) && !Rcpp::NumericVector::is_na( z_range[1] ) ) {
sfc.attr("z_range") = z_range;
}

sfheaders::zm::attach_m_range_attributes( m_range );
sfc.attr("m_range") = m_range;
if( !Rcpp::NumericVector::is_na( m_range[0] ) && !Rcpp::NumericVector::is_na( m_range[1] ) ) {
sfc.attr("m_range") = m_range;
}
}

inline void attach_sfc_attributes(
Expand Down
39 changes: 12 additions & 27 deletions tests/testthat/test-bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ test_that("z and m range correctly reported",{
, m = 20:9
)




pt <- sf_point(obj = df, x = "x", y = "y", z = "z")
mpt <- sf_multipoint(obj = df, x = "x", y = "y", z = "z", multipoint_id = "id1")
ls <- sf_linestring(obj = df, x = "x", y = "y", z = "z", linestring_id = "id1")
Expand Down Expand Up @@ -303,18 +300,12 @@ test_that("z and m range correctly reported",{
expect_true( all( attr( p$geometry, "z_range" ) == c(1,12) ) )
expect_true( all( attr( mp$geometry, "z_range" ) == c(1,12) ) )

expect_true( is.na( attr( pt$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( pt$geometry, "m_range" )[2] ) )
expect_true( is.na( attr( mp$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( mp$geometry, "m_range" )[2] ) )
expect_true( is.na( attr( ls$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( ls$geometry, "m_range" )[2] ) )
expect_true( is.na( attr( mls$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( mls$geometry, "m_range" )[2] ) )
expect_true( is.na( attr( p$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( p$geometry, "m_range" )[2] ) )
expect_true( is.na( attr( mp$geometry, "m_range" )[1] ) )
expect_true( is.na( attr( mp$geometry, "m_range" )[2] ) )
expect_true( is.null( attr( pt$geometry, "m_range" ) ) )
expect_true( is.null( attr( mp$geometry, "m_range" ) ) )
expect_true( is.null( attr( ls$geometry, "m_range" ) ) )
expect_true( is.null( attr( mls$geometry, "m_range" ) ) )
expect_true( is.null( attr( p$geometry, "m_range" ) ) )
expect_true( is.null( attr( mp$geometry, "m_range" ) ) )


pt <- sf_point(obj = df, x = "x", y = "y", m = "m")
Expand Down Expand Up @@ -347,18 +338,12 @@ test_that("z and m range correctly reported",{
expect_true( all( attr( p$geometry, "m_range" ) == c(9,20) ) )
expect_true( all( attr( mp$geometry, "m_range" ) == c(9,20) ) )

expect_true( is.na( attr( pt$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( pt$geometry, "z_range" )[2] ) )
expect_true( is.na( attr( mp$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( mp$geometry, "z_range" )[2] ) )
expect_true( is.na( attr( ls$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( ls$geometry, "z_range" )[2] ) )
expect_true( is.na( attr( mls$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( mls$geometry, "z_range" )[2] ) )
expect_true( is.na( attr( p$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( p$geometry, "z_range" )[2] ) )
expect_true( is.na( attr( mp$geometry, "z_range" )[1] ) )
expect_true( is.na( attr( mp$geometry, "z_range" )[2] ) )
expect_true( is.null( attr( pt$geometry, "z_range" ) ) )
expect_true( is.null( attr( mp$geometry, "z_range" ) ) )
expect_true( is.null( attr( ls$geometry, "z_range" ) ) )
expect_true( is.null( attr( mls$geometry, "z_range" ) ) )
expect_true( is.null( attr( p$geometry, "z_range" ) ) )
expect_true( is.null( attr( mp$geometry, "z_range" ) ) )


pt <- sf_point(obj = df, x = "x", y = "y", z = "z", m = "m")
Expand Down

0 comments on commit 6462efa

Please sign in to comment.