diff --git a/R/vapour-gdal-library.R b/R/vapour-gdal-library.R index a52b481..dd8a924 100644 --- a/R/vapour-gdal-library.R +++ b/R/vapour-gdal-library.R @@ -85,7 +85,7 @@ vapour_srs_wkt <- function(crs) { #' @export #' #' @examples -#' #vapour_srs_wkt("+proj=longlat") +#' vapour_srs_wkt("+proj=longlat") #' vapour_crs_is_lonlat("+proj=laea +type=crs") #' vapour_crs_is_lonlat("+proj=longlat +type=crs") #' vapour_crs_is_lonlat("+init=EPSG:4326") diff --git a/inst/include/gdallibrary/gdallibrary.h b/inst/include/gdallibrary/gdallibrary.h index 993ffa4..cd202ce 100644 --- a/inst/include/gdallibrary/gdallibrary.h +++ b/inst/include/gdallibrary/gdallibrary.h @@ -6,6 +6,9 @@ #include "CollectorList.h" #include "gdalraster/gdalraster.h" +#include +#include + namespace gdallibrary { using namespace Rcpp; @@ -657,10 +660,12 @@ inline List gdal_read_geometry(CharacterVector dsn, -inline CharacterVector gdal_proj_to_wkt(CharacterVector proj_str) { +inline CharacterVector gdal_proj_to_wkt(SEXP proj_str) { OGRSpatialReference oSRS; char *pszWKT = nullptr; - oSRS.SetFromUserInput(proj_str[0]); + const char* crs_in[] = {CHAR(STRING_ELT(proj_str, 0))}; + + oSRS.SetFromUserInput(*crs_in); #if GDAL_VERSION_MAJOR >= 3 const char *options[3] = { "MULTILINE=YES", "FORMAT=WKT2", NULL }; OGRErr err = oSRS.exportToWkt(&pszWKT, options); @@ -668,14 +673,15 @@ inline CharacterVector gdal_proj_to_wkt(CharacterVector proj_str) { OGRErr err = oSRS.exportToWkt(&pszWKT); #endif - CharacterVector out; + //CharacterVector out; + SEXP out = PROTECT(Rf_allocVector(STRSXP, 1)); + if (err) { - out = Rcpp::CharacterVector::create(NA_STRING); - CPLFree(pszWKT); + SET_STRING_ELT(out, 0, NA_STRING); } else { - out = Rcpp::CharacterVector::create(pszWKT); + SET_STRING_ELT(out, 0, Rf_mkChar(pszWKT)); } - + UNPROTECT(1); return out; } diff --git a/man/vapour_crs_is_lonlat.Rd b/man/vapour_crs_is_lonlat.Rd index 455ffe5..12564b4 100644 --- a/man/vapour_crs_is_lonlat.Rd +++ b/man/vapour_crs_is_lonlat.Rd @@ -16,7 +16,7 @@ logical value \code{TRUE} for lonlat, \code{FALSE} otherwise Returns \code{TRUE} if this is longitude latitude data. Missing, malformed, zero-length values are disallowed. } \examples{ -#vapour_srs_wkt("+proj=longlat") +vapour_srs_wkt("+proj=longlat") vapour_crs_is_lonlat("+proj=laea +type=crs") vapour_crs_is_lonlat("+proj=longlat +type=crs") vapour_crs_is_lonlat("+init=EPSG:4326")