Helper function for translator implementer wanting support for MapInfo * .tab files. * * @param pszFilename filename of .tab * @param padfGeoTransform output geotransform. Must hold 6 doubles. * @param ppszWKT output pointer to a string that will be allocated with * CPLMalloc(). * @param pnGCPCount output pointer to GCP count. * @param ppasGCPs outputer pointer to an array of GCPs. * @ret
| 2295 | * @return TRUE in case of success, FALSE otherwise. |
| 2296 | */ |
| 2297 | int CPL_STDCALL GDALLoadTabFile(const char *pszFilename, |
| 2298 | double *padfGeoTransform, char **ppszWKT, |
| 2299 | int *pnGCPCount, GDAL_GCP **ppasGCPs) |
| 2300 | |
| 2301 | { |
| 2302 | char **papszLines = CSLLoad2(pszFilename, 1000, 200, nullptr); |
| 2303 | |
| 2304 | if (!papszLines) |
| 2305 | return FALSE; |
| 2306 | |
| 2307 | char **papszTok = nullptr; |
| 2308 | bool bTypeRasterFound = false; |
| 2309 | bool bInsideTableDef = false; |
| 2310 | int nCoordinateCount = 0; |
| 2311 | GDAL_GCP asGCPs[256]; // TODO(schwehr): Initialize. |
| 2312 | const int numLines = CSLCount(papszLines); |
| 2313 | |
| 2314 | // Iterate all lines in the TAB-file |
| 2315 | for (int iLine = 0; iLine < numLines; iLine++) |
| 2316 | { |
| 2317 | CSLDestroy(papszTok); |
| 2318 | papszTok = |
| 2319 | CSLTokenizeStringComplex(papszLines[iLine], " \t(),;", TRUE, FALSE); |
| 2320 | |
| 2321 | if (CSLCount(papszTok) < 2) |
| 2322 | continue; |
| 2323 | |
| 2324 | // Did we find table definition |
| 2325 | if (EQUAL(papszTok[0], "Definition") && EQUAL(papszTok[1], "Table")) |
| 2326 | { |
| 2327 | bInsideTableDef = TRUE; |
| 2328 | } |
| 2329 | else if (bInsideTableDef && (EQUAL(papszTok[0], "Type"))) |
| 2330 | { |
| 2331 | // Only RASTER-type will be handled |
| 2332 | if (EQUAL(papszTok[1], "RASTER")) |
| 2333 | { |
| 2334 | bTypeRasterFound = true; |
| 2335 | } |
| 2336 | else |
| 2337 | { |
| 2338 | CSLDestroy(papszTok); |
| 2339 | CSLDestroy(papszLines); |
| 2340 | return FALSE; |
| 2341 | } |
| 2342 | } |
| 2343 | else if (bTypeRasterFound && bInsideTableDef && |
| 2344 | CSLCount(papszTok) > 4 && EQUAL(papszTok[4], "Label") && |
| 2345 | nCoordinateCount < static_cast<int>(CPL_ARRAYSIZE(asGCPs))) |
| 2346 | { |
| 2347 | GDALInitGCPs(1, asGCPs + nCoordinateCount); |
| 2348 | |
| 2349 | asGCPs[nCoordinateCount].dfGCPPixel = CPLAtofM(papszTok[2]); |
| 2350 | asGCPs[nCoordinateCount].dfGCPLine = CPLAtofM(papszTok[3]); |
| 2351 | asGCPs[nCoordinateCount].dfGCPX = CPLAtofM(papszTok[0]); |
| 2352 | asGCPs[nCoordinateCount].dfGCPY = CPLAtofM(papszTok[1]); |
| 2353 | if (papszTok[5] != nullptr) |
| 2354 | { |
nothing calls this directly
no test coverage detected