Permalink
Browse files

Apply map rotation to symbols, similarly to the rule of labels (fixes #…

…5271)

If the symbol angle is unspecified or 0, then the map rotation is ignored.
Otherwise, the map rotation is applied.
  • Loading branch information...
rouault committed Jun 11, 2018
1 parent 2f0678d commit 91d53be63cf0061466ced1d99171039ef869e168
Showing with 189 additions and 6 deletions.
  1. +39 −6 mapdraw.c
  2. BIN msautotest/renderers/expected/symbolrot.png
  3. +150 −0 msautotest/renderers/symbolrot.map
@@ -1683,14 +1683,29 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
{
int l, c = shape->classindex, j, i, s;
pointObj *point;
int ret = MS_FAILURE;

#ifdef USE_PROJ
if (layer->project && layer->transform == MS_TRUE)
msProjectShape(&layer->projection, &map->projection, shape);
#endif

for (l = 0; l < layer->class[c]->numlabels; l++)
if (layer->class[c]->labels[l]->angle != 0) layer->class[c]->labels[l]->angle -= map->gt.rotation_angle; /* TODO: is this right???? */
// Only take into account map rotation if the label and style angles are
// non-zero.
if( map->gt.rotation_angle )
{
for (l = 0; l < layer->class[c]->numlabels; l++)
{
if( layer->class[c]->labels[l]->angle != 0 )
layer->class[c]->labels[l]->angle -= map->gt.rotation_angle;
}

for (s = 0; s < layer->class[c]->numstyles; s++)
{
if( layer->class[c]->styles[s]->angle != 0 )
layer->class[c]->styles[s]->angle -= map->gt.rotation_angle;
}
}

for (j = 0; j < shape->numlines; j++) {
for (i = 0; i < shape->line[j].numpoints; i++) {
@@ -1707,26 +1722,44 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
layer->class[c]->styles[s]->minscaledenom,
layer->class[c]->styles[s]->maxscaledenom))
if(UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, point, layer->class[c]->styles[s], layer->scalefactor))) {
return MS_FAILURE;
goto end;
}
}
}
if(MS_DRAW_LABELS(drawmode)) {
if (layer->labelcache) {
if (msAddLabelGroup(map, image, layer, c, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
if (msAddLabelGroup(map, image, layer, c, shape, point, -1) != MS_SUCCESS) goto end;
} else {
for (l = 0; l < layer->class[c]->numlabels; l++)
if(msGetLabelStatus(map,layer,shape,layer->class[c]->labels[l]) == MS_ON) {
char *annotext = msShapeGetLabelAnnotation(layer,shape,layer->class[c]->labels[l]);
if(UNLIKELY(MS_FAILURE == msDrawLabel(map, image, *point, annotext, layer->class[c]->labels[l], layer->scalefactor))) {
return MS_FAILURE;
goto end;
}
}
}
}
}
}
return MS_SUCCESS;
ret = MS_SUCCESS;

end:
if( map->gt.rotation_angle )
{
for (l = 0; l < layer->class[c]->numlabels; l++)
{
if( layer->class[c]->labels[l]->angle != 0 )
layer->class[c]->labels[l]->angle += map->gt.rotation_angle;
}

for (s = 0; s < layer->class[c]->numstyles; s++)
{
if( layer->class[c]->styles[s]->angle != 0 )
layer->class[c]->styles[s]->angle += map->gt.rotation_angle;
}
}

return ret;
}

int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj *shape,
Binary file not shown.
@@ -0,0 +1,150 @@
# RUN_PARMS: symbolrot.png [SHP2IMG] -m [MAPFILE] -i png -o [RESULT]

#
# Test support for rotating symbols with their map.
#
# REQUIRES: OUTPUT=PNG SUPPORTS=PROJ
#
MAP
NAME "test"

EXTENT 520000 140000 540000 160000
UNITS METERS

IMAGECOLOR 255 255 255
STATUS ON
SIZE 500 500

ANGLE 45

SYMBOL
NAME "v-line"
TYPE vector
FILLED false
POINTS
0 0
5 10
10 0
END # POINTS
END # SYMBOL

IMAGETYPE png

PROJECTION
"init=epsg:21781"
END

LAYER
NAME line_layer
STATUS DEFAULT
TYPE LINE
PROJECTION
"init=epsg:21781"
END

FEATURE
WKT "LINESTRING(530000 100000, 530000 200000)"
END

CLASS
STYLE
WIDTH 1
COLOR 0 0 0
PATTERN 10 3 10 3 END
END
END
END

LAYER
NAME pt_exactly_same_value_as_map_rotation_red
STATUS DEFAULT
TYPE POINT
PROJECTION
"init=epsg:21781"
END

FEATURE
WKT "POINT(530000 151000)"
END

CLASS
STYLE
SYMBOL "v-line"
WIDTH 5
COLOR 0 0 255
OUTLINECOLOR 32 32 32
ANGLE 45
END
END
END

LAYER
NAME pt_almost_zero_rotation_yellow
STATUS DEFAULT
TYPE POINT
PROJECTION
"init=epsg:21781"
END

FEATURE
WKT "POINT(530000 148000)"
END

CLASS
STYLE
SYMBOL "v-line"
WIDTH 5
COLOR 255 255 0
OUTLINECOLOR 32 32 32
ANGLE 0.0001
END
END
END

LAYER
NAME pt_other_value_as_map_rotation_green
STATUS DEFAULT
TYPE POINT
PROJECTION
"init=epsg:21781"
END

FEATURE
WKT "POINT(530000 149500)"
END

CLASS
STYLE
SYMBOL "v-line"
WIDTH 5
COLOR 0 255 0
OUTLINECOLOR 32 32 32
ANGLE 22.5
END
END
END

LAYER
NAME pt_does_not_follow_map_rotation_blue
STATUS DEFAULT
TYPE POINT
PROJECTION
"init=epsg:21781"
END

FEATURE
WKT "POINT(530000 145000)"
END

CLASS
STYLE
SYMBOL "v-line"
WIDTH 5
COLOR 255 0 0
OUTLINECOLOR 32 32 32
END
END
END

END

0 comments on commit 91d53be

Please sign in to comment.