Skip to content

Commit

Permalink
Merge pull request #6183 from rouault/mapcontour_nodata
Browse files Browse the repository at this point in the history
Contour layer: take into account nodata value from GDAL raster (fixes #6182)
  • Loading branch information
rouault committed Nov 23, 2020
2 parents 9bd402c + a484345 commit 612a9d6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mapcontour.c
Expand Up @@ -446,6 +446,17 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect)
return MS_FAILURE;
}

{
// Copy nodata value from source dataset to memory dataset
int bHasNoData = FALSE;
double dfNoDataValue = GDALGetRasterNoDataValue(hBand, &bHasNoData);
if( bHasNoData )
{
GDALSetRasterNoDataValue(GDALGetRasterBand(clinfo->hDS, 1),
dfNoDataValue);
}
}

adfGeoTransform[0] = copyRect.minx;
adfGeoTransform[1] = dst_cellsize_x;
adfGeoTransform[2] = 0;
Expand Down Expand Up @@ -533,6 +544,8 @@ static int msContourLayerGenerateContour(layerObj *layer)
int levelCount = 0;
GDALRasterBandH hBand = NULL;
CPLErr eErr;
int bHasNoData = FALSE;
double dfNoDataValue;

contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo;

Expand Down Expand Up @@ -613,10 +626,12 @@ static int msContourLayerGenerateContour(layerObj *layer)
CSLDestroy(levelsTmp);
free(option);
}


dfNoDataValue = GDALGetRasterNoDataValue(hBand, &bHasNoData);

eErr = GDALContourGenerate( hBand, interval, 0.0,
levelCount, levels,
FALSE, 0.0, hLayer,
bHasNoData, dfNoDataValue, hLayer,
OGR_FD_GetFieldIndex(OGR_L_GetLayerDefn( hLayer),
"ID" ),
(elevItem == NULL) ? -1 :
Expand Down

0 comments on commit 612a9d6

Please sign in to comment.