Skip to content

Commit fb36ab7

Browse files
authored
Merge pull request #11145 from dbaston/apps-add-unique-ptr
apps: use unique_ptr overloads of addGeometry, addRing
2 parents 5479b45 + 62a2176 commit fb36ab7

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

apps/gdal_footprint_lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
10281028
CPLAssert(poGeom);
10291029
if (poGeom->getGeometryType() == wkbPolygon)
10301030
{
1031-
poMP->addGeometryDirectly(poGeom.release());
1031+
poMP->addGeometry(std::move(poGeom));
10321032
}
10331033
}
10341034
poMemLayer = std::make_unique<OGRMemLayer>("", nullptr, wkbUnknown);
@@ -1095,7 +1095,7 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
10951095
}
10961096
}
10971097
if (!poNewPoly->IsEmpty())
1098-
poMP->addGeometryDirectly(poNewPoly.release());
1098+
poMP->addGeometry(std::move(poNewPoly));
10991099
}
11001100
poGeom = std::move(poMP);
11011101
}

apps/gdal_rasterize_lib.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static void InvertGeometries(GDALDatasetH hDstDS,
366366
double adfGeoTransform[6] = {};
367367
GDALGetGeoTransform(hDstDS, adfGeoTransform);
368368

369-
OGRLinearRing *poUniverseRing = new OGRLinearRing();
369+
auto poUniverseRing = std::make_unique<OGRLinearRing>();
370370

371371
poUniverseRing->addPoint(
372372
adfGeoTransform[0] + -2 * adfGeoTransform[1] + -2 * adfGeoTransform[2],
@@ -391,9 +391,9 @@ static void InvertGeometries(GDALDatasetH hDstDS,
391391
adfGeoTransform[0] + -2 * adfGeoTransform[1] + -2 * adfGeoTransform[2],
392392
adfGeoTransform[3] + -2 * adfGeoTransform[4] + -2 * adfGeoTransform[5]);
393393

394-
OGRPolygon *poUniversePoly = new OGRPolygon();
395-
poUniversePoly->addRingDirectly(poUniverseRing);
396-
poInvertMP->addGeometryDirectly(poUniversePoly);
394+
auto poUniversePoly = std::make_unique<OGRPolygon>();
395+
poUniversePoly->addRing(std::move(poUniverseRing));
396+
poInvertMP->addGeometry(std::move(poUniversePoly));
397397

398398
bool bFoundNonPoly = false;
399399
// If we have GEOS, use it to "subtract" each polygon from the universe
@@ -434,6 +434,9 @@ static void InvertGeometries(GDALDatasetH hDstDS,
434434
return;
435435
}
436436

437+
OGRPolygon &hUniversePoly =
438+
*poInvertMP->getGeometryRef(poInvertMP->getNumGeometries() - 1);
439+
437440
/* -------------------------------------------------------------------- */
438441
/* If we don't have GEOS, add outer rings of polygons as inner */
439442
/* rings of poUniversePoly and inner rings as sub-polygons. Note */
@@ -460,15 +463,18 @@ static void InvertGeometries(GDALDatasetH hDstDS,
460463
}
461464

462465
const auto ProcessPoly =
463-
[poUniversePoly, poInvertMP](OGRPolygon *poPoly)
466+
[&hUniversePoly, poInvertMP](OGRPolygon *poPoly)
464467
{
465468
for (int i = poPoly->getNumInteriorRings() - 1; i >= 0; --i)
466469
{
467-
auto poNewPoly = new OGRPolygon();
468-
poNewPoly->addRingDirectly(poPoly->stealInteriorRing(i));
469-
poInvertMP->addGeometryDirectly(poNewPoly);
470+
auto poNewPoly = std::make_unique<OGRPolygon>();
471+
std::unique_ptr<OGRLinearRing> poRing(
472+
poPoly->stealInteriorRing(i));
473+
poNewPoly->addRing(std::move(poRing));
474+
poInvertMP->addGeometry(std::move(poNewPoly));
470475
}
471-
poUniversePoly->addRingDirectly(poPoly->stealExteriorRing());
476+
std::unique_ptr<OGRLinearRing> poShell(poPoly->stealExteriorRing());
477+
hUniversePoly.addRing(std::move(poShell));
472478
};
473479

474480
if (eGType == wkbPolygon)

apps/gdaltindex_lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ GDALDatasetH GDALTileIndex(const char *pszDest, int nSrcCount,
12691269
auto poRing = std::make_unique<OGRLinearRing>();
12701270
for (int k = 0; k < 5; k++)
12711271
poRing->addPoint(adfX[k], adfY[k]);
1272-
poPoly->addRingDirectly(poRing.release());
1272+
poPoly->addRing(std::move(poRing));
12731273
poFeature->SetGeometryDirectly(poPoly.release());
12741274

12751275
if (poLayer->CreateFeature(poFeature.get()) != OGRERR_NONE)

apps/gdalwarp_lib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,7 +3427,7 @@ static CPLErr LoadCutline(const std::string &osCutlineDSNameOrWKT,
34273427
OGRwkbGeometryType eType = wkbFlatten(poGeom->getGeometryType());
34283428

34293429
if (eType == wkbPolygon)
3430-
poMultiPolygon->addGeometryDirectly(poGeom.release());
3430+
poMultiPolygon->addGeometry(std::move(poGeom));
34313431
else if (eType == wkbMultiPolygon)
34323432
{
34333433
for (const auto *poSubGeom : poGeom->toMultiPolygon())
@@ -5401,7 +5401,7 @@ static CPLErr TransformCutlineToSource(GDALDataset *poSrcDS,
54015401
{
54025402
const double dfCutlineBlendDist = CPLAtof(CSLFetchNameValueDef(
54035403
*ppapszWarpOptions, "CUTLINE_BLEND_DIST", "0"));
5404-
OGRLinearRing *poRing = new OGRLinearRing();
5404+
auto poRing = std::make_unique<OGRLinearRing>();
54055405
poRing->addPoint(-dfCutlineBlendDist, -dfCutlineBlendDist);
54065406
poRing->addPoint(-dfCutlineBlendDist,
54075407
dfCutlineBlendDist + poSrcDS->GetRasterYSize());
@@ -5411,7 +5411,7 @@ static CPLErr TransformCutlineToSource(GDALDataset *poSrcDS,
54115411
-dfCutlineBlendDist);
54125412
poRing->addPoint(-dfCutlineBlendDist, -dfCutlineBlendDist);
54135413
OGRPolygon oSrcDSFootprint;
5414-
oSrcDSFootprint.addRingDirectly(poRing);
5414+
oSrcDSFootprint.addRing(std::move(poRing));
54155415
OGREnvelope sSrcDSEnvelope;
54165416
oSrcDSFootprint.getEnvelope(&sSrcDSEnvelope);
54175417
OGREnvelope sCutlineEnvelope;

apps/ogr2ogr_lib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,21 +688,21 @@ static std::unique_ptr<OGRGeometry> LoadGeometry(const std::string &osDS,
688688
"should be manually inspected.",
689689
poFeat->GetFID(), osDS.c_str());
690690

691-
oGC.addGeometryDirectly(poValid.release());
691+
oGC.addGeometry(std::move(poValid));
692692
}
693693
else
694694
{
695695
CPLError(CE_Failure, CPLE_AppDefined,
696696
"Geometry of feature " CPL_FRMT_GIB " of %s "
697-
"is invalid, and could not been made valid.",
697+
"is invalid, and could not be made valid.",
698698
poFeat->GetFID(), osDS.c_str());
699699
oGC.empty();
700700
break;
701701
}
702702
}
703703
else
704704
{
705-
oGC.addGeometryDirectly(poSrcGeom.release());
705+
oGC.addGeometry(std::move(poSrcGeom));
706706
}
707707
}
708708
}

0 commit comments

Comments
 (0)