Skip to content

Commit

Permalink
GDALCreateGenImgProjTransformer2(): recognize [SRC_SRS_|DST_SRS_][_DA…
Browse files Browse the repository at this point in the history
…TA_AXIS_TO_SRS_AXIS_MAPPING|_AXIS_MAPPING_STRATEGY]
  • Loading branch information
rouault committed Jan 10, 2025
1 parent 06c046d commit 006a750
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions alg/gdaltransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,30 +1951,70 @@ void *GDALCreateGenImgProjTransformer2(GDALDatasetH hSrcDS, GDALDatasetH hDstDS,

const char *pszCO = CSLFetchNameValue(papszOptions, "COORDINATE_OPERATION");

const auto SetAxisMapping =
[papszOptions](OGRSpatialReference &oSRS, const char *pszPrefix)
{
const char *pszMapping = CSLFetchNameValue(
papszOptions, std::string(pszPrefix)
.append("_DATA_AXIS_TO_SRS_AXIS_MAPPING")
.c_str());
if (pszMapping)
{
CPLStringList aosTokens(CSLTokenizeString2(pszMapping, ",", 0));
std::vector<int> anMapping;
for (int i = 0; i < aosTokens.size(); ++i)
anMapping.push_back(atoi(aosTokens[i]));
oSRS.SetDataAxisToSRSAxisMapping(anMapping);
}
else
{
const char *pszStrategy = CSLFetchNameValueDef(
papszOptions,
std::string(pszPrefix).append("_AXIS_MAPPING_STRATEGY").c_str(),
"TRADITIONAL_GIS_ORDER");
if (EQUAL(pszStrategy, "TRADITIONAL_GIS_ORDER"))
oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
else if (EQUAL(pszStrategy, "AUTHORITY_COMPLIANT"))
oSRS.SetAxisMappingStrategy(OAMS_AUTHORITY_COMPLIANT);
else
{
CPLError(CE_Warning, CPLE_AppDefined,
"Unrecognized value '%s' for %s", pszStrategy,
std::string(pszPrefix)
.append("_AXIS_MAPPING_STRATEGY")
.c_str());
return false;
}
}
return true;
};

OGRSpatialReference oSrcSRS;
if (pszSrcSRS)
{
oSrcSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if (pszSrcSRS[0] != '\0' &&
oSrcSRS.SetFromUserInput(pszSrcSRS) != OGRERR_NONE)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Failed to import coordinate system `%s'.", pszSrcSRS);
return nullptr;
}
if (!SetAxisMapping(oSrcSRS, "SRC_SRS"))
return nullptr;
}

OGRSpatialReference oDstSRS;
if (pszDstSRS)
{
oDstSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
if (pszDstSRS[0] != '\0' &&
oDstSRS.SetFromUserInput(pszDstSRS) != OGRERR_NONE)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Failed to import coordinate system `%s'.", pszDstSRS);
return nullptr;
}
if (!SetAxisMapping(oDstSRS, "DST_SRS"))
return nullptr;
}

const char *pszSrcGeolocArray =
Expand Down

0 comments on commit 006a750

Please sign in to comment.