[Mapserver-users] Problems with PerlMapscript 3.7 Syntax

Sean Gillies sgillies@frii.com
Thu, 1 May 2003 13:02:30 -0600


I can't speak for the developer who committed the change, but
it appears to me that the developer wants to promote some
degree of uniformity across object methods.  The mapObj has a
save() method that outputs to disk, and it seems natural that
the extension to imageObj that outputs to disk should also be
named 'save'.

Is not at all productive?  If all mapping objects had a save()
method, one could reliably save an arbitrary object without
having to do any type checking, or looking up whether you have
to use 'saveMap' or 'saveImage' or 'saveSymbol'.  Objects
save themselves using methods uniformly named 'save'.  This
promotes development of more modular and reusable code.  To me,
that is productive.

I don't deny that refactoring scripts to work with the newer
MapScript module will have a cost.  One way to enable a script
to work with 3.6 mapscript and 4.0 mapscript is to use
try/catch.  This example in Python:

try:
	img.saveImage('foo.png')
except AttributeError:
	img.save('foo.png')

With Perl it's a bit uglier since you have to eval() and trap
errors, but it's the same idea.

Sean

On Thursday, May 1, 2003, at 12:23  PM, Joe Bussell wrote:

> Is it just me, or does this function renaming seem unnecesary?  I  
> fully understand fixing up the internal code.  I do not accept that  
> making function call naming changes from distinctly articulated names  
> like "saveImage()" to its ambiguously named alternative "save()" is at  
> all productive.
>
> Could you explain to me the reason that this particular name was  
> changed?  Can we agree on a stable interface and concentrate on the  
> real buisiness of the day?
>
> Cordially,
>
> Joe Bussell
> On Time Systems
> www.trafficdodger.com
>
>
> Sean Gillies wrote:
>> Babak,
>> The function you're looking for is save(), not saveImage().
>> To find out what functions are current in MapScript, you need to
>> look in the mapscript.i file.  The documentation is far behind
>> development.
>> To find all symbols in a package, do something like what's
>> illustrated on page 281 of Programming Perl, 2nd edition:
>> foreach $symname (sort keys %main::) {
>>     ...
>> }
>> Hope this helps,
>> Sean
>> On Thursday, May 1, 2003, at 08:34  AM, Babak Toloue Tehrani wrote:
>>> Hello,
>>>
>>> I have still problems with perlmapscript 3.7. The demo below with the
>>> syntax of perlmapscript 3.6 is working very fine on my system.  
>>> shp2img
>>> is also working for the mapfile below.
>>>
>>>> From the WIKI MigrationGuide I Take the syntax for saveImage():
>>>
>>>
>>> $img->saveImage('test37.png');
>>>
>>> and get following output:
>>>
>>> Can't locate auto/mapscript/imageObj/saveImage.al in @INC (@INC
>>> contains: /usr/lib/perl5/5.8.0/i586-linux-thread-multi
>>> /usr/lib/perl5/5.8.0
>>> /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi
>>> /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at  
>>> test37.pl
>>> line 7
>>>
>>> Then I looked for the string saveImage in the mapscript.pm module and
>>> found the function msSaveImage who brings me following output:
>>>
>>> Usage: msSaveImage(map,img,filename); at test37.pl line 7.
>>>
>>> I tried: $map->msSaveImage($map,$img,'test37');
>>>
>>> and got same errormessage as before. Then I tried to set the set the
>>> ImageType with:
>>>
>>> map->setImageType("png") or die('Unable to setImageType.');
>>>
>>> and see that it failed. Here the script and the mapfile:
>>>
>>> (Does someone now a tool to extract from a perl Module  
>>> (mapscript.pm) a
>>> list of all Classes/Objects, Members and Methods?)
>>>
>>> Thanks a lot,
>>>
>>> Babak
>>>
>>> ===================================================================== 
>>> == ===
>>> #!/usr/bin/perl -w
>>> use mapscript;
>>> use strict;
>>>
>>> my $map = new mapscript::mapObj("data/demo37.map") or die('Unable to
>>> OPEN mapfile.');
>>> $map->setImageType("png") or die('Unable to setImageType.');
>>> my $img = $map->draw() or die('Unable to DRAW mapfile.');
>>> $map->msSaveImage($map,$img,'test37');
>>> $img->free();
>>> --------------------------------------------------------------------- 
>>> -- ---
>>> NAME DEMO37
>>> STATUS ON
>>> SIZE 600 450
>>> EXTENT 5.3 55.5 15.5 46.9
>>> UNITS METERS
>>> SHAPEPATH "data"
>>> IMAGECOLOR 255 255 255
>>>
>>> OUTPUTFORMAT
>>>   NAME png
>>>   DRIVER "GD/PNG"
>>>   MIMETYPE "image/png"
>>>   IMAGEMODE PC256
>>>   EXTENSION "png"
>>> END
>>>
>>> LAYER
>>>   NAME TESTLAYER
>>>   TYPE POLYGON
>>>   STATUS DEFAULT
>>>   DATA lnd01dd.shp
>>>   CLASS
>>>       NAME TESTCLASS
>>>       SYMBOL 0
>>>       COLOR 195 195 195
>>>       OUTLINECOLOR 102 102 102
>>>   END
>>> END
>>> END
>>>
>>>
>> -- 
>> Sean Gillies
>> sgillies at frii dot com
>> http://www.frii.com/~sgillies
>> _______________________________________________
>> Mapserver-users mailing list
>> Mapserver-users@lists.gis.umn.edu
>> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
>

_______________________________________________
Mapserver-users mailing list
Mapserver-users@lists.gis.umn.edu
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users