Using MapServer as a C/C++ library

Brian Peschel brianp at OCCINC.COM
Fri Jan 13 16:20:14 EST 2006


So, I thought I was on the right track here. I setup my map file. I call 
msDrawMap. If I call msSaveImage() I can see the image.

So, I tried using the GD pointer. I complied without SWIG, so looking at 
map.h, I figured I could make this call:

_image_ptr = gdImageJpegPtr( msImage->img.gd, &_image_size, 50 );

to create a jpeg image pointer. However, the value of _image_size after 
the return is a negative number.

I am missing something (probably really obvious).....

- Brian

Ned Harding wrote:
> Brian,
>
> Fortunately, stuff like this is really easy when you are using the
> internal APIs.  They are not documented super well, but they are pretty
> self explanatory.  Don't bother with the CGI API and go straight to the
> raw APIs underneath.
>
> 	mapObj *pMap = msLoadMap(strDefaultMapPath, NULL); 
> 	imageObj *pImage = msDrawMap(pMap);
>
> At this point, pImage contains a gd pointer.  If you wanted to do
> anything custom with the layers or extent, you can work directly on the
> pMap object in between the Load and the Draw.  Don't forget to call the
> cleanup functions when you are done:
>
> 	msFreeImage(pImage);
> 	msFreeMap(pMap);
>
> Ned Harding
> Chief Technology Officer
> SRC - Extending the Reach of Micromarketing
> 3825 Iris Ave Suite 150
> Boulder, CO 80303
> (303) 440-8896 x104
>
> http://www.extendthereach.com
>
> Technology in Action:
>
> http://www.DemographicsNow.com
>
>
> -----Original Message-----
> From: UMN MapServer Developers List [mailto:MAPSERVER-DEV at LISTS.UMN.EDU]
> On Behalf Of Brian Peschel
> Sent: Monday, January 02, 2006 6:08 AM
> To: MAPSERVER-DEV at LISTS.UMN.EDU
> Subject: [UMN_MAPSERVER-DEV] Using MapServer as a C/C++ library
>
> I originally posted this on the USER list, but it was suggested I also
> post this to the DEV list, so.....
> [start original post]
> So I am curious about using MapServer inside an existing C++ program.  A
> previous query about this suggested I shell out to the OS and call
> shp2image to create the image which I could then read in.  Shelling to
> the OS is not my prefered way of doing anything (there are limitations
> in the C system() call I would prefer to avoid).  So, I would rather use
> MapServer as a library call.
>
> Looking at the makefile generated by MapServer, I see that the CGI
> program can be compiled as a library (the shp2img program uses a static
> library version), so that should work for me.
>
> Looking at the PHP/MapScript documentation
> (http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class) and the
> code for shp2img, I see how the mapObj is created which creates an
> imageObj which writes out to a file.  I could (I suppose) write out to a
> file and use GD to read the file back in to I can get access to the
> pixels for my display.  I would prefer to skip the write to file/read
> the file part for speed.
>
> Is there another reference on the classes I am missing?  The online docs
> don't seem to give an indication of what the actual classes do, just
> methods in the classes.  Is there a better place to look for this?  Is
> this more of a question for the DEV list rather than the USER list?
>
> I haven't actually installed MapScript itself.  From the Readme in the
> MapServer download, it says it is a module, and does not list C or C++
> as a language it supports.
> [end original post]
>
> The one suggestion I saw was to try to use the SWIG mapserver interface
> and write my own wrapper.  This may be more than I can bite off in a
> short period of time.  It might be easier (for me, not for the
> community) to just create the library version of MapServer and do what I
> need by looking at the headers and the couple of examples that ship with
> the executable.
>
> Thanks in advance for any help...
>
> - Brian
>   

-- 
Brian Peschel
One Call Concepts, Inc
Systems Division

Voice: 414-259-1047 ext. 93
Fax: 414-777-3666



More information about the mapserver-dev mailing list