[mapserver-users] labels for pie|bar charts

Nicol Hermann mapserver at geoworld.de
Thu Aug 1 10:33:27 PDT 2019


Hello Steve,

you are right. With older versions of Mapserver I used 2 layers.
One for the chart (type=chart) and the other one to do the labeling
(type=annotation).
I used PHP Mapscript at that time. See the code snippet for the
annotation layer below. It uses the same data source like the chartlayer. 

$layer = ms_newLayerObj($Map);
$layer -> set('status', MS_ON);
$layer -> set('labelcache', MS_ON);
$layer -> set('type', MS_LAYER_ANNOTATION );
$layer -> set('data', $datapath);
$layer -> set('status', MS_ON);
$poClass = ms_newClassObj($layer);
$poClass-> set("name", "Beschrifung " );
$felder= '(';
foreach( $chartLayer['fieldlist'] as $feld ){
   $felder .= sprintf('%s = [%s]-', $feld, $feld); 
}
$felder .=sprintf(')');
$poClass->settext($layer, "$felder");
$poClass-> label -> set('font', "arial");
$poClass-> label -> set('type', MS_TRUETYPE);
$poClass-> label -> set('size', 8);
$poClass-> label -> set('antialias', MS_TRUE);
$poClass-> label -> color -> setRGB ( 0, 0, 0 );
$poClass-> label -> set ('wrap', 0x2d); // use '-' to do a line break
$poClass-> label ->set('position', MS_AUTO);
$poClass-> label ->set('partials', MS_FALSE);
$poClass-> label ->backgroundcolor->setRGB('240','240','240');

Unfortunately this approach do not work anymore as the annotation type
is not longer supported.

The MapFile which I am trying currently looks like this:

  LAYER
    DATA
"/home/nicol/public_html/geoworld/gw2_1und1/data/brd/media.shp"
    LABELITEM "NAME"
    NAME "Staedtecharts"
    PROJECTION
      "init=epsg:4326"
    END # PROJECTION
    STATUS DEFAULT 
    TYPE CHART
    # PROCESSING "CHART_SIZE_RANGE=bevzahl"
    # PROCESSING "CHART_SIZE=130" # Fixe Groesse
    PROCESSING "CHART_TYPE=pie"  # pie, bar
    PROCESSING "CHART_SIZE_RANGE = itemname minsize maxsize minval
maxval exponent"
    PROCESSING "CHART_SIZE_RANGE=bevzahl 30 300 100000 2000000"
    LABELITEM "NAME"
    UNITS DD 
    CLASS
      NAME "Maennlich"
      TEXT 'Hallo'
      LABEL
        FONT "arial"
        SIZE 30
        COLOR 255 0 0
        ENCODING "UTF-8"
        MINFEATURESIZE AUTO
        OFFSET 0 0
        POSITION AUTO
        SHADOWSIZE 1 1
      END # LABEL
      STYLE
        COLOR 192 192 192
        OUTLINECOLOR 0 0 0
        SIZE [mann]
      END # STYLE
    END # CLASS
    CLASS
      NAME "Weiblich"
      STYLE
        SIZE [frau]
        COLOR 255 255 0
        OUTLINECOLOR 0 0 0
      END
    END
  END # LAYER


My hope was that the chart type now also takes care of the labeling.

Any idea how to realize the labeling for the individual slices now?

Thanks
Nicol


Am Donnerstag, den 01.08.2019, 14:34 +0000 schrieb Lime, Steve D
(MNIT):
> Hi Nicol: Do you you have a sample mapfile that showed your approach?
> Since CHART and ANNOTATION are both layer types that implies multiple
> layers. --Steve
> 
> -----Original Message-----
> From: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org
> ] On Behalf Of Nicol Hermann
> Sent: Wednesday, July 31, 2019 2:52 PM
> To: mapserver-users at lists.osgeo.org
> Subject: [mapserver-users] labels for pie|bar charts
> 
> This message may be from an external email source.
> Do not select links or open attachments unless verified. Report all
> suspicious emails to Minnesota IT Services Security Operations
> Center.
> 
> 
> 
> Hello,
> 
> I am trying to understand how labeling/annotation with layer type
> 'chart' for the individual slices e.g. of a PIE/BAR chart would work
> (
> https://gcc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmapserver.org%2Foutput%2Fdynamic_charting.html&data=02%7C01%7Csteve.lime%40state.mn.us%7C6232218953ac431b0e4c08d715f1180f%7Ceb14b04624c445198f26b89c2159828c%7C0%7C0%7C637001997557352724&sdata=ZFkZ8QsEuUaAGFyFIxfZjWK9XR8QeyDBv390t2p%2F23o%3D&reserved=0).
> I have tried to set a LABELITEM on layer level, a LABEL block within
> the CLASS section, a TEXT property in the CLASS block but none of my
> attempts show any labels.
> In earlier versions of Mapserver I have used the ANNOTATION layer
> type
> to get labels but this type is now deprecated for 7.x versions.
> Any ideas?
> Thank you very much.
> 
> Nicol
> 
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> https://gcc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fmapserver-users&data=02%7C01%7Csteve.lime%40state.mn.us%7C6232218953ac431b0e4c08d715f1180f%7Ceb14b04624c445198f26b89c2159828c%7C0%7C0%7C637001997557352724&sdata=dceZhhKxeZLbr717UmidG4ujIcnThwm7mlU5bIoGfBQ%3D&reserved=0



More information about the mapserver-users mailing list