[Mapserver-dev] Working PHP Mapscript module produced with SWiG?!

Mark Cave-Ayland m.cave-ayland at webbased.co.uk
Thu Mar 18 11:35:38 EST 2004

This is a multi-part message in MIME format.

Content-Type: text/plain;
Content-Transfer-Encoding: 7bit

Hi Paul/Developers,

In response to your email, I've just had a play at using SWiG to
generate a PHP Mapscript module and I'm pleased to report back that I
have managed to produce a working mapscript.so module by running SWiG on
the mapscript.i file :)

The setup I used was:

	PHP 4.3.3
	SWiG 1.3.21
	Mapserver 3.6.6

I was hoping to also test Mapserver 4, but unfortunately our new
development server running Mapserver 4 is also running PHP5, and alas
SWiG doesn't yet support PHP5.

To do this, I created a new directory called php4 in the mapscript/
directory and created a symlink to mapscript.i. The resulting wrapper
file was generated (with warnings) using:

	swig -php4 mapscript.i

and compiled using the attached build.sh script. During compilation I
received two warnings which were given below:

mapscript_wrap.c: In function `_wrap_labelObj_wrap_get':
mapscript_wrap.c:9087: warning: initialization makes pointer from
integer without a cast
mapscript_wrap.c: In function
mapscript_wrap.c:13820: warning: initialization makes pointer from
integer without a cast

The only gotcha I found was that it was necessary to specify all the
libraries used by the mapscript module using -l when generating the
shared library, otherwise PHP would give an 'undefined symbol' error
when the module was loaded with dl().

As a quick test I took a test script I wrote in Perl Mapscript and
converted it into PHP Mapscript (also attached) and was absolutely
stoked when it worked. I don't know how we should go about
comprehensibly testing this, but I thought I would report back to the
list that the module compiles and appears to work. Do we have any way
testing that all the functions are working correctly? It would be great
to see a unified Mapscript, especially as developers are working on
bringing together the documentation :)




Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446

This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.

> -----Original Message-----
> From: mapserver-dev-admin at lists.gis.umn.edu 
> [mailto:mapserver-dev-admin at lists.gis.umn.edu] On Behalf Of 
> Paul Ramsey
> Sent: 17 February 2004 23:48
> To: mapserver-dev
> Subject: Re: [Mapserver-dev] SWIG MapScript docs
> Steve Lime wrote:
> > MapScript should be viewed as one, unified, API rather than 
> the 6 or 
> > so seperate ones it is today. That was the idea originally.
> Has anyone exercised the PHP4 support in SWIG lately? Last 
> time I tried 
> (almost a year ago) is was not up to the test, but these 
> things change...
> -- 
>        __
>       /
>       | Paul Ramsey
>       | Refractions Research
>       | Email: pramsey at refractions.net
>       | Phone: (250) 885-0632
>       \_
> _______________________________________________
> Mapserver-dev mailing list
> Mapserver-dev at lists.gis.umn.edu 
> http://lists.gis.umn.edu/mailman/listinfo/maps> erver-dev

Content-Type: application/octet-stream;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;


// Display a simple PostGIS layer using PHP Mapscript (SWiG version)

// PHP Mapscript test
$map =3D new mapObj('');

// Extents
$rectExtent =3D new rectObj();
$rectExtent->minx =3D 239997.5;
$rectExtent->miny =3D 60002.5;
$rectExtent->maxx =3D 279997.5;
$rectExtent->maxy =3D 40002.5;

// Setup the map
$backColor =3D new colorObj();
$backColor->red =3D 255;
$backColor->green =3D 255;
$backColor->blue =3D 255;

$map->imagecolor =3D $backColor;
$map->imagetype =3D MS_PNG;
$map->interlace =3D MS_OFF;
$map->extent =3D $rectExtent;
$map->width =3D 320;
$map->height =3D 320;

// For predefined symbols

// Generate a new layer with a single class
$layer =3D new layerObj($map);
$class =3D new classObj($layer);

// Setup the layer
$layer->status =3D MS_ON;
$layer->connectiontype =3D MS_POSTGIS;
$layer->type =3D MS_LAYER_POINT;
$layer->connection =3D 'user=3Dpostgres password=3Dnone =
dbname=3Dinfomapper_dev host=3D192.168.2.4 port=3D5432';
$layer->setFilter('layermoid=3D23::bigint AND isdeleteditem=3D\'f\'');
$layer->data =3D 'geom from osgb_point';

// Setup the class for a symbol
//$class->color =3D $map->addColor(0, 0, 255);
//$class->symbol =3D $map->getSymbolByName('circle');
//$class->size =3D 5;

// OR setup the class for the bitmap
$class->symbol =3D =

// Draw the map
$mapimg =3D $map->prepareImage();
$layer->draw($map, $mapimg);

// Save a copy of the final image
$mapimg->saveImage('/tmp/out-php.png', $map->imagetype, =
$map->transparent, $map->interlace, 50);


Content-Type: application/octet-stream;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;

export PHPINC=3D`php-config --includes`=0A=
gcc $PHPINC -fpic -c mapscript_wrap.c=0A=
gcc -shared mapscript_wrap.o -o mapscript.so -lmap -lproj -lpq -ltiff =
-ljpeg -lpng=0A=


More information about the mapserver-dev mailing list