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

Method FindMatches

ogr/ogrspatialreference.cpp:11894–12004  ·  view source on GitHub ↗

* \brief Try to identify a match between the passed SRS and a related SRS * in a catalog. * * Matching may be partial, or may fail. * Returned entries will be sorted by decreasing match confidence (first * entry has the highest match confidence). * * The exact way matching is done may change in future versions. Starting with * GDAL 3.0, it relies on PROJ' proj_identify() function. * * Th

Source from the content-addressed store, hash-verified

11892 * @see OGRSpatialReference::FindBestMatch()
11893 */
11894OGRSpatialReferenceH *
11895OGRSpatialReference::FindMatches(CSLConstList papszOptions, int *pnEntries,
11896 int **ppanMatchConfidence) const
11897{
11898 TAKE_OPTIONAL_LOCK();
11899
11900 CPL_IGNORE_RET_VAL(papszOptions);
11901
11902 if (pnEntries)
11903 *pnEntries = 0;
11904 if (ppanMatchConfidence)
11905 *ppanMatchConfidence = nullptr;
11906
11907 d->refreshProjObj();
11908 if (!d->m_pj_crs)
11909 return nullptr;
11910
11911 int *panConfidence = nullptr;
11912 auto ctxt = d->getPROJContext();
11913 auto list =
11914 proj_identify(ctxt, d->m_pj_crs, nullptr, nullptr, &panConfidence);
11915 if (!list)
11916 return nullptr;
11917
11918 const int nMatches = proj_list_get_count(list);
11919
11920 if (pnEntries)
11921 *pnEntries = static_cast<int>(nMatches);
11922 OGRSpatialReferenceH *pahRet = static_cast<OGRSpatialReferenceH *>(
11923 CPLCalloc(sizeof(OGRSpatialReferenceH), nMatches + 1));
11924 if (ppanMatchConfidence)
11925 {
11926 *ppanMatchConfidence =
11927 static_cast<int *>(CPLMalloc(sizeof(int) * (nMatches + 1)));
11928 }
11929
11930 bool bSortAgain = false;
11931
11932 for (int i = 0; i < nMatches; i++)
11933 {
11934 PJ *obj = proj_list_get(ctxt, list, i);
11935 CPLAssert(obj);
11936 OGRSpatialReference *poSRS = new OGRSpatialReference();
11937 poSRS->d->setPjCRS(obj);
11938 pahRet[i] = ToHandle(poSRS);
11939
11940 // Identify matches that only differ by axis order
11941 if (panConfidence[i] == 50 && GetAxesCount() == 2 &&
11942 poSRS->GetAxesCount() == 2 &&
11943 GetDataAxisToSRSAxisMapping() == std::vector<int>{1, 2})
11944 {
11945 OGRAxisOrientation eThisAxis0 = OAO_Other;
11946 OGRAxisOrientation eThisAxis1 = OAO_Other;
11947 OGRAxisOrientation eSRSAxis0 = OAO_Other;
11948 OGRAxisOrientation eSRSAxis1 = OAO_Other;
11949 GetAxis(nullptr, 0, &eThisAxis0);
11950 GetAxis(nullptr, 1, &eThisAxis1);
11951 poSRS->GetAxis(nullptr, 0, &eSRSAxis0);

Callers 7

OSRFindMatchesFunction · 0.80
IdentifyCRSMethod · 0.80
GDBToOGRSpatialReferenceFunction · 0.80
mainFunction · 0.80
test_osr_epsg_13Function · 0.80
MainMethod · 0.80

Calls 13

CPLCallocFunction · 0.85
CPLMallocFunction · 0.85
refreshProjObjMethod · 0.80
getPROJContextMethod · 0.80
setPjCRSMethod · 0.80
GetAxesCountMethod · 0.80
GetAxisMethod · 0.80
ToHandleFunction · 0.70
CPL_IGNORE_RET_VALFunction · 0.50
push_backMethod · 0.45
beginMethod · 0.45

Tested by 3

mainFunction · 0.64
test_osr_epsg_13Function · 0.64