@@ -434,14 +434,14 @@ void gdal_init(std::string projpath, std::string datapath) {
434434 // GDAL_NETCDF_IGNORE_XY_AXIS_NAME_CHECKS
435435
436436 // GDALregistred = true;
437- #if GDAL_VERSION_MAJOR >= 3
438- #ifdef PROJ_6
439437 if (!projpath.empty ()) {
440- const char *cp = projpath.c_str ();
441- proj_context_set_search_paths (PJ_DEFAULT_CTX, 1 , &cp);
442- }
443- #endif
438+ #if GDAL_VERSION_NUM >= 3000000
439+ std::vector<char *> cpaths (2 );
440+ cpaths[0 ] = (char *)projpath.c_str ();
441+ cpaths[1 ] = NULL ;
442+ OSRSetPROJSearchPaths (cpaths.data ());
444443#endif
444+ }
445445#ifdef PROJ_71
446446 #ifndef __EMSCRIPTEN__
447447 proj_context_set_enable_network (PJ_DEFAULT_CTX, 1 );
@@ -567,36 +567,54 @@ std::vector<std::string> get_proj_search_paths() {
567567
568568
569569// [[Rcpp::export(name = ".set_proj_search_paths")]]
570- bool set_proj_search_paths (std::vector<std::string> paths) {
570+ bool set_proj_search_paths (std::vector<std::string> paths, bool with_proj = false ) {
571571 if (paths.empty ()) {
572572 return false ;
573573 }
574+ if (with_proj) {
575+ // Set for PROJ library
576+ if (paths.size () == 1 ) {
577+ const char *cp = paths[0 ].c_str ();
578+ proj_context_set_search_paths (PJ_DEFAULT_CTX, 1 , &cp);
579+ }
580+ return true ;
581+ } else {
582+ // Set for GDAL
574583#if GDAL_VERSION_NUM >= 3000000
575- std::vector <char *> cpaths (paths.size ()+1 );
576- for (size_t i = 0 ; i < paths.size (); i++) {
577- cpaths[i] = (char *) (paths[i].c_str ());
578- }
579- cpaths[cpaths.size ()-1 ] = NULL ;
580- OSRSetPROJSearchPaths (cpaths.data ());
581- return true ;
584+ std::vector <char *> cpaths (paths.size ()+1 );
585+ for (size_t i = 0 ; i < paths.size (); i++) {
586+ cpaths[i] = (char *) (paths[i].c_str ());
587+ }
588+ cpaths[cpaths.size ()-1 ] = NULL ;
589+ OSRSetPROJSearchPaths (cpaths.data ());
590+ return true ;
582591#else
583- return false ;
592+ return false ;
584593#endif
594+ }
585595}
586596
587597
588598// [[Rcpp::export(name = ".PROJ_network")]]
589- std::string PROJ_network (bool enable, std::string url) {
599+ std::string PROJ_network (int enable, std::string url) {
590600 std::string s = " " ;
591601#ifdef PROJ_71
592- if (enable) {
602+ if (enable == -1 ) { // get current status
603+ return std::to_string (proj_context_is_network_enabled (PJ_DEFAULT_CTX));
604+ } else if (enable == 1 ) {
593605 proj_context_set_enable_network (PJ_DEFAULT_CTX, 1 );
606+ #if GDAL_VERSION_NUM >= 3040000
607+ OSRSetPROJEnableNetwork (1 );
608+ #endif
594609 if (url.size () > 5 ) {
595610 proj_context_set_url_endpoint (PJ_DEFAULT_CTX, url.c_str ());
596611 }
597612 s = proj_context_get_url_endpoint (PJ_DEFAULT_CTX);
598- } else { // disable:
613+ } else if (enable == 0 ) { // disable:
599614 proj_context_set_enable_network (PJ_DEFAULT_CTX, 0 );
615+ #if GDAL_VERSION_NUM >= 3040000
616+ OSRSetPROJEnableNetwork (0 );
617+ #endif
600618 }
601619#endif
602620 return s;
0 commit comments