Hi,
 
My library  mylib  uses  OGRSpatialReference  as setting for a project. Thus 
the variable  OGRSpatialReference SpatialReference  is defined outside the 
scope. Then one can set spatial reference, set length units and this is going 
to be a project setting (this is done via setters/getters API defined in  mylib 
). Then all data that will be loaded to the RAM will be transformed to this 
spatial reference. My library is built as a shared library.
 
The application which uses my library is built on Qt and it is modular 
application. Briefly I can describe it as:
*  app  executable that links to the applib
*  applib is the main library that links to mylib  and  gdal
*  appmodule  is loadable module that links to   mylib  and  gdal
*  mylib links to the gdal
If I set  SpatialReference  setting from  applib then there is no any problem, 
I can set spatial reference from user input and set length units and then get 
them them back (print it).
 
But if I try to do the same then  SpatialReference is able to store only length 
units while the authority name/code can’t be retrieved (it gives me empty). 
Retrieving  SpatialReference also doesn’t return spatial reference that were 
previously set.
 
The  PROJ_LIB  variable is set when app is launching and it should be ok.
 
I really have no idea why this is happening and have to ask for help…
 
Ubuntu 20.04, prebuilt GDAL 3.1.4 with PROJ 7.0.1 (i don’t remember exactly the 
version of PROJ). The link where I  download GDAL is here
 
Here is the code that I use for settings in  mylib_settings.cpp :
 
/*------------- START OF  mylib_settings.cpp  -------------*/
#include "mylib_settings.h"
#include <units/units.hpp>
#include <gdal/gdal.h>
#include <gdal/gdal_priv.h>
 
namespace {
 
static OGRSpatialReference SpatialReference  {};
 
}  // namespace
 
// Only these setters/getters are exported
void  setSpatialReference ( OGRSpatialReference  sr){
   SpatialReference  = sr;
}
 
void  setSpatialReferenceFromUserInput (
     const  std::string & name){
   SpatialReference .SetFromUserInput(name.c_str());
}
 
void setSpatialReferenceFromUserInput (
     const  std::string & authName,  const std::string & code){
   SpatialReference .SetFromUserInput((authName + ":" + code).c_str());
}
 
OGRSpatialReference  getSpatialReference (){
   return  SpatialReference ;
}
 
void  setLengthUnits ( const  std::string & units){
   double  coef = units::convert(
      units::unit_from_string(units),
      units::unit_from_string("meter"));
   SpatialReference .SetLinearUnitsAndUpdateParameters(units.c_str(), coef);
}
 
std::string getLengthUnits (){
   const char  *units =  nullptr ;
   SpatialReference .GetLinearUnits(&units);
   return std::string (units);
}
 
std::string getAuthorityName (){
  if ( auto * p =  SpatialReference .GetAuthorityName({}))
     return  p;
   return  {};
}
 
std::string getAuthorityCode (){
  if ( auto * p =  SpatialReference .GetAuthorityCode({}))
     return  p;
   return  {};
}
/*------------- END OF  mylib_settings.cpp  -------------*/
 
 
Regards,
Kerim Khemraev
 
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to