SWIGMapscript: processLegendTemplate throws error

Umberto Nicoletti unicoletti at PROMETEO.IT
Tue Dec 14 23:49:27 PST 2004


On Mon, 2004-12-13 at 10:16 -0700, Sean Gillies wrote:
> Can you not try and catch, and pass in the case of an exception?
> This is essentially what happens with shp2pdf.
>

I have modified the DrawMap example as follows:

mapObj map = new mapObj(args[0]);
    map.getImagecolor().setRGB(153, 153, 204);
    styleObj st = map.getLayer(1).getClass(0).getStyle(0);
    st.getColor().setHex("#000000");
    outputFormatObj pdf=new outputFormatObj("pdf","pdf");
    //outputFormatObj flash=new outputFormatObj("SWF","swf");
    imageObj img=null;
    try {
    map.setOutputFormat(pdf);
    //map.setOutputFormat(flash);
    //map.getScalebar().setStatus(mapscript.MS_OFF);
    System.out.println("Scalebar status:
"+map.getScalebar().getStatus());
    img = map.draw();
    System.out.println("The map will be drawn to:"+args[1]);
    } catch(Throwable e) {
    }
    img.save(args[1], map);

but, as I suspected it does not work because draw() does not return and
img is therefore null.
I attach a patch for this PDF specific error. Let me know if you like it
or if we should work it out differently.

Regards,
Umberto


> I still have a hard time believing that the templating can work.
> The mapscript function expects char** and Andreas is passing a
> Java array of strings.  Does Swig-java translate these
> automatically?
>
> The templating functions certainly do not work for Perl and Python.
>
> Sean
>
> On Dec 13, 2004, at 10:08 AM, Umberto Nicoletti wrote:
>
> > Sean,
> > the problem is in maphash.c around line 126. There you can see that
> > mapserver sets an error because the user tried to free an already null
> > hashTable and this causes Java mapscript to bail out with an exception,
> > while in earlier versions the error was ignored.
> >
> > This is a consequence of my patch for handling mapserver errors as
> > exceptions in java mapscript. In fact I have faced a similar error
> > while
> > trying to produce pdf output from Java mapscript. The same map file was
> > working fine with shp2pdf because shp2pdf was just ignoring the error.
> > I believe that my patch, while trying to prevent the java virtual
> > machine from crashing altogether, ends up throwing exceptions when
> > instead it is dealing with a warning (even tough it is an error in
> > mapserver terms).
> > What we need is probably some fine tuning for situations like this...
> >
> > Apologies to Andreas if this is not helping you, but I am just trying
> > to
> > generalize your problem so that we can work out a (hopefully) better
> > solution.
> >
> > Please let me know what you think about this,
> > Umberto
> >
> >
> >
> > On Mon, 2004-12-13 at 07:23 -0700, Sean Gillies wrote:
> >> On Dec 13, 2004, at 6:14 AM, GeoIT wrote:
> >>
> >>> Dear experts,
> >>> I used mapObj.processLegendTemplate successfully with mapserver 4.0.
> >>> =
> >>> Now I
> >>> try to upgrade to version 440 and get the following error using this
> >>> =
> >>> method:
> >>>
> >>> Java.lang.UnknownError: Can't free NULL table
> >>>
> >>> Any ideas ?
> >>>
> >>> The code is:
> >>>         public String getProcessedLegendTemplate(mapObj mapObject) {
> >>>                 String[] names =3D {"img", "legend", "scalebar", =
> >>> "ref"};
> >>>                 String[] values =3D {"", "", "", ""};
> >>>                 int numItems =3D 4;
> >>>                 return mapObject.processLegendTemplate(names,
> >>> values,numItems);
> >>>         }
> >>>
> >>>
> >>> regards
> >>> Andreas Paukner-Ruzicka
> >>>
> >>
> >> Andreas,
> >>
> >> I am very surprised that you could call processLegendTemplate
> >> with MapServer 4.0.  It was my understanding that Java mapscript
> >> was broken at that time.
> >>
> >> Please enter a report into the MapServer Bugzilla under the
> >> SWIG mapscript component and I will investigate and try to fix
> >> it before the next release.
> >>
> >> cheers,
> >> Sean
> >>
> >> --
> >> Sean Gillies
> >> sgillies at frii dot com
> >> http://users.frii.com/sgillies
> > --
> > Umberto Nicoletti <unicoletti at prometeo.it>
> > Prometeo SRL
> >
--
Umberto Nicoletti <unicoletti at prometeo.it>
Prometeo SRL
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-pdf-bitmapfonts.diff
Type: text/x-patch
Size: 731 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20041215/16dee03c/attachment.bin>


More information about the MapServer-users mailing list