Opened 21 years ago

Closed 21 years ago

Last modified 21 years ago

#272 closed defect (fixed)

New msMapCopy function

Reported by: wzhang@… Owned by: sgillies@…
Priority: high Milestone:
Component: MapServer C Library Version: 4.0
Severity: normal Keywords:
Cc:

Description

I noticed that the map object is always created by loading mapfile in 
msLoadMap() function. I wonder in the new version of MapServer if you can add 
something like msMapCopy() function. I feel if we can do this

	mapObj *srcmap = NULL;
	mapObj *newmap = NULL;

	srcmap = msLoadMap("C:\\test.map", NULL);

	while ( maprequest == TRUE)
	{
		newmap = msMapCopy(srcmap);

		/* ***********************************

	          use newmap object to generate map image

		************************************/
		
 		msFreeMap(newmap);
	}

It will be much more efficient than loading mapfile every time.

Attachments (1)

testCopyMap.py (3.9 KB ) - added by sgillies@… 21 years ago.
Unit testing script

Download all attachments as: .zip

Change History (9)

comment:1 by sgillies@…, 21 years ago

Status: newassigned
An msMapCopy function would be very useful to me as well.
I'll accept this request, if that's OK with you, Steve.

--
Sean
sgillies@frii.com

comment:2 by sgillies@…, 21 years ago

Owner: changed from sdlime to sgillies@…
Status: assignednew
Oh, forgot to reassign to myself.

--
Sean
sgillies@frii.com

by sgillies@…, 21 years ago

Attachment: testCopyMap.py added

Unit testing script

comment:3 by sgillies@…, 21 years ago

Status: newassigned
Have spent some days writing functions to copy mapping objects.  There's
enough code (~ 700 lines) that I'm reluctant to add it to mapfile.c, so
I've created a mapcopy.c file.

I started by cutting all the structure declarations from map.h, plus some
from maptemplate.h, mapoutput.h and using these as skeletons for functions.
For example, starting with the structure {...} classObj, I create an
msCopyClass() function that strdups all char * attributes, memcpys all the
other simple types, and calls msCopy*() functions for class attributes
(style, color, etc.).  Tedious!

Status: msCopyMap() will make a valid map copy.  All layers, classes are
present.  We are not copying any caches or items.  Copy of hash tables is
not yet implemented, so metadata is not ready yet.

I am attaching the Python test script which enumerates the unit tests I've
done.  Even for someone new to Python, should be clear what I've tested.




comment:4 by dmorissette, 21 years ago

Cc: assefa@… morissette@… added

comment:5 by assefa, 21 years ago

I started using the mapcopy code yesterday to do layer copying. I am running 
into problems related to the metadata copy. I know it is not yet implemented. If 
you do not see any inconvinience or are not working on it, I would like to 
implement the code in msCopyHashTable. The code would be :

  int msCopyHashTable(hashTableObj dst, hashTableObj src)
  {
    for (i=0;i<MS_HASHSIZE; i++) {
    if (src[i] != NULL) {
      for (tp=src[i]; tp!=NULL; tp=tp->next)
         msInsertHashTable(dst, tp->key, tp->data);
	
    }
  }

comment:6 by sgillies@…, 21 years ago

I'm not working on the hash tables currently, so yes, please do.

S.


comment:7 by sgillies@…, 21 years ago

Resolution: fixed
Status: assignedclosed
Looks like assefa is using msCopyLayer in php_mapscript.c,
and I've committed to mapscript.i a tested clone() method 
using msCopyMap() that extends mapObj and is used like this
Python example:

   map1 = mapObj(mapfile)
   map2 = map1.clone()

I think the conotation of 'clone' is better than 'copy'.
Our new map is not an _exact_ copy because msCopyMap() only
copies the properties that would be defined in a mapfile,
the genes if you will.  Caches are not (currently) copied.

As the clone() method is working well for me, and I haven't
heard otherwise from assefa about msCopyLayer in php, I'm
going to call this feature request resolved as fixed.
If/when bugs are found, we'll create a new issue.
 

comment:8 by dmorissette, 21 years ago

For the record, I added the map->clone() method to PHP MapScript as well.
I also fixed a few build problems and added error checking in the clone() method 
in mapscript.i so that it returns NULL if msCopyMap() doesn't return MS_SUCCESS.
Note: See TracTickets for help on using tickets.