MCPcopy Create free account
hub / github.com/OSGeo/PROJ / insertIntoHierarchy

Function insertIntoHierarchy

src/grids.cpp:1381–1440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1379
1380template <class GridType, class GenericGridType>
1381static void
1382insertIntoHierarchy(PJ_CONTEXT *ctx, std::unique_ptr<GridType> &&grid,
1383 const std::string &gridName, const std::string &parentName,
1384 std::vector<std::unique_ptr<GenericGridType>> &topGrids,
1385 std::map<std::string, GridType *> &mapGrids) {
1386 const auto &extent = grid->extentAndRes();
1387
1388 // If we have one or both of grid_name and parent_grid_name, try to use
1389 // the names to recreate the hierarchy
1390 if (!gridName.empty()) {
1391 if (mapGrids.find(gridName) != mapGrids.end()) {
1392 pj_log(ctx, PJ_LOG_DEBUG, "Several grids called %s found!",
1393 gridName.c_str());
1394 }
1395 mapGrids[gridName] = grid.get();
1396 }
1397
1398 if (!parentName.empty()) {
1399 auto iter = mapGrids.find(parentName);
1400 if (iter == mapGrids.end()) {
1401 pj_log(ctx, PJ_LOG_DEBUG,
1402 "Grid %s refers to non-existing parent %s. "
1403 "Using bounding-box method.",
1404 gridName.c_str(), parentName.c_str());
1405 } else {
1406 if (iter->second->extentAndRes().contains(extent)) {
1407 iter->second->m_children.emplace_back(std::move(grid));
1408 return;
1409 } else {
1410 pj_log(ctx, PJ_LOG_DEBUG,
1411 "Grid %s refers to parent %s, but its extent is "
1412 "not included in it. Using bounding-box method.",
1413 gridName.c_str(), parentName.c_str());
1414 }
1415 }
1416 } else if (!gridName.empty()) {
1417 topGrids.emplace_back(std::move(grid));
1418 return;
1419 }
1420
1421 const std::string &type = grid->metadataItem("TYPE");
1422
1423 // Fallback to analyzing spatial extents
1424 for (const auto &candidateParent : topGrids) {
1425 if (!type.empty() && candidateParent->metadataItem("TYPE") != type) {
1426 continue;
1427 }
1428
1429 const auto &candidateParentExtent = candidateParent->extentAndRes();
1430 if (candidateParentExtent.contains(extent)) {
1431 static_cast<GridType *>(candidateParent.get())
1432 ->insertGrid(ctx, std::move(grid));
1433 return;
1434 } else if (candidateParentExtent.intersects(extent)) {
1435 pj_log(ctx, PJ_LOG_DEBUG, "Partially intersecting grids found!");
1436 }
1437 }
1438

Callers 1

openMethod · 0.85

Calls 7

pj_logFunction · 0.85
endMethod · 0.80
insertGridMethod · 0.80
emptyMethod · 0.45
getMethod · 0.45
containsMethod · 0.45
intersectsMethod · 0.45

Tested by

no test coverage detected