Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/spatial #20

Merged
merged 57 commits into from Aug 19, 2021
Merged

Feature/spatial #20

merged 57 commits into from Aug 19, 2021

Conversation

cneyens
Copy link
Collaborator

@cneyens cneyens commented Sep 16, 2020

Introducing S3 conversions from spatial objects to RMODFLOW objects (rmf_list and rmf_2d/3d/4d_arrays) and vice versa. Supported spatial classes are sf, stars and raster objects. stars is the main driver because it can handle rotated grids or rectilinear grids. Vector/raster I/O is not handled by RMODFLOW; only conversions. Most functionality is explained in the vignette 'spatial.Rmd'.

A brief summary:

  • Projection information is handled through the prj object. It consists of an origin vector (bottomleft model corner coordinates), a rotation angle and a sf crs element. The prj object can be part of the dis object. Upon writing a DIS file to disk, RMODFLOW projection information is written to the header comments. When reading in a DIS file, RMODFLOW projection information is obtained from either RMODFLOW style projection information in the DIS headers, ModelMuse style projection information or OWHM style. It can also be read from a usgs.model.reference file
  • By default, all functions that have a prj argument obtain this from the supplied dis argument using rmf_get_prj() which returns NULL for dis objects without a prj. prj arguments can still be supplied explicitely to function calls.
  • Length units are converted on the fly between RMODFLOW (dis$lenuni) and the crs in the prj object using rmfi_prj_length_multiplier (e.g. in rmf_convert_grid_to_xyz).
  • Conversion from rmf_list and rmf_2d/3d/4d_arrays to sf, stars and raster (the latter only for non-rotated regular grids).
  • Conversion from sf, stars and raster to rmf_list and rmf_2d/3d/4d_arrays.
  • rmf_as_tibble and other functions using coordinates have been updated
  • rmf_export_* functions have been removed as RMODFLOW doesn't provide I/O for spatial objects.

Notes:

  • Functions have been tested for rotated regular grids, not yet for rectilinear grids with varying cell size.
  • In the current implementation, rmf_as_list.sf returns multiple cells for POINT geometries located on cell boundaries using op = sf::st_intersects (default). While this is correct behaviour from a spatial point of view, typically in the MODFLOW world, point values should be connected to a single cell. E.g. a well location should not belong the multiple cells, just one. See also the vignette.

Breaking changes:

  • prj$projection is replaced by prj$crs (in line with sf).
  • rmf_write_prj and rmf_read_prj are replaced by internal functions since prj is read/written from the dis file (or read from usgs.model.reference) instead of individual files.
  • RMODFLOW.Rmd: Test sf chunk failed in build since rmf_as_sf has changed. Current fix: chunk not evaluated.
  • rmf_install: had to skip the examples for this function in the build since they returned permission-based errors on my machine.

@cneyens cneyens marked this pull request as ready for review November 5, 2020 20:05
@rogiersbart
Copy link
Owner

Looks very complete Cas. This should also provide the required functionality for making the rmf_create_* function implementations much more straightforward I think. Will not go through lengthy testing right now, and just merge.

@rogiersbart rogiersbart merged commit c85cf04 into rogiersbart:develop Aug 19, 2021
@cneyens cneyens deleted the feature/spatial branch August 21, 2021 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants