Skip to content

Commit

Permalink
Fix contour layer drawing fails when the map extent do not overlap wi…
Browse files Browse the repository at this point in the history
…th the source data (#4753)
  • Loading branch information
Alan Boudreault committed Sep 9, 2013
1 parent 906c8ee commit 0fede4b
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions mapcontour.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void msContourLayerInfoInitialize(layerObj *layer)
clinfo->ogrLayer.connectiontype = MS_OGR;
clinfo->ogrLayer.name = msStrdup(layer->name);
clinfo->ogrLayer.connection = (char*)msSmallMalloc(strlen(clinfo->ogrLayer.name)+13);
sprintf(clinfo->ogrLayer.connection, "__%s_CONTOUR__", layer->name);
sprintf(clinfo->ogrLayer.connection, "__%s_CONTOUR__", clinfo->ogrLayer.name);
clinfo->ogrLayer.units = layer->units;
}

Expand Down Expand Up @@ -322,8 +322,8 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect)

if (copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy) {
if (layer->debug)
msDebug("msContourLayerReadRaster(): Error in overlap calculation.\n");
return MS_FAILURE;
msDebug("msContourLayerReadRaster(): No overlap.\n");
return MS_SUCCESS;
}

/*
Expand Down Expand Up @@ -365,7 +365,7 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect)
{
if (layer->debug)
msDebug("msContourLayerReadRaster(): input window too small, or no apparent overlap between map view and this window(1).\n");
return MS_FAILURE;
return MS_SUCCESS;
}

/* Target buffer size */
Expand All @@ -375,7 +375,7 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect)
if (dst_xsize == 0 || dst_ysize == 0) {
if (layer->debug)
msDebug("msContourLayerReadRaster(): no apparent overlap between map view and this window(2).\n");
return MS_FAILURE;
return MS_SUCCESS;
}

if (layer->debug)
Expand Down Expand Up @@ -522,6 +522,10 @@ static int msContourLayerGenerateContour(layerObj *layer)
return MS_FAILURE;
}

if (!clinfo->hDS) { /* no overlap */
return MS_SUCCESS;
}

hBand = GDALGetRasterBand(clinfo->hDS, 1);
if (hBand == NULL)
{
Expand Down Expand Up @@ -655,12 +659,14 @@ int msContourLayerOpen(layerObj *layer)
if (msContourLayerGenerateContour(layer) != MS_SUCCESS)
return MS_FAILURE;

GDALClose(clinfo->hDS);
clinfo->hDS = NULL;
free(clinfo->buffer);
if (clinfo->hDS) {
GDALClose(clinfo->hDS);
clinfo->hDS = NULL;
free(clinfo->buffer);
}

/* Open our virtual ogr layer */
if (msLayerOpen(&clinfo->ogrLayer) != MS_SUCCESS)
if (clinfo->hOGRDS && (msLayerOpen(&clinfo->ogrLayer) != MS_SUCCESS))
return MS_FAILURE;

return MS_SUCCESS;
Expand All @@ -681,7 +687,8 @@ int msContourLayerClose(layerObj *layer)
msDebug("Entering msContourLayerClose().\n");

if (clinfo) {
msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS);
if (clinfo->hOGRDS)
msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS);

msLayerClose(&clinfo->ogrLayer);

Expand Down Expand Up @@ -718,6 +725,7 @@ int msContourLayerGetItems(layerObj *layer)

int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
{
int i;
rectObj newRect;
contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo;

Expand All @@ -744,7 +752,9 @@ int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
#endif

/* regenerate the raster io */
msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS);
if (clinfo->hOGRDS)
msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS);

msLayerClose(&clinfo->ogrLayer);

/* Open the raster source */
Expand All @@ -755,16 +765,24 @@ int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
if (msContourLayerGenerateContour(layer) != MS_SUCCESS)
return MS_FAILURE;

GDALClose(clinfo->hDS);
clinfo->hDS = NULL;
free(clinfo->buffer);
if (clinfo->hDS) {
GDALClose(clinfo->hDS);
clinfo->hDS = NULL;
free(clinfo->buffer);
}

if (!clinfo->hOGRDS) /* no overlap */
return MS_DONE;

/* Open our virtual ogr layer */
if (msLayerOpen(&clinfo->ogrLayer) != MS_SUCCESS)
return MS_FAILURE;

clinfo->ogrLayer.numitems = layer->numitems;
clinfo->ogrLayer.items = CSLDuplicate(layer->items);
clinfo->ogrLayer.items = (char **) msSmallMalloc(sizeof(char *)*layer->numitems);
for (i=0; i<layer->numitems;++i) {
clinfo->ogrLayer.items[i] = msStrdup(layer->items[i]);
}

return msLayerWhichShapes(&clinfo->ogrLayer, rect, isQuery);
}
Expand Down

0 comments on commit 0fede4b

Please sign in to comment.