Skip to content

Commit

Permalink
try R internals
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Jun 6, 2024
1 parent 83aa1de commit ea50e5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/vapour-gdal-library.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 13 additions & 7 deletions inst/include/gdallibrary/gdallibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "CollectorList.h"
#include "gdalraster/gdalraster.h"

#include <Rinternals.h>
#include <R.h>

namespace gdallibrary {
using namespace Rcpp;

Expand Down Expand Up @@ -657,25 +660,28 @@ 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);
#else
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;
}

Expand Down
2 changes: 1 addition & 1 deletion man/vapour_crs_is_lonlat.Rd

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

0 comments on commit ea50e5f

Please sign in to comment.