apps: use unique_ptr overloads of addGeometry, addRing
References https://github.com/OSGeo/gdal/issues/4371
This commit is contained in:
parent
ffc433ab8b
commit
62a217624e
|
@ -1028,7 +1028,7 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
|
|||
CPLAssert(poGeom);
|
||||
if (poGeom->getGeometryType() == wkbPolygon)
|
||||
{
|
||||
poMP->addGeometryDirectly(poGeom.release());
|
||||
poMP->addGeometry(std::move(poGeom));
|
||||
}
|
||||
}
|
||||
poMemLayer = std::make_unique<OGRMemLayer>("", nullptr, wkbUnknown);
|
||||
|
@ -1095,7 +1095,7 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
|
|||
}
|
||||
}
|
||||
if (!poNewPoly->IsEmpty())
|
||||
poMP->addGeometryDirectly(poNewPoly.release());
|
||||
poMP->addGeometry(std::move(poNewPoly));
|
||||
}
|
||||
poGeom = std::move(poMP);
|
||||
}
|
||||
|
|
|
@ -366,7 +366,7 @@ static void InvertGeometries(GDALDatasetH hDstDS,
|
|||
double adfGeoTransform[6] = {};
|
||||
GDALGetGeoTransform(hDstDS, adfGeoTransform);
|
||||
|
||||
OGRLinearRing *poUniverseRing = new OGRLinearRing();
|
||||
auto poUniverseRing = std::make_unique<OGRLinearRing>();
|
||||
|
||||
poUniverseRing->addPoint(
|
||||
adfGeoTransform[0] + -2 * adfGeoTransform[1] + -2 * adfGeoTransform[2],
|
||||
|
@ -391,9 +391,9 @@ static void InvertGeometries(GDALDatasetH hDstDS,
|
|||
adfGeoTransform[0] + -2 * adfGeoTransform[1] + -2 * adfGeoTransform[2],
|
||||
adfGeoTransform[3] + -2 * adfGeoTransform[4] + -2 * adfGeoTransform[5]);
|
||||
|
||||
OGRPolygon *poUniversePoly = new OGRPolygon();
|
||||
poUniversePoly->addRingDirectly(poUniverseRing);
|
||||
poInvertMP->addGeometryDirectly(poUniversePoly);
|
||||
auto poUniversePoly = std::make_unique<OGRPolygon>();
|
||||
poUniversePoly->addRing(std::move(poUniverseRing));
|
||||
poInvertMP->addGeometry(std::move(poUniversePoly));
|
||||
|
||||
bool bFoundNonPoly = false;
|
||||
// If we have GEOS, use it to "subtract" each polygon from the universe
|
||||
|
@ -434,6 +434,9 @@ static void InvertGeometries(GDALDatasetH hDstDS,
|
|||
return;
|
||||
}
|
||||
|
||||
OGRPolygon &hUniversePoly =
|
||||
*poInvertMP->getGeometryRef(poInvertMP->getNumGeometries() - 1);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* If we don't have GEOS, add outer rings of polygons as inner */
|
||||
/* rings of poUniversePoly and inner rings as sub-polygons. Note */
|
||||
|
@ -460,15 +463,18 @@ static void InvertGeometries(GDALDatasetH hDstDS,
|
|||
}
|
||||
|
||||
const auto ProcessPoly =
|
||||
[poUniversePoly, poInvertMP](OGRPolygon *poPoly)
|
||||
[&hUniversePoly, poInvertMP](OGRPolygon *poPoly)
|
||||
{
|
||||
for (int i = poPoly->getNumInteriorRings() - 1; i >= 0; --i)
|
||||
{
|
||||
auto poNewPoly = new OGRPolygon();
|
||||
poNewPoly->addRingDirectly(poPoly->stealInteriorRing(i));
|
||||
poInvertMP->addGeometryDirectly(poNewPoly);
|
||||
auto poNewPoly = std::make_unique<OGRPolygon>();
|
||||
std::unique_ptr<OGRLinearRing> poRing(
|
||||
poPoly->stealInteriorRing(i));
|
||||
poNewPoly->addRing(std::move(poRing));
|
||||
poInvertMP->addGeometry(std::move(poNewPoly));
|
||||
}
|
||||
poUniversePoly->addRingDirectly(poPoly->stealExteriorRing());
|
||||
std::unique_ptr<OGRLinearRing> poShell(poPoly->stealExteriorRing());
|
||||
hUniversePoly.addRing(std::move(poShell));
|
||||
};
|
||||
|
||||
if (eGType == wkbPolygon)
|
||||
|
|
|
@ -1269,7 +1269,7 @@ GDALDatasetH GDALTileIndex(const char *pszDest, int nSrcCount,
|
|||
auto poRing = std::make_unique<OGRLinearRing>();
|
||||
for (int k = 0; k < 5; k++)
|
||||
poRing->addPoint(adfX[k], adfY[k]);
|
||||
poPoly->addRingDirectly(poRing.release());
|
||||
poPoly->addRing(std::move(poRing));
|
||||
poFeature->SetGeometryDirectly(poPoly.release());
|
||||
|
||||
if (poLayer->CreateFeature(poFeature.get()) != OGRERR_NONE)
|
||||
|
|
|
@ -3427,7 +3427,7 @@ static CPLErr LoadCutline(const std::string &osCutlineDSNameOrWKT,
|
|||
OGRwkbGeometryType eType = wkbFlatten(poGeom->getGeometryType());
|
||||
|
||||
if (eType == wkbPolygon)
|
||||
poMultiPolygon->addGeometryDirectly(poGeom.release());
|
||||
poMultiPolygon->addGeometry(std::move(poGeom));
|
||||
else if (eType == wkbMultiPolygon)
|
||||
{
|
||||
for (const auto *poSubGeom : poGeom->toMultiPolygon())
|
||||
|
@ -5401,7 +5401,7 @@ static CPLErr TransformCutlineToSource(GDALDataset *poSrcDS,
|
|||
{
|
||||
const double dfCutlineBlendDist = CPLAtof(CSLFetchNameValueDef(
|
||||
*ppapszWarpOptions, "CUTLINE_BLEND_DIST", "0"));
|
||||
OGRLinearRing *poRing = new OGRLinearRing();
|
||||
auto poRing = std::make_unique<OGRLinearRing>();
|
||||
poRing->addPoint(-dfCutlineBlendDist, -dfCutlineBlendDist);
|
||||
poRing->addPoint(-dfCutlineBlendDist,
|
||||
dfCutlineBlendDist + poSrcDS->GetRasterYSize());
|
||||
|
@ -5411,7 +5411,7 @@ static CPLErr TransformCutlineToSource(GDALDataset *poSrcDS,
|
|||
-dfCutlineBlendDist);
|
||||
poRing->addPoint(-dfCutlineBlendDist, -dfCutlineBlendDist);
|
||||
OGRPolygon oSrcDSFootprint;
|
||||
oSrcDSFootprint.addRingDirectly(poRing);
|
||||
oSrcDSFootprint.addRing(std::move(poRing));
|
||||
OGREnvelope sSrcDSEnvelope;
|
||||
oSrcDSFootprint.getEnvelope(&sSrcDSEnvelope);
|
||||
OGREnvelope sCutlineEnvelope;
|
||||
|
|
|
@ -688,13 +688,13 @@ static std::unique_ptr<OGRGeometry> LoadGeometry(const std::string &osDS,
|
|||
"should be manually inspected.",
|
||||
poFeat->GetFID(), osDS.c_str());
|
||||
|
||||
oGC.addGeometryDirectly(poValid.release());
|
||||
oGC.addGeometry(std::move(poValid));
|
||||
}
|
||||
else
|
||||
{
|
||||
CPLError(CE_Failure, CPLE_AppDefined,
|
||||
"Geometry of feature " CPL_FRMT_GIB " of %s "
|
||||
"is invalid, and could not been made valid.",
|
||||
"is invalid, and could not be made valid.",
|
||||
poFeat->GetFID(), osDS.c_str());
|
||||
oGC.empty();
|
||||
break;
|
||||
|
@ -702,7 +702,7 @@ static std::unique_ptr<OGRGeometry> LoadGeometry(const std::string &osDS,
|
|||
}
|
||||
else
|
||||
{
|
||||
oGC.addGeometryDirectly(poSrcGeom.release());
|
||||
oGC.addGeometry(std::move(poSrcGeom));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue