<HTML><BODY><div>Hi,</div><div> </div><div>My library <strong>mylib </strong>uses <strong>OGRSpatialReference </strong>as setting for a project. Thus the variable <strong>OGRSpatialReference SpatialReference </strong>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 <strong>mylib</strong>). 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.</div><div> </div><div>The application which uses my library is built on Qt and it is modular application. Briefly I can describe it as:</div><ul><li><strong>app </strong>executable that links to the<strong> applib</strong></li><li><strong>applib</strong> is the main library that links to<strong> mylib </strong>and <strong>gdal</strong></li><li><b>appmodule </b>is loadable module that links to<b> </b><strong>mylib </strong>and <strong>gdal</strong></li><li><strong>mylib</strong> links to the gdal</li></ul><div>If I set <strong>SpatialReference </strong>setting from <strong>applib</strong> 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).</div><div> </div><div>But if I try to do the same then <strong>SpatialReference</strong> is able to store only length units while the authority name/code can’t be retrieved (it gives me empty). Retrieving <strong>SpatialReference</strong> also doesn’t return spatial reference that were previously set.</div><div> </div><div>The <strong>PROJ_LIB</strong> variable is set when app is launching and it should be ok.</div><div> </div><div>I really have no idea why this is happening and have to ask for help…</div><div> </div><div>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 <a href="https://sourceforge.net/projects/gdal-wheels-for-linux/">download GDAL is here</a></div><div> </div><div>Here is the code that I use for settings in <strong>mylib_settings.cpp</strong>:</div><div> </div><div><span style="font-size:14px;line-height:20px;"><span style="color:#00b050;">/*------------- START OF <strong>mylib_settings.cpp </strong></span></span><span style="font-size:12px;line-height:20px;"><span style="font-size: 14px;"><span style="color:#00b050;">-------------*/</span></span></span></div><div><span style="font-size:12px;line-height:20px;"><span style="color:#005ff9;">#include "mylib_settings.h"<br>#include <units/units.hpp></span></span></div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#005ff9;">#include <gdal/gdal.h></span></span></div><div><span style="font-size:12px;line-height:20px;"><span style="color:#005ff9;">#include <gdal/gdal_priv.h></span></span></div><div> </div><div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">namespace {</span></span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">static</span><span style="color:#b36ae2;"> OGRSpatialReference</span> <span style="color:#c82613;">SpatialReference </span>{};</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">} </span><span style="color:#00b050;">// namespace</span></span></div></div><div> </div><div><span style="font-size:12px;line-height:20px;"><span style="color:#00b050;">// Only these setters/getters are exported</span></span></div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">void </span><strong>setSpatialReference</strong>(<span style="color:#b36ae2;">OGRSpatialReference </span>sr){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#c82613;">SpatialReference </span>= sr;</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">void </span><strong>setSpatialReferenceFromUserInput</strong>(</span></div><div><span style="font-size:12px;line-height:20px;">    <span style="color:#f1c232;">const </span><span style="color:#b36ae2;">std::string</span>& name){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#c82613;">SpatialReference</span>.SetFromUserInput(name.c_str());</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">void</span> <strong>setSpatialReferenceFromUserInput</strong>(</span></div><div><span style="font-size:12px;line-height:20px;">    <span style="color:#f1c232;">const </span><span style="color:#b36ae2;">std::string</span>& authName, <span style="color:#f1c232;">const</span><span style="color:#b36ae2;"> std::string</span>& code){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#c82613;">SpatialReference</span>.SetFromUserInput((authName + ":" + code).c_str());</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#b36ae2;">OGRSpatialReference </span><strong>getSpatialReference</strong>(){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">return </span><span style="color:#c82613;">SpatialReference</span>;</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#f1c232;">void </span><strong>setLengthUnits</strong>(<span style="color:#f1c232;">const </span><span style="color:#b36ae2;">std::string</span>& units){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">double </span>coef = units::convert(</span></div><div><span style="font-size:12px;line-height:20px;">      units::unit_from_string(units),</span></div><div><span style="font-size:12px;line-height:20px;">      units::unit_from_string("meter"));</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#c82613;">SpatialReference</span>.SetLinearUnitsAndUpdateParameters(units.c_str(), coef);</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#b36ae2;">std::string</span> <strong>getLengthUnits</strong>(){</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">const char </span>*units = <span style="color:#f1c232;">nullptr</span>;</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#c82613;">SpatialReference</span>.GetLinearUnits(&units);</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">return</span><span style="color:#b36ae2;"> std::string</span>(units);</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#b36ae2;">std::string</span> <strong>getAuthorityName</strong>(){</span></div><div><span style="font-size:12px;line-height:20px;"> <span style="color:#f1c232;"> if</span>(<span style="color:#f1c232;">auto</span>* p = <span style="color:#c82613;">SpatialReference</span>.GetAuthorityName({}))</span></div><div><span style="font-size:12px;line-height:20px;">    <span style="color:#f1c232;">return </span>p;</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">return </span>{};</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div></div><div> </div><div><div><span style="font-size:12px;line-height:20px;"><span style="color:#b36ae2;">std::string</span> <strong>getAuthorityCode</strong>(){</span></div><div><span style="font-size:12px;line-height:20px;"> <span style="color:#f1c232;"> if</span>(<span style="color:#f1c232;">auto</span>* p = <span style="color:#c82613;">SpatialReference</span>.GetAuthorityCode({}))</span></div><div><span style="font-size:12px;line-height:20px;">    <span style="color:#f1c232;">return </span>p;</span></div><div><span style="font-size:12px;line-height:20px;">  <span style="color:#f1c232;">return </span>{};</span></div><div><span style="font-size:12px;line-height:20px;">}</span></div><div><span style="font-size:14px;line-height:20px;"><span style="color:#00b050;">/*------------- END OF <strong>mylib_settings.cpp </strong></span></span><span style="font-size:12px;line-height:20px;"><span style="font-size: 14px;"><span style="color:#00b050;">-------------*/</span></span></span></div></div></div></div><div> </div><div> </div><div>Regards,</div><div>Kerim Khemraev</div><div> </div></BODY></HTML>