MCPcopy Create free account
hub / github.com/OSGeo/gdal / GDALLoadRPCFile

Function GDALLoadRPCFile

gcore/gdal_mdreader.cpp:633–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

631 * http://trac.osgeo.org/gdal/ticket/3639 */
632
633char **GDALLoadRPCFile(const CPLString &soFilePath)
634{
635 if (soFilePath.empty())
636 return nullptr;
637
638 /* -------------------------------------------------------------------- */
639 /* Read file and parse. */
640 /* -------------------------------------------------------------------- */
641 // 100 lines would be enough, but some .rpc files have CR CR LF end of
642 // lines, which result in a blank line to be recognized, so accept up
643 // to 200 lines (#6341)
644 char **papszLines = CSLLoad2(soFilePath, 200, 100, nullptr);
645 if (!papszLines)
646 return nullptr;
647
648 char **papszMD = nullptr;
649
650 /* From LINE_OFF to HEIGHT_SCALE */
651 for (size_t i = 0; i < 23; i += 2)
652 {
653 const char *pszRPBVal = CSLFetchNameValue(papszLines, apszRPBMap[i]);
654
655 if (pszRPBVal == nullptr)
656 {
657 if (strcmp(apszRPBMap[i], RPC_ERR_RAND) == 0 ||
658 strcmp(apszRPBMap[i], RPC_ERR_BIAS) == 0)
659 {
660 continue;
661 }
662 CPLError(
663 CE_Failure, CPLE_AppDefined,
664 "%s file found, but missing %s field (and possibly others).",
665 soFilePath.c_str(), apszRPBMap[i]);
666 CSLDestroy(papszMD);
667 CSLDestroy(papszLines);
668 return nullptr;
669 }
670 else
671 {
672 while (*pszRPBVal == ' ' || *pszRPBVal == '\t')
673 pszRPBVal++;
674 papszMD = CSLSetNameValue(papszMD, apszRPBMap[i], pszRPBVal);
675 }
676 }
677
678 /* For LINE_NUM_COEFF, LINE_DEN_COEFF, SAMP_NUM_COEFF, SAMP_DEN_COEFF */
679 /* parameters that have 20 values each */
680 for (size_t i = 24; apszRPBMap[i] != nullptr; i += 2)
681 {
682 CPLString soVal;
683 for (int j = 1; j <= 20; j++)
684 {
685 CPLString soRPBMapItem;
686 soRPBMapItem.Printf("%s_%d", apszRPBMap[i], j);
687 const char *pszRPBVal =
688 CSLFetchNameValue(papszLines, soRPBMapItem.c_str());
689 if (pszRPBVal == nullptr)
690 {

Callers 5

LoadMetadataMethod · 0.85
LoadMetadataMethod · 0.85
LoadMetadataMethod · 0.85
LoadMetadataMethod · 0.85
OpenInternalMethod · 0.85

Calls 7

CSLLoad2Function · 0.85
CSLFetchNameValueFunction · 0.85
CPLErrorFunction · 0.85
CSLSetNameValueFunction · 0.85
PrintfMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected