|
19 | 19 | #include "qgsmessagelog.h"
|
20 | 20 | #include <sqlite3.h>
|
21 | 21 | #include <QCollator>
|
| 22 | +#include "qgsprojutils.h" |
22 | 23 |
|
23 | 24 | #if PROJ_VERSION_MAJOR>=6
|
24 | 25 | #include <proj.h>
|
@@ -215,13 +216,61 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
|
215 | 216 | #if PROJ_VERSION_MAJOR>=6
|
216 | 217 | sEllipsoidCacheLock.lockForWrite();
|
217 | 218 |
|
| 219 | + PJ_CONTEXT *context = QgsProjContext::get(); |
| 220 | + PROJ_STRING_LIST authorities = proj_get_authorities_from_database( context ); |
| 221 | + PROJ_STRING_LIST authoritiesIt = authorities; |
| 222 | + while ( char *authority = *authoritiesIt ) |
| 223 | + { |
| 224 | + QgsDebugMsg( QString( authority ) ); |
| 225 | + PROJ_STRING_LIST codes = proj_get_codes_from_database( context, authority, PJ_TYPE_ELLIPSOID, 0 ); |
| 226 | + PROJ_STRING_LIST codesIt = codes; |
| 227 | + while ( char *code = *codesIt ) |
| 228 | + { |
| 229 | + EllipsoidDefinition def; |
| 230 | + |
| 231 | + QgsDebugMsg( QString( code ) ); |
| 232 | + |
| 233 | + PJ *ellipsoid = proj_create_from_database( context, authority, code, PJ_CATEGORY_ELLIPSOID, 0, nullptr ); |
| 234 | + |
| 235 | + QgsDebugMsg( QString( proj_get_name( ellipsoid ) ) ); |
| 236 | + def.description = QString( proj_get_name( ellipsoid ) ) ; |
| 237 | + |
| 238 | + double semiMajor, semiMinor, invFlattening; |
| 239 | + int semiMinorComputed; |
| 240 | + if ( proj_ellipsoid_get_parameters( context, ellipsoid, &semiMajor, &semiMinor, &semiMinorComputed, &invFlattening ) == 0 ) |
| 241 | + { |
| 242 | + def.parameters.semiMajor = semiMajor; |
| 243 | + def.parameters.semiMinor = semiMinor; |
| 244 | + def.parameters.inverseFlattening = invFlattening; |
| 245 | + } |
| 246 | + else |
| 247 | + { |
| 248 | + def.parameters.valid = false; |
| 249 | + } |
| 250 | + |
| 251 | + defs << def; |
| 252 | + |
| 253 | + // sEllipsoidCache.insert( QString( ellipsoid->id ), def.parameters ); |
| 254 | + |
| 255 | + |
| 256 | + codesIt++; |
| 257 | + } |
| 258 | + proj_string_list_destroy( codes ); |
| 259 | + |
| 260 | + authoritiesIt++; |
| 261 | + } |
| 262 | + proj_string_list_destroy( authorities ); |
| 263 | + |
| 264 | +#if 0 |
218 | 265 | // use proj to get ellipsoids
|
219 | 266 | const PJ_ELLPS *ellipsoid = proj_list_ellps();
|
220 | 267 | while ( ellipsoid->name )
|
221 | 268 | {
|
222 | 269 | EllipsoidDefinition def;
|
223 | 270 | def.acronym = ellipsoid->id ;
|
224 | 271 | def.description = ellipsoid->name;
|
| 272 | + QgsDebugMsg( QString( ellipsoid->id ) ); |
| 273 | + QgsDebugMsg( QString( ellipsoid->name ) ); |
225 | 274 | const QString majorString( ellipsoid->major );
|
226 | 275 | def.parameters.semiMajor = majorString.midRef( 2 ).toDouble();
|
227 | 276 | const QString minorString( ellipsoid->ell );
|
@@ -258,6 +307,7 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
|
258 | 307 |
|
259 | 308 | ellipsoid++;
|
260 | 309 | }
|
| 310 | +#endif |
261 | 311 | sEllipsoidCacheLock.unlock();
|
262 | 312 |
|
263 | 313 |
|
@@ -301,7 +351,7 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
|
301 | 351 | collator.setCaseSensitivity( Qt::CaseInsensitive );
|
302 | 352 | std::sort( defs.begin(), defs.end(), [&collator]( const EllipsoidDefinition & a, const EllipsoidDefinition & b )
|
303 | 353 | {
|
304 |
| - return collator.compare( a.acronym, b.acronym ) < 0; |
| 354 | + return collator.compare( a.description, b.description ) < 0; |
305 | 355 | } );
|
306 | 356 | sDefinitionCache = defs;
|
307 | 357 | sDefinitionCacheLock.unlock();
|
|
0 commit comments