Bug report #18969
syncDB() and syncDatabase() fail to import WKTs from esri_extra.wkt and cubewerx_extra.wkt
|Affected QGIS version:||3.1(master)||Regression?:||No|
|Operating System:||Easy fix?:||Yes|
|Pull Request or Patch supplied:||Yes||Resolution:||fixed/implemented|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||26800|
QgsCoordinateReferenceSystem:: syncDb() and syncDatabase(), respectively for QGIS 2.18 and QGIS 3, through loadWkts(), fail to import 1 WKT from esri_extra.wkt (EPSG:102113) and 20 WKTs from cubewerx_extra.wkt (both from GDAL 2.2) during postintall (by crssync.exe in Windows).
This is due to an "empty" line present almost at the end of esri_extra.wkt, before the EPSG:102113 line, that was introduced accidentally with commit:21278c00304bb90c49180bb43cb074e8b4a4ccbf. At that time the code worked well also with that empty line, but later it was changed to fix some other bugs.
The bug lies in loadWkts(), that is used by syncDb() / syncDatabase() to load WKTs from epsg.wkts: it exits returning false if it finds an empty line during the for loop that reads the WKTs lines so it breaks the wkts reading process skipping the last line of esri_extra.wkt and all the lines in cubewerx_extra.wkt.
Obviously, we can fix this deleting the added empty line from esri_extra.wkt, but I think it would be better to fix the bug in loadWkts() slightly modifying this part of the for loop
int pos = line.indexOf( ',' ); if ( pos < 0 ) return false; bool ok; int epsg = line.left( pos ).toInt( &ok ); if ( !ok ) return false;
like is in loadIDs()
int pos = line.indexOf( ',' ); if ( pos < 0 ) continue; bool ok; int epsg = line.left( pos ).toInt( &ok ); if ( !ok ) continue;
because the new esri_extra.wkt and cubewerx_extra.wkt in GDAL 2.3 and above have empty lines between WKTs lines.