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

Function GDALPolygonizeT

alg/polygonize.cpp:73–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71
72template <class DataType, class EqualityTest>
73static CPLErr GDALPolygonizeT(GDALRasterBandH hSrcBand,
74 GDALRasterBandH hMaskBand, OGRLayerH hOutLayer,
75 int iPixValField, CSLConstList papszOptions,
76 GDALProgressFunc pfnProgress, void *pProgressArg,
77 GDALDataType eDT)
78
79{
80 VALIDATE_POINTER1(hSrcBand, "GDALPolygonize", CE_Failure);
81 VALIDATE_POINTER1(hOutLayer, "GDALPolygonize", CE_Failure);
82
83 if (pfnProgress == nullptr)
84 pfnProgress = GDALDummyProgress;
85
86 const int nConnectedness =
87 CSLFetchNameValue(papszOptions, "8CONNECTED") ? 8 : 4;
88
89 /* -------------------------------------------------------------------- */
90 /* Confirm our output layer will support feature creation. */
91 /* -------------------------------------------------------------------- */
92 if (!OGR_L_TestCapability(hOutLayer, OLCSequentialWrite))
93 {
94 CPLError(CE_Failure, CPLE_AppDefined,
95 "Output feature layer does not appear to support creation "
96 "of features in GDALPolygonize().");
97 return CE_Failure;
98 }
99
100 /* -------------------------------------------------------------------- */
101 /* Allocate working buffers. */
102 /* -------------------------------------------------------------------- */
103 const int nXSize = GDALGetRasterBandXSize(hSrcBand);
104 const int nYSize = GDALGetRasterBandYSize(hSrcBand);
105 if (nXSize > std::numeric_limits<int>::max() - 2)
106 {
107 CPLError(CE_Failure, CPLE_AppDefined, "Too wide raster");
108 return CE_Failure;
109 }
110
111 DataType *panLastLineVal =
112 static_cast<DataType *>(VSI_MALLOC2_VERBOSE(sizeof(DataType), nXSize));
113 DataType *panThisLineVal =
114 static_cast<DataType *>(VSI_MALLOC2_VERBOSE(sizeof(DataType), nXSize));
115 GInt32 *panLastLineId =
116 static_cast<GInt32 *>(VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
117 GInt32 *panThisLineId =
118 static_cast<GInt32 *>(VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize));
119
120 GByte *pabyMaskLine = static_cast<GByte *>(VSI_MALLOC_VERBOSE(nXSize));
121
122 if (panLastLineVal == nullptr || panThisLineVal == nullptr ||
123 panLastLineId == nullptr || panThisLineId == nullptr ||
124 pabyMaskLine == nullptr)
125 {
126 CPLFree(panThisLineId);
127 CPLFree(panLastLineId);
128 CPLFree(panThisLineVal);
129 CPLFree(panLastLineVal);
130 CPLFree(pabyMaskLine);

Callers

nothing calls this directly

Calls 15

CSLFetchNameValueFunction · 0.85
OGR_L_TestCapabilityFunction · 0.85
CPLErrorFunction · 0.85
GDALGeoTransformFunction · 0.85
CSLFetchNameValueDefFunction · 0.85
ProcessLineMethod · 0.80
CompleteMergesMethod · 0.80
getTheOuterPolygonMethod · 0.80
getErrMethod · 0.80
GPMaskImageDataFunction · 0.70
maxFunction · 0.50
OpenFunction · 0.50

Tested by

no test coverage detected