Opened 20 years ago

Closed 20 years ago

Last modified 20 years ago

#724 closed defect (fixed)

OUTPUTFORMAT (float32) fails from MapScript

Reported by: warmerdam Owned by: warmerdam
Priority: high Milestone: 4.4 release
Component: MapScript-SWIG Version: 4.2
Severity: normal Keywords:
Cc: sgillies@…, lfilak@…

Description

Hi,

I'm trying to produce a 32-bit floating point geotiff as output from a
Python-Mapscript program. A similar thing used to work with the CGI mapserv
program with the OUTPUTFORMAT set as following:

OUTPUTFORMAT
  NAME FGTiff
  DRIVER "GDAL/GTiff"
  MIMETYPE "image/tiff"
  IMAGEMODE FLOAT32
  EXTENSION "tif"
END

However, I need to do a similar thing in mapscript and I run into a segmentation
fault. The top of the stacktrace looks like:
#0  0x4073c39d in msImageInitGD (image=0x823f700, background=0x40d72ea4)
   at mapgd.c:137
#1  0x407369bc in msDrawMap (map=0x40d4a008) at mapdraw.c:142
#2  0x406c19ea in mapObj_draw (self=0x0) at mapscript_wrap.c:2403
#3  0x406e41ac in _wrap_mapObj_draw (self=0x0, args=0x0)
   at mapscript_wrap.c:18792
#4  0x080f3469 in PyCFunction_Call (func=0x405d198c, arg=0x407a7aec, kw=0x0)
   at Objects/methodobject.c:108

My code to setup the output format object is as follows:

formatObj = mapscript.outputFormatObj("GDAL/GTiff")
formatObj.name = "fgtiff"
formatObj.imagemode = mapscript.MS_IMAGEMODE_FLOAT32
formatObj.mimetype = "image/tiff"
formatObj.extension = "tif"
mapObj.outputformat = formatObj

Any ideas why this might be happening or how to fix it?

Many thanks,

- John

Change History (10)

comment:1 by fwarmerdam, 20 years ago

Cc: sgillies@… added
Sean,

When reading from a mapfile, there is custom code in the END processing for
loadOutputFormat() to set the format->renderer to MS_RENDER_WITH_RAWDATA if
the imagemode is one of a few special values.  I think some similar sort of
logic needs to go in MapScript when imagemode is set.  How would I got about
changing mapscript.i to provide custom code in the methods that sets imagemode?

Best regards,

comment:2 by sgillies@…, 20 years ago

How to have the imagemode setter change the value of renderer
as a side effect?  Nevermind that SWIG doesn't support this in
a straight forward way -- I'd prefer that the mapscript module
aspire to be as orthogonal as possible.

How about checking to make sure that the imagemode/renderer pair
make sense on the drawing end rather than on the loading end?
Or implementing an extension function that jointly modifies them?
Or better document the existing situation?  I did not do a very
complete job on the output formats in mapscript.txt because
there were some things I didn't understand.  The renderer, for
one.

comment:3 by lfilak@…, 20 years ago

Cc: lfilak@… added

comment:4 by fwarmerdam, 20 years ago

Milestone: 4.4 release
Status: newassigned
This is clearly an issue I need to deal with and by the 4.4 release.

comment:5 by fwarmerdam, 20 years ago

Sean,

There is already an msOuputFormatValidate() function in mapoutput.c that is
used to verify reasonable state of an outputFormatObj.  It is invoked at the
point that output formats are selected for use in a map for instance.  

I will change this function to "fixup" the imagemode which I think would
resolve this issue.

I am looking into doing a similar fixup for conflicting transparent/imagemode
issues for another bug. 

comment:6 by fwarmerdam, 20 years ago

Resolution: fixed
Status: assignedclosed
OK, I have made the changes to validate() to correct the renderer setting.
I have also exposed the validate() method in mapscript so that scripters
can force it to be used immediately, though it isn't strictly necessary. 
It will be done later on an msSelectOutputFormat(). 

I would add that it is illegal to directly assign mapObj.outputformat.
It has to be "selected in" in order to perform proper reference counting. 
I see there is a setOutputFormat() method on the mapObj which does this
correct.  Can we ensure this is used and that outputformat is read-only
from MapScript?  Is this already done?

I am marking this bug resolved, though it might be nice for PHP mapscript
to also have the validate method exposed. 

comment:7 by sgillies@…, 20 years ago

So validate() should be called for every dynamically-created format?

I've consistently reminded users to select output formats using the
mapObj::setImageType() method.  I think everybody knows (or should)
that directly setting outputformat is a no-no.  

To make it immutable, edit map.h like this:

#ifdef SWIG
%immutable;
  outputFormatObj *outputformat;
%mutable;
#endif SWIG

comment:8 by fwarmerdam, 20 years ago

Sean, 

Scripts don't normally have to call validate() since at a lower level other
stuff will call validate().  I just exposed it in mapscript for easier testing,
and for those rare cases where a script might want to directly change an
imageFormatObj that is already assigned to a map. 

I would like to make mapObj->outputformat immutable.  Should I just go ahead and
do that?  

comment:9 by sgillies@…, 20 years ago

Yes, go ahead.

comment:10 by fwarmerdam, 20 years ago

outputformat (and numoutputformat and outputformatlist) made immutable.

Note: See TracTickets for help on using tickets.