[mapserver-users] dynamic layer with color depending of an expression (under PHP) (FWD)

teb teb at mallit.fr.umn.edu
Mon Oct 29 13:09:47 EST 2001


------------- Begin Forwarded Message -------------

From: "CATHIGNOL, Frederic" <Frederic.CATHIGNOL at astrium-space.com>
To: "'mapserver-info at lists.gis.umn.edu'" <mapserver-info at lists.gis.umn.edu>
Subject: dynamic layer with color depending of an expression (under PHP)
Date: Mon, 29 Oct 2001 10:53:50 +0100
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by mallit.fr.umn.edu id 
DAA25417

Hello;

2nd bid !
In fact I think that my first mail has not been practical to read with too
much information. I try to re-ask my question with a new look ! :

I have a problem to declare dynamic layer with color depending of expression
under php mapscript see below.
Please could you help me with an example...

I have tested first with a .map file : It works (you will see the code here
after) and then with a PHP script wich does not work (code is given after).
At execution of the script, it does not display the layer and if I want to
redraw the page, it has an error : (I think that mapserver crashed, and I
need to restart the apache server whith mapserver).
Warning: MapServer Error in msLoadMap(): (é):(0) in c:\my
program\easyphp\www\projet1\pactes-ess\htdocs\mapserv.phtml on line 60
(Rmq line 60 : $gpoMap = ms_newMapObj("pactes-def.map");   )
Fatal error: Failed to open map file pactes-def.map in c:\my
program\easyphp\www\projet1\pactes-ess\htdocs\mapserv.phtml on line 60

If you are curious, you have also the object results (in annexes) for both
cases (.map, and php script).

I) .MAP CODE :
LAYER
  NAME numdep
  STATUS ON
  DATA LIMITE_ADMINISTRATIVE
  TYPE LINE
  CLASSITEM "NATURE"
  CLASS
    EXPRESSION "Limite côtière"
    COLOR 255 0 0 # dummy color
  END
  CLASS
    EXPRESSION "Limite de département"
    COLOR 0 255 0 # dummy color
  END
  CLASS
    EXPRESSION "Limite de région"
    COLOR 0 0 255 # dummy color
  END
  CLASS
    EXPRESSION "Limite frontalière"
    COLOR 0 255 255 # dummy color
  END
END


II) PHP script CODE
$layer = ms_newLayerObj($gpoMap);
$layer->set("name","LIMITE_ADMINISTRATIVE");
$layer->set("type", MS_LAYER_LINE);                     
$layer->set("data", "lay2");
$layer->setMetaData("DESCRIPTION","Limites administratives des
départements");
$layer->set("classitem", "NATURE");
$fredclass = ms_newClassObj($layer);
$fredclass->set("name","lay2o001");
$fredclass->setexpression("Limite de département");
$fredclass->set("color",10);       /* Corresponding to a new color :
128,128,128 */
$fredclass = ms_newClassObj($layer);
$fredclass->set("name","lay2o002");
$fredclass->setexpression("Limite côtière");
$fredclass->set("color",11);       /* Corresponding to a new color :
64,0,128 */
$fredclass = ms_newClassObj($layer);
$fredclass->set("name","lay2o003");
$fredclass->setexpression("Frontière internationale");
$fredclass->set("color",12);       /* Corresponding to a new color :
128,128,64 */
$fredclass = ms_newClassObj($layer);
$fredclass->set("name","lay2o004");
$fredclass->setexpression("Limite de région");
$fredclass->set("color",13);       /* Corresponding to a new color :
64,128,128 */


MANY THANKS FOR YOUR HELP

F.CATHIGNOL

-------------------------------------------------------------------------

ANNEXE I :

The result object after execution is (by a print_r() of the variable)  with
a .MAP file:
layer Object
(
    [_handle_] => Resource id #28
    [_map_handle_] => Resource id #8
    [numclasses] => 4
    [index] => 1
    [status] => 1
    [classitem] => NATURE
    [name] => numdep
    [group] => 
    [data] => LIMITE_ADMINISTRATIVE
    [type] => 1
    [tolerance] => 3
    [toleranceunits] => 6
    [symbolscale] => -1
    [minscale] => -1
    [maxscale] => -1
    [labelminscale] => -1
    [labelmaxscale] => -1
    [maxfeatures] => -1
    [offsite] => -1
    [transform] => 1
    [labelcache] => 1
    [postlabelcache] => 0
    [labelitem] => 
    [labelsizeitem] => 
    [labelangleitem] => 
    [tileitem] => location
    [tileindex] => 
    [header] => 
    [footer] => 
    [connection] => 
    [connectiontype] => 1
    [filteritem] => 
)
class Object
(
    [_handle_] => Resource id #29
    [_layer_handle_] => Resource id #28
    [name] => 
    [type] => 1
    [color] => 4
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #30
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #31
    [_layer_handle_] => Resource id #28
    [name] => 
    [type] => 1
    [color] => 5
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #32
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #33
    [_layer_handle_] => Resource id #28
    [name] => 
    [type] => 1
    [color] => 6
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #34
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #35
    [_layer_handle_] => Resource id #28
    [name] => 
    [type] => 1
    [color] => 7
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #36
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)



ANNEXE II : (result with PHP script)

At execution it gives with a print_r of the objects :
layer Object
(
    [_handle_] => Resource id #70
    [_map_handle_] => Resource id #8
    [numclasses] => 4
    [index] => 5
    [status] => 1
    [classitem] => NATURE
    [name] => lay2
    [group] => 
    [data] => LIMITE_ADMINISTRATIVE
    [type] => 1
    [tolerance] => 3
    [toleranceunits] => 6
    [symbolscale] => -1
    [minscale] => -1
    [maxscale] => -1
    [labelminscale] => -1
    [labelmaxscale] => -1
    [maxfeatures] => -1
    [offsite] => -1
    [transform] => 1
    [labelcache] => 1
    [postlabelcache] => 0
    [labelitem] => 
    [labelsizeitem] => 
    [labelangleitem] => 
    [tileitem] => location
    [tileindex] => 
    [header] => 
    [footer] => 
    [connection] => 
    [connectiontype] => 1
    [filteritem] => 
)
class Object
(
    [_handle_] => Resource id #71
    [_layer_handle_] => Resource id #70
    [name] => lay2o001
    [type] => 1
    [color] => 10
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #72
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #73
    [_layer_handle_] => Resource id #70
    [name] => lay2o002
    [type] => 1
    [color] => 11
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #74
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #75
    [_layer_handle_] => Resource id #70
    [name] => lay2o003
    [type] => 1
    [color] => 12
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #76
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
class Object
(
    [_handle_] => Resource id #77
    [_layer_handle_] => Resource id #70
    [name] => lay2o004
    [type] => 1
    [color] => 13
    [backgroundcolor] => -1
    [outlinecolor] => -1
    [overlaycolor] => -1
    [overlaybackgroundcolor] => -1
    [overlayoutlinecolor] => -1
    [symbol] => 0
    [size] => 1
    [minsize] => 1
    [maxsize] => 100
    [symbolname] => 
    [overlaysymbol] => -1
    [overlaysize] => 1
    [overlayminsize] => 1
    [overlaymaxsize] => 100
    [overlaysymbolname] => 
    [template] => 
    [label] => label Object
        (
            [_handle_] => Resource id #78
            [font] => 
            [type] => 1
            [color] => 1
            [outlinecolor] => -1
            [shadowcolor] => -1
            [shadowsizex] => 1
            [shadowsizey] => 1
            [backgroundcolor] => -1
            [backgroundshadowcolor] => -1
            [backgroundshadowsizex] => 1
            [backgroundshadowsizey] => 1
            [size] => -1
            [minsize] => 4
            [maxsize] => 256
            [position] => 8
            [offsetx] => 0
            [offsety] => 0
            [angle] => 0
            [autoangle] => 0
            [buffer] => 0
            [antialias] => -1
            [wrap] => 10
            [minfeaturesize] => -1
            [autominfeaturesize] => 0
            [mindistance] => -1
            [partials] => 1
            [force] => 0
        )

)
As you can see it is nearly  identical (colors changed)...






------------- End Forwarded Message -------------





More information about the mapserver-users mailing list