MCPcopy Create free account
hub / github.com/OSGeo/gdal / CPL_STDCALL GDALLoadWorldFile

Function CPL_STDCALL GDALLoadWorldFile

gcore/gdal_misc.cpp:2552–2608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2550 */
2551
2552int CPL_STDCALL GDALLoadWorldFile(const char *pszFilename,
2553 double *padfGeoTransform)
2554
2555{
2556 VALIDATE_POINTER1(pszFilename, "GDALLoadWorldFile", FALSE);
2557 VALIDATE_POINTER1(padfGeoTransform, "GDALLoadWorldFile", FALSE);
2558
2559 char **papszLines = CSLLoad2(pszFilename, 100, 100, nullptr);
2560
2561 if (!papszLines)
2562 return FALSE;
2563
2564 double world[6] = {0.0};
2565 // reads the first 6 non-empty lines
2566 int nLines = 0;
2567 const int nLinesCount = CSLCount(papszLines);
2568 for (int i = 0;
2569 i < nLinesCount && nLines < static_cast<int>(CPL_ARRAYSIZE(world));
2570 ++i)
2571 {
2572 CPLString line(papszLines[i]);
2573 if (line.Trim().empty())
2574 continue;
2575
2576 world[nLines] = CPLAtofM(line);
2577 ++nLines;
2578 }
2579
2580 if (nLines == 6 && (world[0] != 0.0 || world[2] != 0.0) &&
2581 (world[3] != 0.0 || world[1] != 0.0))
2582 {
2583 padfGeoTransform[0] = world[4];
2584 padfGeoTransform[1] = world[0];
2585 padfGeoTransform[2] = world[2];
2586 padfGeoTransform[3] = world[5];
2587 padfGeoTransform[4] = world[1];
2588 padfGeoTransform[5] = world[3];
2589
2590 // correct for center of pixel vs. top left of pixel
2591 padfGeoTransform[0] -= 0.5 * padfGeoTransform[1];
2592 padfGeoTransform[0] -= 0.5 * padfGeoTransform[2];
2593 padfGeoTransform[3] -= 0.5 * padfGeoTransform[4];
2594 padfGeoTransform[3] -= 0.5 * padfGeoTransform[5];
2595
2596 CSLDestroy(papszLines);
2597
2598 return TRUE;
2599 }
2600 else
2601 {
2602 CPLDebug("GDAL",
2603 "GDALLoadWorldFile(%s) found file, but it was corrupt.",
2604 pszFilename);
2605 CSLDestroy(papszLines);
2606 return FALSE;
2607 }
2608}
2609

Callers

nothing calls this directly

Calls 5

CSLLoad2Function · 0.85
CSLCountFunction · 0.85
CPLAtofMFunction · 0.85
CPLDebugFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected