-
-
Save iljya/e67a2a245c6968e685c11498a8361fe0 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?> | |
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100pt" height="100pt" viewBox="0 0 100 100" version="1.1"> | |
<g id="surface2"> | |
<rect x="0" y="0" width="100" height="100" style="fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;"/> | |
<path style="fill-rule:nonzero;fill:rgb(0%,64.313728%,30.19608%);fill-opacity:1;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.249917 0.248289 L 4.959269 0.248289 L 4.959269 4.961711 L 0.249917 4.961711 Z M 0.249917 0.248289 " transform="matrix(0.959693,0,0,0.959693,40.1,50)"/> | |
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;" d="M 40.101562 49.5 C 40.101562 50.167969 39.101562 50.167969 39.101562 49.5 C 39.101562 48.832031 40.101562 48.832031 40.101562 49.5 "/> | |
<path style="fill-rule:nonzero;fill:rgb(0%,64.313728%,30.19608%);fill-opacity:1;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.248289 0.248289 L 4.961711 0.248289 L 4.961711 4.961711 L 0.248289 4.961711 Z M 0.248289 0.248289 " transform="matrix(0.959693,0,0,0.959693,47.5,47.5)"/> | |
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;" d="M 50 49.5 C 50 50.167969 49 50.167969 49 49.5 C 49 48.832031 50 48.832031 50 49.5 "/> | |
<path style="fill-rule:nonzero;fill:rgb(0%,64.313728%,30.19608%);fill-opacity:1;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.250731 0.248289 L 4.960083 0.248289 L 4.960083 4.961711 L 0.250731 4.961711 Z M 0.250731 0.248289 " transform="matrix(0.959693,0,0,0.959693,54.9,45)"/> | |
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;" d="M 59.898438 49.5 C 59.898438 50.167969 58.898438 50.167969 58.898438 49.5 C 58.898438 48.832031 59.898438 48.832031 59.898438 49.5 "/> | |
</g> | |
</svg> |
MAP | |
NAME SVG_ICON_ANCHORPOINT_TEST | |
STATUS ON | |
SIZE 100 100 | |
EXTENT 0 0 0.001 0.001 | |
IMAGECOLOR 255 255 255 | |
IMAGETYPE svg | |
CONFIG "MS_ERRORFILE" "stderr" | |
SYMBOL | |
NAME "square_0_0" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 0 0 | |
END | |
SYMBOL | |
NAME "square_05_05" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 0.5 0.5 | |
END | |
SYMBOL | |
NAME "square_1_1" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 1 1 | |
END | |
SYMBOL | |
NAME "DEBUG" | |
TYPE ellipse | |
FILLED true | |
POINTS | |
1 1 | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0004 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_0_0" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0005 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_05_05" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0006 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_1_1" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
END |
MapServer version 7.4.3 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS SUPPORTS=PBF INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
Also doesn't work with 7.6.2.
MapServer version 7.6.2 OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WFS_SERVER SUPPORTS=WCS_SERVER SUPPORTS=FASTCGI SUPPORTS=GEOS SUPPORTS=POINT_Z_M INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
I found the issue! The SVG symbol (square.svg) does not have a width/height set. If the width/height is set, the symbol is correctly anchored at the set anchorpoints.
The reason the results are so strange seems to be related to the fractional maxx/maxy set in the viewbox: they are apparently being cast to ints! I verified this by adding a print statement in mapcairo.c::msPreloadSVGSymbol() [0]:
rsvg_handle_get_dimensions_sub (cache->svgc, &dim, NULL);
symbol->sizex = dim.width;
symbol->sizey = dim.height;
fprintf( stderr, "width: %d height: %d\n", dim.width, dim.height);
The dimensions returned by rsvg_handle_get_dimensions_sub(...) are always ints [1].
[0] https://github.com/MapServer/MapServer/blob/main/mapcairo.c#L1000
[1] https://github.com/ImageMagick/librsvg/blob/main/rsvg-base.c#L1458
Thanks for all of this research. Added to docs as a note (MapServer/MapServer-documentation#446)
SVG symbols, SVG output, and Anchorpoints
Note the strange output produced by the above map file. It has:
Note how the anchor points are not where they should be (see map.svg above). You have to zoom in to see properly.
![svg.map](https://raw.githubusercontent.com/gist/iljya/e67a2a245c6968e685c11498a8361fe0/raw/dbaa0fe49f87c112e99c31b0700a8fe00a761de4/map.svg)
I use this command to render the map:
shp2img -o map.svg -m svg.map
If I change the output type to png, I get the expected result, with the symbols anchored at the correct point:
It is possible that this is related to these issues, but I'm not sure:
MapServer/MapServer#5593
https://trac.osgeo.org/mapserver/ticket/4184