Skip to content

Commit

Permalink
Refactoring towards SLD "painter's model" implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbo-ads committed Feb 20, 2020
1 parent 48cfca5 commit 2b80a45
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
43 changes: 23 additions & 20 deletions mapdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
char cache=MS_FALSE;
int maxnumstyles=1;
featureListNodeObjPtr shpcache=NULL, current=NULL;
int classindex = -1;
int nclasses = 0;
int *classgroup = NULL;
double minfeaturesize = -1;
Expand Down Expand Up @@ -1004,9 +1005,6 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
return MS_FAILURE;
}

/* step through the target shapes */
msInitShape(&shape);

nclasses = 0;
classgroup = NULL;
if(layer->classgroup && layer->numclasses > 0)
Expand All @@ -1015,24 +1013,34 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
if(layer->minfeaturesize > 0)
minfeaturesize = Pix2LayerGeoref(map, layer, layer->minfeaturesize);

while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) {

/* Check if the shape size is ok to be drawn */
if((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && (minfeaturesize > 0) && (msShapeCheckSize(&shape, minfeaturesize) == MS_FALSE)) {
if(layer->debug >= MS_DEBUGLEVEL_V)
msDebug("msDrawVectorLayer(): Skipping shape (%ld) because LAYER::MINFEATURESIZE is bigger than shape size\n", shape.index);
msFreeShape(&shape);
continue;
/* step through the target shapes and their classes */
msInitShape(&shape);
classindex = -1;
for (;;) {
if (classindex == -1) {
status = msLayerNextShape(layer, &shape);
if (status != MS_SUCCESS) {
break;
}

/* Check if the shape size is ok to be drawn */
if((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && (minfeaturesize > 0) && (msShapeCheckSize(&shape, minfeaturesize) == MS_FALSE)) {
if(layer->debug >= MS_DEBUGLEVEL_V)
msDebug("msDrawVectorLayer(): Skipping shape (%ld) because LAYER::MINFEATURESIZE is bigger than shape size\n", shape.index);
continue;
}
}

shape.classindex = msShapeGetClass(layer, map, &shape, classgroup, nclasses);
if((shape.classindex == -1) || (layer->class[shape.classindex]->status == MS_OFF)) {
msFreeShape(&shape);
classindex = msShapeGetNextClass(classindex, layer, map, &shape, classgroup, nclasses);
if((classindex == -1) || (layer->class[classindex]->status == MS_OFF)) {
continue;
}
shape.classindex = classindex;
classindex = -1; // This value indicates that no more class is to be
// fetched from current shape

if(maxfeatures >=0 && featuresdrawn >= maxfeatures) {
msFreeShape(&shape);
status = MS_DONE;
break;
}
Expand All @@ -1055,14 +1063,12 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
if(strcasecmp(layer->styleitem, "AUTO") == 0) {
if(msLayerGetAutoStyle(map, layer, layer->class[shape.classindex], &shape) != MS_SUCCESS) {
retcode = MS_FAILURE;
msFreeShape(&shape);
break;
}
} else {
/* Generic feature style handling as per RFC-61 */
if(msLayerGetFeatureStyle(map, layer, layer->class[shape.classindex], &shape) != MS_SUCCESS) {
retcode = MS_FAILURE;
msFreeShape(&shape);
break;
}
}
Expand Down Expand Up @@ -1110,28 +1116,25 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
else
status = msDrawShape(map, layer, &shape, image, -1, drawmode); /* all styles */
if(status != MS_SUCCESS) {
msFreeShape(&shape);
retcode = MS_FAILURE;
break;
}

if(shape.numlines == 0) { /* once clipped the shape didn't need to be drawn */
msFreeShape(&shape);
continue;
}

if(cache) {
if(insertFeatureList(&shpcache, &shape) == NULL) {
msFreeShape(&shape);
retcode = MS_FAILURE; /* problem adding to the cache */
break;
}
}

maxnumstyles = MS_MAX(maxnumstyles, layer->class[shape.classindex]->numstyles);

msFreeShape(&shape);
}
msFreeShape(&shape);

if (classgroup)
msFree(classgroup);
Expand Down
1 change: 1 addition & 0 deletions mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT int msEvalContext(mapObj *map, layerObj *layer, char *context);
MS_DLL_EXPORT int msEvalExpression(layerObj *layer, shapeObj *shape, expressionObj *expression, int itemindex);
MS_DLL_EXPORT int msShapeGetClass(layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses);
MS_DLL_EXPORT int msShapeGetNextClass(int currentclass, layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses);
MS_DLL_EXPORT int msShapeCheckSize(shapeObj *shape, double minfeaturesize);
MS_DLL_EXPORT char* msShapeGetLabelAnnotation(layerObj *layer, shapeObj *shape, labelObj *lbl);
MS_DLL_EXPORT int msGetLabelStatus(mapObj *map, layerObj *layer, shapeObj *shape, labelObj *lbl);
Expand Down
11 changes: 10 additions & 1 deletion maputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,23 @@ int *msAllocateValidClassGroups(layerObj *lp, int *nclasses)
}

int msShapeGetClass(layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses)
{
return msShapeGetNextClass(-1, layer, map, shape, classgroup, numclasses);
}

int msShapeGetNextClass(int currentclass, layerObj *layer, mapObj *map,
shapeObj *shape, int *classgroup, int numclasses)
{
int i, iclass;

if (currentclass < 0)
currentclass = -1;

if (layer->numclasses > 0) {
if (classgroup == NULL || numclasses <=0)
numclasses = layer->numclasses;

for(i=0; i<numclasses; i++) {
for(i=currentclass+1; i<numclasses; i++) {
if (classgroup)
iclass = classgroup[i];
else
Expand Down

0 comments on commit 2b80a45

Please sign in to comment.