Skip to content

Commit

Permalink
Remove dependence on rgdal
Browse files Browse the repository at this point in the history
  • Loading branch information
LHMarshall committed Oct 18, 2023
1 parent 239d460 commit 8a4b590
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Package: dssd
Imports:
sf,
rgdal,
ggplot2,
methods
Suggests: knitr,
Expand All @@ -12,7 +11,7 @@ Suggests: knitr,
VignetteBuilder: knitr
Type: Package
Title: Distance Sampling Survey Design
Version: 1.0.0
Version: 1.0.1
Authors@R: c(
person("Laura", "Marshall", email = "[email protected]", role = c("aut", "cre")),
person("Rexstad", "Eric", email = "[email protected]", role = "ctb"))
Expand All @@ -28,7 +27,7 @@ Description: Creates survey designs for distance sampling surveys. These
BugReports: https://github.com/DistanceDevelopment/dssd/issues
License: GPL (>=2)
Encoding: UTF-8
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Collate:
'Class.Constructors.R'
'Coverage.Grid.R'
Expand Down
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
dssd 1.0.1
----------

Bug Fixes

* Removed dependence on rgdal

dssd 1.0.0
----------

Expand Down
41 changes: 21 additions & 20 deletions R/write.transects.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' between columns. For line transects which have been split across geographical
#' features (such as islands or lakes) there will be two or more rows in the
#' csv / txt file with all rows having the same transect ID.
#' @param object an object inheriting from class Transect or an sf spatial
#' object extracted from a Transect object.
#' @param object an object inheriting from class Transect. Alternatively, for
#' all file types except gpx an sf spatial object can be supplied.
#' @param dsn the data source name, currently a filename with a 'shp'
#' 'csv', 'txt' or 'gpx' extension.
#' @param layer a character vector specifying the layer name, only
Expand All @@ -26,10 +26,10 @@
#' @importFrom sf as_Spatial
#' @importFrom methods as
#' @author Laura Marshall
#' @details To write the transects to shapefile only the dsn is needed with
#' @details To write the transects to file usually only the dsn is needed with
#' a 'shp', 'csv' or 'txt' file extension. To write a gpx file you need to
#' specify the dsn, layer, dataset.options and usually a projection to
#' project the coordinates back into latitude and longitude.
#' specify the dsn and a projection so allow the coordinates to be transformed.
#' back into latitude and longitude.
#'
#' @examples
#' # Note that for CRAN testing purposes all files written in example code must
Expand Down Expand Up @@ -76,10 +76,9 @@
#' write.transects(survey,
#' dsn = paste0(tempdir(), "/", "transects.gpx"),
#' layer = "lines",
#' dataset.options = "GPX_USE_EXTENSIONS=yes",
#' proj4string = orig.crs)
#'
write.transects <- function(object, dsn, layer = character(0), dataset.options = character(0), overwrite = FALSE, proj4string = character(0)){
write.transects <- function(object, dsn, layer = NULL, dataset.options = character(0), overwrite = FALSE, proj4string = character(0)){
if(length(proj4string) > 0){
if(is.na(sf::st_crs(object@samplers))){
warning("No coordinate system found for survey transects. A coordinate system is only specified for transects if one was specified for the survey region. Cannot project survey transects.", immediate. = TRUE, call. = FALSE)
Expand All @@ -102,21 +101,23 @@ write.transects <- function(object, dsn, layer = character(0), dataset.options =
stop("Object of wrong class to write to shapefile.", call. = FALSE)
}
}else if(dsn.ext == "gpx"){
if(length(layer) == 0 || length(dataset.options) == 0){
stop("You must supply a layer and dataset options to write a gpx file. See documentation ", call. = FALSE)
}else if(inherits(object, "Transect")){
rgdal::writeOGR(as(object@samplers, "Spatial"),
dsn=dsn, layer=layer, driver="GPX",
dataset_options=dataset.options,
overwrite_layer = overwrite)
}else if(inherits(object,"sf") || inherits(object,"sfc")){
rgdal::writeOGR(as(object, "Spatial"),
dsn=dsn, layer=layer, driver="GPX",
dataset_options=dataset.options,
overwrite_layer = overwrite)
if(inherits(object, "Transect")){
sf.column <- attr(object@samplers, "sf_column")
#Check that there is a specific geometry defined
if(is(object@samplers[[sf.column]], "sfc_GEOMETRY")){
if(inherits(object, "Point.Transect")){
object@samplers <- sf::st_cast(object@samplers, "POINT")
}else if(inherits(object, "Line.Transect")){
object@samplers <- sf::st_cast(object@samplers, "MULTILINESTRING")
}
}
}else{
stop("Object of wrong class to write to gpx file.", call. = FALSE)
stop("Please supply an object of either class Point.Transect or Line.Transect to write to gpx file.", call. = FALSE)
}
# Write to gpx file
sf::st_write(object@samplers[[sf.column]],
dsn=dsn,
layer=layer)
}else if(dsn.ext == "csv"){
if(inherits(object, "Point.Transect")){
samplers <- point.coords.as.dataframe(object@samplers)
Expand Down
13 changes: 6 additions & 7 deletions man/write.transects.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a4b590

Please sign in to comment.