[Mapserver-dev] New msCloneLayerObj() function

Sean Gillies sgillies at frii.com
Mon Feb 17 14:40:09 EST 2003


On Monday, February 17, 2003, at 11:54  AM, Daniel Morissette wrote:

> Steve,
>
> We are thinking of adding a new function to mapfile.c (and MapScript) 
> to
> initialize a new layer by creating a clone of an existing layer.  This
> would allow us to easily make copies of layers inside a single mapObj,
> or to copy layers from one mapObj to another.
>
> The C function prototype would be:
>
>   int msCloneLayerObj(mapObj *target_map, layerObj *src_layer);
>
> which would create a new layer inside target_map which is a copy of
> src_layer.
>
> In PHP MapScript, the function ms_newMapObj() would be extended to take
> an optional second argument that would be the layer to clone:
>
>  layerObj ms_newLayerObj(mapObj target_map [,layerObj layer_to_clone])
>
> I don't think SWIG allows for optional arguments like we use in PHP, so
> we would have to expose a separate function for msCloneLayerObj() in 
> the
> SWIG'd MapScript.
>
> Is that OK with you?  Any suggestions, comments?
>
> Daniel
> -- 
>
Daniel,

There was a request in Bugzilla for a msCopyMap() function that I
accepted as my first contribution to MapServer.  I've nearly finished
it and it has what you are looking for.

int msCopyLayer(layerObj *dst, layerObj *src, mapObj *map);

I picked the argument order to resemble memcpy().  The mapObj is
needed as a final argument because the destination layer needs a
pointer to it's parent map.  It's intended to copy layers
between maps, but could copy within a map as well.

In mapscript.i, I was planning to extend layerObj with a copy()
function which would be used like this Python example:

map1 = mapObj(mapfile) # contains a layer
lay1 = map1.getlayer(0)
lay2 = layerObj(map1)
lay2 = lay1.copy()

I'm reluctant to commit my code into mapfile.c since there's ~700 lines
(including functions to copy other map objects), so I was thinking
of a new file?  mapcopy.c perhaps?  I could commit this file to CVS if
you want to take a look.

Speaking of new features -- I've been wishing for functions to remove
layers and classes from mapObjs.  I thought I might move on to that
next after finishing the ms*Copy stuff.

cheers,
Sean
--
Sean Gillies
sgillies at frii.com
http://www.frii.com/~sgillies




More information about the mapserver-dev mailing list