Skip to content

Commit

Permalink
always fill wkt2 field if GDAL >= 3; #1146
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Nov 29, 2019
1 parent 4f961ed commit a74ffe4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/gdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,8 @@ Rcpp::List CPL_crs_parameters(Rcpp::List crs) {
return out;
}

// [[Rcpp::export]]
Rcpp::CharacterVector CPL_wkt2_from_epsg(Rcpp::IntegerVector epsg) {
Rcpp::CharacterVector wkt2_from_spatial_reference(OGRSpatialReference *srs) { // FIXME: add options?
#if GDAL_VERSION_MAJOR >= 3
OGRSpatialReference *srs = new OGRSpatialReference;
srs = handle_axis_order(srs);
handle_error(srs->importFromEPSG(epsg[0]));
// const char **options = { "MULTILINE=YES", "FORMAT=WKT2", NULL };
char *cp;
const char *options[3];
options[0] = "MULTILINE=YES";
Expand All @@ -187,6 +182,20 @@ Rcpp::CharacterVector CPL_wkt2_from_epsg(Rcpp::IntegerVector epsg) {
Rcpp::stop("OGR error: cannot export to WKT2");
Rcpp::CharacterVector out(cp);
CPLFree(cp);
return out;
#else
return Rcpp::CharacterVector::create(NA_STRING);
#endif
}

// [[Rcpp::export]]
Rcpp::CharacterVector CPL_wkt2_from_epsg(Rcpp::IntegerVector epsg) {
#if GDAL_VERSION_MAJOR >= 3
OGRSpatialReference *srs = new OGRSpatialReference;
srs = handle_axis_order(srs);
handle_error(srs->importFromEPSG(epsg[0]));
// const char **options = { "MULTILINE=YES", "FORMAT=WKT2", NULL };
Rcpp::CharacterVector out = wkt2_from_spatial_reference(srs);
delete srs;
return(out);
#else
Expand Down Expand Up @@ -293,10 +302,13 @@ Rcpp::List create_crs(OGRSpatialReference *ref) {
} else
crs(0) = NA_INTEGER;
crs(1) = p4s_from_spatial_reference(ref);
/*
if (epsg_is_na)
crs(2) = Rcpp::CharacterVector::create(NA_STRING);
else
crs(2) = CPL_wkt2_from_epsg(crs(0));
*/
crs(2) = wkt2_from_spatial_reference(ref);
}
Rcpp::CharacterVector nms(3);
nms(0) = "epsg";
Expand Down

0 comments on commit a74ffe4

Please sign in to comment.