108
111
" gdaldem hillshade input_dem output_hillshade \n"
109
112
" [-z ZFactor (default=1)] [-s scale* (default=1)] \n"
110
113
" [-az Azimuth (default=315)] [-alt Altitude (default=45)]\n"
111
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
114
" [-alg ZevenbergenThorne]\n"
115
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
113
117
" - To generates a slope map from any GDAL-supported elevation raster :\n\n"
114
118
" gdaldem slope input_dem output_slope_map \n"
115
119
" [-p use percent slope (default=degrees)] [-s scale* (default=1)]\n"
116
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
120
" [-alg ZevenbergenThorne]\n"
121
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
118
123
" - To generate an aspect map from any GDAL-supported elevation raster\n"
119
124
" Outputs a 32-bit float tiff with pixel values from 0-360 indicating azimuth :\n\n"
120
125
" gdaldem aspect input_dem output_aspect_map \n"
121
126
" [-trigonometric] [-zero_for_flat]\n"
122
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
127
" [-alg ZevenbergenThorne]\n"
128
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
124
130
" - To generate a color relief map from any GDAL-supported elevation raster\n"
125
131
" gdaldem color-relief input_dem color_text_file output_color_relief_map\n"
130
136
" - To generate a Terrain Ruggedness Index (TRI) map from any GDAL-supported elevation raster\n"
131
137
" gdaldem TRI input_dem output_TRI_map\n"
132
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
138
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
134
140
" - To generate a Topographic Position Index (TPI) map from any GDAL-supported elevation raster\n"
135
141
" gdaldem TPI input_dem output_TPI_map\n"
136
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
142
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
138
144
" - To generate a roughness map from any GDAL-supported elevation raster\n"
139
145
" gdaldem roughness input_dem output_roughness_map\n"
140
" [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
146
" [-compute_edges] [-b Band (default=1)] [-of format] [-co \"NAME=VALUE\"]* [-q]\n"
143
149
" Scale is the ratio of vertical units to horizontal\n"
148
154
/************************************************************************/
156
/************************************************************************/
158
typedef float (*GDALGeneric3x3ProcessingAlg) (float* pafWindow, float fDstNoDataValue, void* pData);
160
static float ComputeVal(int bSrcHasNoData, float fSrcNoDataValue,
161
float* afWin, float fDstNoDataValue,
162
GDALGeneric3x3ProcessingAlg pfnAlg,
166
if (bSrcHasNoData && ARE_REAL_EQUAL(afWin[4], fSrcNoDataValue))
168
return fDstNoDataValue;
170
else if (bSrcHasNoData)
175
if (ARE_REAL_EQUAL(afWin[k], fSrcNoDataValue))
180
return fDstNoDataValue;
185
return pfnAlg(afWin, fDstNoDataValue, pData);
188
/************************************************************************/
149
189
/* GDALGeneric3x3Processing() */
150
190
/************************************************************************/
152
typedef float (*GDALGeneric3x3ProcessingAlg) (float* pafWindow, float fDstNoDataValue, void* pData);
154
192
CPLErr GDALGeneric3x3Processing ( GDALRasterBandH hSrcBand,
155
193
GDALRasterBandH hDstBand,
156
194
GDALGeneric3x3ProcessingAlg pfnAlg,
158
197
GDALProgressFunc pfnProgress,
159
198
void * pProgressData)
213
for (j = 0; j < nXSize; j++)
251
if (bComputeAtEdges && nXSize >= 2 && nYSize >= 2)
215
pafOutputBuf[j] = fDstNoDataValue;
253
for (j = 0; j < nXSize; j++)
256
int jmin = (j == 0) ? j : j - 1;
257
int jmax = (j == nXSize - 1) ? j : j + 1;
259
afWin[0] = INTERPOL(pafThreeLineWin[jmin], pafThreeLineWin[nXSize + jmin]);
260
afWin[1] = INTERPOL(pafThreeLineWin[j], pafThreeLineWin[nXSize + j]);
261
afWin[2] = INTERPOL(pafThreeLineWin[jmax], pafThreeLineWin[nXSize + jmax]);
262
afWin[3] = pafThreeLineWin[jmin];
263
afWin[4] = pafThreeLineWin[j];
264
afWin[5] = pafThreeLineWin[jmax];
265
afWin[6] = pafThreeLineWin[nXSize + jmin];
266
afWin[7] = pafThreeLineWin[nXSize + j];
267
afWin[8] = pafThreeLineWin[nXSize + jmax];
269
pafOutputBuf[j] = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
270
afWin, fDstNoDataValue,
271
pfnAlg, pData, bComputeAtEdges);
273
GDALRasterIO(hDstBand, GF_Write,
275
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
217
GDALRasterIO(hDstBand, GF_Write,
219
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
280
for (j = 0; j < nXSize; j++)
282
pafOutputBuf[j] = fDstNoDataValue;
223
284
GDALRasterIO(hDstBand, GF_Write,
224
0, nYSize - 1, nXSize, 1,
225
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
286
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
290
GDALRasterIO(hDstBand, GF_Write,
291
0, nYSize - 1, nXSize, 1,
292
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
228
296
int nLine1Off = 0*nXSize;
243
311
if (eErr != CE_None)
247
pafOutputBuf[0] = fDstNoDataValue;
249
pafOutputBuf[nXSize - 1] = fDstNoDataValue;
314
if (bComputeAtEdges && nXSize >= 2)
319
afWin[0] = INTERPOL(pafThreeLineWin[nLine1Off + j], pafThreeLineWin[nLine1Off + j+1]);
320
afWin[1] = pafThreeLineWin[nLine1Off + j];
321
afWin[2] = pafThreeLineWin[nLine1Off + j+1];
322
afWin[3] = INTERPOL(pafThreeLineWin[nLine2Off + j], pafThreeLineWin[nLine2Off + j+1]);
323
afWin[4] = pafThreeLineWin[nLine2Off + j];
324
afWin[5] = pafThreeLineWin[nLine2Off + j+1];
325
afWin[6] = INTERPOL(pafThreeLineWin[nLine3Off + j], pafThreeLineWin[nLine3Off + j+1]);
326
afWin[7] = pafThreeLineWin[nLine3Off + j];
327
afWin[8] = pafThreeLineWin[nLine3Off + j+1];
329
pafOutputBuf[j] = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
330
afWin, fDstNoDataValue,
331
pfnAlg, pData, bComputeAtEdges);
334
afWin[0] = pafThreeLineWin[nLine1Off + j-1];
335
afWin[1] = pafThreeLineWin[nLine1Off + j];
336
afWin[2] = INTERPOL(pafThreeLineWin[nLine1Off + j], pafThreeLineWin[nLine1Off + j-1]);
337
afWin[3] = pafThreeLineWin[nLine2Off + j-1];
338
afWin[4] = pafThreeLineWin[nLine2Off + j];
339
afWin[5] = INTERPOL(pafThreeLineWin[nLine2Off + j], pafThreeLineWin[nLine2Off + j-1]);
340
afWin[6] = pafThreeLineWin[nLine3Off + j-1];
341
afWin[7] = pafThreeLineWin[nLine3Off + j];
342
afWin[8] = INTERPOL(pafThreeLineWin[nLine3Off + j], pafThreeLineWin[nLine3Off + j-1]);
344
pafOutputBuf[j] = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
345
afWin, fDstNoDataValue,
346
pfnAlg, pData, bComputeAtEdges);
351
pafOutputBuf[0] = fDstNoDataValue;
353
pafOutputBuf[nXSize - 1] = fDstNoDataValue;
251
356
for (j = 1; j < nXSize - 1; j++)
261
366
afWin[7] = pafThreeLineWin[nLine3Off + j];
262
367
afWin[8] = pafThreeLineWin[nLine3Off + j+1];
264
if (bSrcHasNoData && (
265
afWin[0] == fSrcNoDataValue ||
266
afWin[1] == fSrcNoDataValue ||
267
afWin[2] == fSrcNoDataValue ||
268
afWin[3] == fSrcNoDataValue ||
269
afWin[4] == fSrcNoDataValue ||
270
afWin[5] == fSrcNoDataValue ||
271
afWin[6] == fSrcNoDataValue ||
272
afWin[7] == fSrcNoDataValue ||
273
afWin[8] == fSrcNoDataValue))
275
// We have nulls so write nullValue and move on
276
pafOutputBuf[j] = fDstNoDataValue;
280
// We have a valid 3x3 window.
281
pafOutputBuf[j] = pfnAlg(afWin, fDstNoDataValue, pData);
369
pafOutputBuf[j] = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
370
afWin, fDstNoDataValue,
371
pfnAlg, pData, bComputeAtEdges);
285
374
/* -----------------------------------------
303
392
nLine3Off = nTemp;
395
if (bComputeAtEdges && nXSize >= 2 && nYSize >= 2)
397
for (j = 0; j < nXSize; j++)
400
int jmin = (j == 0) ? j : j - 1;
401
int jmax = (j == nXSize - 1) ? j : j + 1;
403
afWin[0] = pafThreeLineWin[nLine1Off + jmin];
404
afWin[1] = pafThreeLineWin[nLine1Off + j];
405
afWin[2] = pafThreeLineWin[nLine1Off + jmax];
406
afWin[3] = pafThreeLineWin[nLine2Off + jmin];
407
afWin[4] = pafThreeLineWin[nLine2Off + j];
408
afWin[5] = pafThreeLineWin[nLine2Off + jmax];
409
afWin[6] = INTERPOL(pafThreeLineWin[nLine2Off + jmin], pafThreeLineWin[nLine1Off + jmin]);
410
afWin[7] = INTERPOL(pafThreeLineWin[nLine2Off + j], pafThreeLineWin[nLine1Off + j]);
411
afWin[8] = INTERPOL(pafThreeLineWin[nLine2Off + jmax], pafThreeLineWin[nLine1Off + jmax]);
413
pafOutputBuf[j] = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
414
afWin, fDstNoDataValue,
415
pfnAlg, pData, bComputeAtEdges);
417
GDALRasterIO(hDstBand, GF_Write,
419
pafOutputBuf, nXSize, 1, GDT_Float32, 0, 0);
306
422
pfnProgress( 1.0, NULL, pProgressData );
375
491
cang = 1.0 + (254.0 * cang);
496
float GDALHillshadeZevenbergenThorneAlg (float* afWin, float fDstNoDataValue, void* pData)
498
GDALHillshadeAlgData* psData = (GDALHillshadeAlgData*)pData;
499
double x, y, aspect, xx_plus_yy, cang;
502
x = (afWin[3] - afWin[5]) / psData->ewres;
504
y = (afWin[7] - afWin[1]) / psData->nsres;
506
xx_plus_yy = x * x + y * y;
508
// ... then aspect...
511
// ... then the shade value
512
cang = (psData->sin_altRadians -
513
psData->cos_altRadians_mul_z_scale_factor * sqrt(xx_plus_yy) *
514
sin(aspect - psData->azRadians)) /
515
sqrt(1 + psData->square_z_scale_factor * xx_plus_yy);
520
cang = 1.0 + (254.0 * cang);
380
525
void* GDALCreateHillshadeData(double* adfGeoTransform,
530
int bZevenbergenThorne)
386
532
GDALHillshadeAlgData* pData =
387
533
(GDALHillshadeAlgData*)CPLMalloc(sizeof(GDALHillshadeAlgData));
425
571
key = (dx * dx + dy * dy);
427
573
if (psData->slopeFormat == 1)
428
return atan(sqrt(key) / (8*psData->scale)) * radiansToDegrees;
430
return 100*(sqrt(key) / (8*psData->scale));
574
return (float) (atan(sqrt(key) / (8*psData->scale)) * radiansToDegrees);
576
return (float) (100*(sqrt(key) / (8*psData->scale)));
579
float GDALSlopeZevenbergenThorneAlg (float* afWin, float fDstNoDataValue, void* pData)
581
const double radiansToDegrees = 180.0 / M_PI;
582
GDALSlopeAlgData* psData = (GDALSlopeAlgData*)pData;
585
dx = (afWin[3] - afWin[5])/psData->ewres;
587
dy = (afWin[7] - afWin[1])/psData->nsres;
589
key = (dx * dx + dy * dy);
591
if (psData->slopeFormat == 1)
592
return (float) (atan(sqrt(key) / (2*psData->scale)) * radiansToDegrees);
594
return (float) (100*(sqrt(key) / (2*psData->scale)));
433
597
void* GDALCreateSlopeData(double* adfGeoTransform,
466
630
dy = ((afWin[6] + afWin[7] + afWin[7] + afWin[8]) -
467
631
(afWin[0] + afWin[1] + afWin[1] + afWin[2]));
469
aspect = atan2(dy,-dx) / degreesToRadians;
471
if (dx == 0 && dy == 0)
474
aspect = fDstNoDataValue;
476
else if ( psData->bAngleAsAzimuth )
479
aspect = 450.0 - aspect;
481
aspect = 90.0 - aspect;
633
aspect = (float) (atan2(dy,-dx) / degreesToRadians);
635
if (dx == 0 && dy == 0)
638
aspect = fDstNoDataValue;
640
else if ( psData->bAngleAsAzimuth )
643
aspect = 450.0f - aspect;
645
aspect = 90.0f - aspect;
659
float GDALAspectZevenbergenThorneAlg (float* afWin, float fDstNoDataValue, void* pData)
661
const double degreesToRadians = M_PI / 180.0;
662
GDALAspectAlgData* psData = (GDALAspectAlgData*)pData;
666
dx = (afWin[5] - afWin[3]);
668
dy = (afWin[7] - afWin[1]);
670
aspect = (float) (atan2(dy,-dx) / degreesToRadians);
672
if (dx == 0 && dy == 0)
675
aspect = fDstNoDataValue;
677
else if ( psData->bAngleAsAzimuth )
680
aspect = 450.0f - aspect;
682
aspect = 90.0f - aspect;
495
695
void* GDALCreateAspectData(int bAngleAsAzimuth)
497
697
GDALAspectAlgData* pData =
742
942
double dfSrcNoDataValue = GDALGetRasterNoDataValue(hSrcBand, &bSrcHasNoData);
744
944
const char* pszLine;
945
int bIsGMT_CPT = FALSE;
745
946
while ((pszLine = CPLReadLineL(fpColorFile)) != NULL)
948
if (pszLine[0] == '#' && strstr(pszLine, "COLOR_MODEL"))
950
if (strstr(pszLine, "COLOR_MODEL = RGB") == NULL)
952
CPLError(CE_Failure, CPLE_AppDefined, "Only COLOR_MODEL = RGB is supported");
953
CPLFree(pasColorAssociation);
747
960
char** papszFields = CSLTokenizeStringComplex(pszLine, " ,\t:",
749
962
/* Skip comment lines */
750
963
int nTokens = CSLCount(papszFields);
752
papszFields[0][0] != '#' &&
753
papszFields[0][0] != '/')
964
if (nTokens >= 1 && (papszFields[0][0] == '#' ||
965
papszFields[0][0] == '/'))
967
CSLDestroy(papszFields);
971
if (bIsGMT_CPT && nTokens == 8)
973
pasColorAssociation =
974
(ColorAssociation*)CPLRealloc(pasColorAssociation,
975
(nColorAssociation + 2) * sizeof(ColorAssociation));
977
pasColorAssociation[nColorAssociation].dfVal = atof(papszFields[0]);
978
pasColorAssociation[nColorAssociation].nR = atoi(papszFields[1]);
979
pasColorAssociation[nColorAssociation].nG = atoi(papszFields[2]);
980
pasColorAssociation[nColorAssociation].nB = atoi(papszFields[3]);
981
pasColorAssociation[nColorAssociation].nA = 255;
984
pasColorAssociation[nColorAssociation].dfVal = atof(papszFields[4]);
985
pasColorAssociation[nColorAssociation].nR = atoi(papszFields[5]);
986
pasColorAssociation[nColorAssociation].nG = atoi(papszFields[6]);
987
pasColorAssociation[nColorAssociation].nB = atoi(papszFields[7]);
988
pasColorAssociation[nColorAssociation].nA = 255;
991
else if (bIsGMT_CPT && nTokens == 4)
993
/* The first token might be B (background), F (foreground) or N (nodata) */
994
/* Just interested in N */
995
if (EQUAL(papszFields[0], "N") && bSrcHasNoData)
997
pasColorAssociation =
998
(ColorAssociation*)CPLRealloc(pasColorAssociation,
999
(nColorAssociation + 1) * sizeof(ColorAssociation));
1001
pasColorAssociation[nColorAssociation].dfVal = dfSrcNoDataValue;
1002
pasColorAssociation[nColorAssociation].nR = atoi(papszFields[1]);
1003
pasColorAssociation[nColorAssociation].nG = atoi(papszFields[2]);
1004
pasColorAssociation[nColorAssociation].nB = atoi(papszFields[3]);
1005
pasColorAssociation[nColorAssociation].nA = 255;
1006
nColorAssociation++;
1009
else if (!bIsGMT_CPT && nTokens >= 2)
755
1011
pasColorAssociation =
756
1012
(ColorAssociation*)CPLRealloc(pasColorAssociation,
1282
1538
GDALGetBlockSize(hSrcBand, &nBlockXSize, &nBlockYSize);
1284
1540
int bRelativeToVRT;
1541
CPLString osPath = CPLGetPath(pszDstFilename);
1285
1542
char* pszSourceFilename = CPLStrdup(
1286
CPLExtractRelativePath( pszDstFilename, GDALGetDescription(hSrcDataset),
1543
CPLExtractRelativePath( osPath.c_str(), GDALGetDescription(hSrcDataset),
1287
1544
&bRelativeToVRT ));
1289
1546
for(iBand = 0; iBand < nBands; iBand++)
1291
1548
VSIFPrintfL(fp, " <VRTRasterBand dataType=\"Byte\" band=\"%d\">\n", iBand + 1);
1549
VSIFPrintfL(fp, " <ColorInterp>%s</ColorInterp>\n",
1550
GDALGetColorInterpretationName((GDALColorInterp)(GCI_RedBand + iBand)));
1292
1551
VSIFPrintfL(fp, " <ComplexSource>\n");
1293
1552
VSIFPrintfL(fp, " <SourceFilename relativeToVRT=\"%d\">%s</SourceFilename>\n",
1294
1553
bRelativeToVRT, pszSourceFilename);
1549
1815
eDataType = eDstDataType;
1550
1816
nBlockXSize = poDS->GetRasterXSize();
1551
1817
nBlockYSize = 1;
1819
bSrcHasNoData = FALSE;
1820
fSrcNoDataValue = (float)GDALGetRasterNoDataValue(poDS->hSrcBand,
1824
void GDALGeneric3x3RasterBand::InitWidthNoData(void* pImage)
1827
GDALGeneric3x3Dataset * poGDS = (GDALGeneric3x3Dataset *) poDS;
1828
if (eDataType == GDT_Byte)
1830
for(j=0;j<nBlockXSize;j++)
1831
((GByte*)pImage)[j] = (GByte) poGDS->dfDstNoDataValue;
1835
for(j=0;j<nBlockXSize;j++)
1836
((float*)pImage)[j] = (float) poGDS->dfDstNoDataValue;
1554
1840
CPLErr GDALGeneric3x3RasterBand::IReadBlock( int nBlockXOff,
1555
1841
int nBlockYOff,
1558
1846
GDALGeneric3x3Dataset * poGDS = (GDALGeneric3x3Dataset *) poDS;
1560
if ( nBlockYOff == 0 || nBlockYOff == nRasterYSize - 1)
1563
if (eDataType == GDT_Byte)
1565
for(j=0;j<nBlockXSize;j++)
1566
((GByte*)pImage)[j] = (GByte) poGDS->dfDstNoDataValue;
1570
for(j=0;j<nBlockXSize;j++)
1571
((float*)pImage)[j] = (float) poGDS->dfDstNoDataValue;
1848
if (poGDS->bComputeAtEdges && nRasterXSize >= 2 && nRasterYSize >= 2)
1850
if (nBlockYOff == 0)
1854
CPLErr eErr = GDALRasterIO( poGDS->hSrcBand,
1856
0, i, nBlockXSize, 1,
1857
poGDS->apafSourceBuf[i+1],
1861
if (eErr != CE_None)
1863
InitWidthNoData(pImage);
1867
poGDS->nCurLine = 0;
1869
for (j = 0; j < nRasterXSize; j++)
1872
int jmin = (j == 0) ? j : j - 1;
1873
int jmax = (j == nRasterXSize - 1) ? j : j + 1;
1875
afWin[0] = INTERPOL(poGDS->apafSourceBuf[1][jmin], poGDS->apafSourceBuf[2][jmin]);
1876
afWin[1] = INTERPOL(poGDS->apafSourceBuf[1][j], poGDS->apafSourceBuf[2][j]);
1877
afWin[2] = INTERPOL(poGDS->apafSourceBuf[1][jmax], poGDS->apafSourceBuf[2][jmax]);
1878
afWin[3] = poGDS->apafSourceBuf[1][jmin];
1879
afWin[4] = poGDS->apafSourceBuf[1][j];
1880
afWin[5] = poGDS->apafSourceBuf[1][jmax];
1881
afWin[6] = poGDS->apafSourceBuf[2][jmin];
1882
afWin[7] = poGDS->apafSourceBuf[2][j];
1883
afWin[8] = poGDS->apafSourceBuf[2][jmax];
1885
fVal = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
1886
afWin, (float) poGDS->dfDstNoDataValue,
1889
poGDS->bComputeAtEdges);
1891
if (eDataType == GDT_Byte)
1892
((GByte*)pImage)[j] = (GByte) (fVal + 0.5);
1894
((float*)pImage)[j] = fVal;
1899
else if (nBlockYOff == nRasterYSize - 1)
1901
if (poGDS->nCurLine != nRasterYSize - 2)
1905
CPLErr eErr = GDALRasterIO( poGDS->hSrcBand,
1907
0, nRasterYSize - 2 + i, nBlockXSize, 1,
1908
poGDS->apafSourceBuf[i+1],
1912
if (eErr != CE_None)
1914
InitWidthNoData(pImage);
1920
for (j = 0; j < nRasterXSize; j++)
1923
int jmin = (j == 0) ? j : j - 1;
1924
int jmax = (j == nRasterXSize - 1) ? j : j + 1;
1926
afWin[0] = poGDS->apafSourceBuf[1][jmin];
1927
afWin[1] = poGDS->apafSourceBuf[1][j];
1928
afWin[2] = poGDS->apafSourceBuf[1][jmax];
1929
afWin[3] = poGDS->apafSourceBuf[2][jmin];
1930
afWin[4] = poGDS->apafSourceBuf[2][j];
1931
afWin[5] = poGDS->apafSourceBuf[2][jmax];
1932
afWin[6] = INTERPOL(poGDS->apafSourceBuf[2][jmin], poGDS->apafSourceBuf[1][jmin]);
1933
afWin[7] = INTERPOL(poGDS->apafSourceBuf[2][j], poGDS->apafSourceBuf[1][j]);
1934
afWin[8] = INTERPOL(poGDS->apafSourceBuf[2][jmax], poGDS->apafSourceBuf[1][jmax]);
1936
fVal = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
1937
afWin, (float) poGDS->dfDstNoDataValue,
1940
poGDS->bComputeAtEdges);
1942
if (eDataType == GDT_Byte)
1943
((GByte*)pImage)[j] = (GByte) (fVal + 0.5);
1945
((float*)pImage)[j] = fVal;
1951
else if ( nBlockYOff == 0 || nBlockYOff == nRasterYSize - 1)
1953
InitWidthNoData(pImage);
1574
1954
return CE_None;
1577
1957
if ( poGDS->nCurLine != nBlockYOff )
1579
if (nBlockYOff != 1 &&
1580
poGDS->nCurLine == nBlockYOff + 1)
1959
if (poGDS->nCurLine + 1 == nBlockYOff)
1582
1961
float* pafTmp = poGDS->apafSourceBuf[0];
1583
1962
poGDS->apafSourceBuf[0] = poGDS->apafSourceBuf[1];
1584
1963
poGDS->apafSourceBuf[1] = poGDS->apafSourceBuf[2];
1585
1964
poGDS->apafSourceBuf[2] = pafTmp;
1587
poGDS->nCurLine = nBlockYOff;
1589
1966
CPLErr eErr = GDALRasterIO( poGDS->hSrcBand,
1591
1968
0, nBlockYOff + 1, nBlockXSize, 1,
1616
1991
if (eErr != CE_None)
1618
memset(pImage, 0, nBlockXSize * sizeof(float));
1993
InitWidthNoData(pImage);
1999
poGDS->nCurLine = nBlockYOff;
1627
if (eDataType == GDT_Byte)
2002
if (poGDS->bComputeAtEdges && nRasterXSize >= 2)
1629
((GByte*)pImage)[0] = (GByte) poGDS->dfDstNoDataValue;
1630
if (nBlockXSize > 1)
1631
((GByte*)pImage)[nBlockXSize - 1] = (GByte) poGDS->dfDstNoDataValue;
2007
afWin[0] = INTERPOL(poGDS->apafSourceBuf[0][j], poGDS->apafSourceBuf[0][j+1]);
2008
afWin[1] = poGDS->apafSourceBuf[0][j];
2009
afWin[2] = poGDS->apafSourceBuf[0][j+1];
2010
afWin[3] = INTERPOL(poGDS->apafSourceBuf[1][j], poGDS->apafSourceBuf[1][j+1]);
2011
afWin[4] = poGDS->apafSourceBuf[1][j];
2012
afWin[5] = poGDS->apafSourceBuf[1][j+1];
2013
afWin[6] = INTERPOL(poGDS->apafSourceBuf[2][j], poGDS->apafSourceBuf[2][j+1]);
2014
afWin[7] = poGDS->apafSourceBuf[2][j];
2015
afWin[8] = poGDS->apafSourceBuf[2][j+1];
2017
fVal = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
2018
afWin, (float) poGDS->dfDstNoDataValue,
2021
poGDS->bComputeAtEdges);
2023
if (eDataType == GDT_Byte)
2024
((GByte*)pImage)[j] = (GByte) (fVal + 0.5);
2026
((float*)pImage)[j] = fVal;
2028
j = nRasterXSize - 1;
2030
afWin[0] = poGDS->apafSourceBuf[0][j-1];
2031
afWin[1] = poGDS->apafSourceBuf[0][j];
2032
afWin[2] = INTERPOL(poGDS->apafSourceBuf[0][j], poGDS->apafSourceBuf[0][j-1]);
2033
afWin[3] = poGDS->apafSourceBuf[1][j-1];
2034
afWin[4] = poGDS->apafSourceBuf[1][j];
2035
afWin[5] = INTERPOL(poGDS->apafSourceBuf[1][j], poGDS->apafSourceBuf[1][j-1]);
2036
afWin[6] = poGDS->apafSourceBuf[2][j-1];
2037
afWin[7] = poGDS->apafSourceBuf[2][j];
2038
afWin[8] = INTERPOL(poGDS->apafSourceBuf[2][j], poGDS->apafSourceBuf[2][j-1]);
2040
fVal = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
2041
afWin, (float) poGDS->dfDstNoDataValue,
2044
poGDS->bComputeAtEdges);
2046
if (eDataType == GDT_Byte)
2047
((GByte*)pImage)[j] = (GByte) (fVal + 0.5);
2049
((float*)pImage)[j] = fVal;
1635
((float*)pImage)[0] = (float) poGDS->dfDstNoDataValue;
1636
if (nBlockXSize > 1)
1637
((float*)pImage)[nBlockXSize - 1] = (float) poGDS->dfDstNoDataValue;
2053
if (eDataType == GDT_Byte)
2055
((GByte*)pImage)[0] = (GByte) poGDS->dfDstNoDataValue;
2056
if (nBlockXSize > 1)
2057
((GByte*)pImage)[nBlockXSize - 1] = (GByte) poGDS->dfDstNoDataValue;
2061
((float*)pImage)[0] = (float) poGDS->dfDstNoDataValue;
2062
if (nBlockXSize > 1)
2063
((float*)pImage)[nBlockXSize - 1] = (float) poGDS->dfDstNoDataValue;
1641
double dfSrcNoDataValue = GDALGetRasterNoDataValue(poGDS->hSrcBand,
1644
2068
for(j=1;j<nBlockXSize - 1;j++)
1654
2078
afWin[7] = poGDS->apafSourceBuf[2][j];
1655
2079
afWin[8] = poGDS->apafSourceBuf[2][j+1];
1657
// Check if afWin has null value
1658
int bContainsNull = FALSE;
1661
for ( int n = 0; n <= 8; n++)
1663
if(afWin[n] == dfSrcNoDataValue)
1665
bContainsNull = TRUE;
1673
// We have nulls so write nullValue and move on
1674
if (eDataType == GDT_Byte)
1675
((GByte*)pImage)[j] = (GByte) poGDS->dfDstNoDataValue;
1677
((float*)pImage)[j] = (float) poGDS->dfDstNoDataValue;
1679
// We have a valid 3x3 window.
1680
if (eDataType == GDT_Byte)
1681
((GByte*)pImage)[j] = (GByte) (poGDS->pfnAlg(
1682
afWin, poGDS->dfDstNoDataValue, poGDS->pAlgData) + 0.5);
1684
((float*)pImage)[j] = (float) poGDS->pfnAlg(
1685
afWin, poGDS->dfDstNoDataValue, poGDS->pAlgData);
2081
fVal = ComputeVal(bSrcHasNoData, fSrcNoDataValue,
2082
afWin, (float) poGDS->dfDstNoDataValue,
2085
poGDS->bComputeAtEdges);
2087
if (eDataType == GDT_Byte)
2088
((GByte*)pImage)[j] = (GByte) (fVal + 0.5);
2090
((float*)pImage)[j] = fVal;
1689
2094
return CE_None;