Skip to content

Commit

Permalink
SDA_spatialQuery(): only calculate extent polygon for SpatRaster, n…
Browse files Browse the repository at this point in the history
…ot SpatVector
  • Loading branch information
brownag committed Mar 8, 2023
1 parent 0fd9125 commit ec48b0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Bug fixes
- Fix selected set (`SS` argument) for `get_ecosite_history_from_NASIS_db()`

- `get_SDA_pmgroupname`: return `NA` (not "NULL") for empty/missing `pmgroupname` when `simplify=TRUE `

- `SDA_spatialQuery()`:

- `geomIntersection=TRUE` with `db="SAPOLYGON"` now correctly labels the `areasymbol` column (previously was `mukey`) to match `geomIntersection=FALSE` and SDA schema

- Bounding box extent polygons are now only calculated for `SpatRaster` (not `SpatVector`) input

# soilDB 2.7.6 (2022-11-28)

Expand Down
12 changes: 7 additions & 5 deletions R/SDA-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ FROM geom_data;
},
SAPOLYGON = { switch(method,
intersection = "
WITH geom_data (geom, mukey) AS (
WITH geom_data (geom, areasymbol) AS (
SELECT
sapolygongeo.STIntersection( geometry::STGeomFromText('%s', 4326) ) AS geom, areasymbol
FROM sapolygon
WHERE sapolygongeo.STIntersects( geometry::STGeomFromText('%s', 4326) ) = 1
)
SELECT
geom.STAsText() AS geom, mukey,
geom.STAsText() AS geom, areasymbol,
GEOGRAPHY::STGeomFromWKB(geom.STUnion(geom.STStartPoint()).STAsBinary(), 4326).STArea() * 0.000247105 AS area_ac
FROM geom_data;
",
Expand Down Expand Up @@ -357,12 +357,14 @@ SDA_spatialQuery <- function(geom,
geom <- terra::rast(geom)
}

if (inherits(geom, 'SpatRaster') | inherits(geom, 'SpatVector')) {
if (inherits(geom, 'SpatRaster') || inherits(geom, 'SpatVector')) {
# terra support
return_terra <- TRUE
return_sf <- TRUE
geom <- terra::as.polygons(terra::ext(geom),
crs = terra::crs(geom))
# convert raster to extent polygon if needed
if (inherits(geom, 'SpatRaster')) {
geom <- terra::as.polygons(terra::ext(geom), crs = terra::crs(geom))
}
geom <- sf::st_as_sf(geom)
} else if (inherits(geom, 'sf') || inherits(geom, 'sfc')) {
return_sf <- TRUE
Expand Down

0 comments on commit ec48b0f

Please sign in to comment.