PERL/Mapscript postGIS examples?

Stephen Davies sdc at SDC.COM.AU
Fri Mar 17 22:15:08 PST 2006


Thanks for the feedback.

Turning on PostgreSQL logging did indeed reveal more information.
However, it leaves even more confused than before.

It seems that the underlying cause of my results is that the extent 
being used by mapscript bears no relation to the extent that I 
specified.

Here is the sql statement generated from mapscript:

 2006-03-18 16:22:47 CST LOG:  00000: duration: 33.759 ms  statement: 
DECLARE mycursor BINARY CURSOR FOR SELECT 
location::text,asbinary(force_collection(force_2d(geom)),'NDR'),id::text 
from probe WHERE geom && setSRID('BOX3D(139.522253226183 
-0.000314231148091942,139.522253452601 -0.000314003203767908)'::BOX3D, 
find_srid('','probe','geom') )

The actual extent specified (and the one that works from CGI mapserv) 
was:

139.5143351 -34.7459112 139.5278707 -34.7207064

The "correct" query as generated by a CGI call with the above mapext is:

2006-03-18 16:11:57 CST LOG:  00000: duration: 33.703 ms  statement: 
DECLARE mycursor BINARY CURSOR FOR SELECT 
location::text,asbinary(force_collection(force_2d
(geom)),'NDR'),id::text from probe WHERE geom && 
setSRID('BOX3D(139.508530404246 -34.7456930137356,139.533675395754 
-34.7204885334377)'::BOX3D, find_srid('','probe','geom') ) 

Again the extent is changed but nowhere as drastically.

I then tried hard-wiring the extent into the map file and removing the 
mapext argument from the CGI call and got the same result and the same 
query.

I then modified my PERL script to use the extent in the map file and 
again got the same result and the same query generated.

It looks as if the mapscript setExtent method does something strange and 
different from the CGI mapext option and that both do strange things 
with extent statements in map files in some circumstances.

I tried changing the UNITS to DD but this made no difference (METERS is 
required to make reference maps etc work properly in the CGI world.)

Cheers,
Stephen

On Friday 17 March 2006 23:42, Simpson wrote:
> Stephen,
>
> You might try checking the Postgresql logs to see if Mapserver is
> connecting and requesting data.  Turn on statement logging in
> Postgresql config to get details of exactly what is being sent.  You
> can then run the statement from psql to see if it is returning what
> you expect.
>
> Drew.
>
> -----Original Message-----
> From: UMN MapServer Users List
> [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On Behalf Of Stephen Davies
> Sent: Friday, March 17, 2006 12:48 AM
> To: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: [UMN_MAPSERVER-USERS] PERL/Mapscript postGIS examples?
>
>
> Could somebody please send me or point me at an example of a
> PERL/Mapscript script that displays layers populated from a postGIS
> database and/or raster layers?
> The following PERL/Mapscript  and map file generates an image
> containing only the copyright layer.
> Exactly the same map file with mapserver invoked as CGI generates all
> layers.
> (In both cases the extent is provided as args.
> eg ./genpics q 1 jpg 139.5143351 -34.7459112 139.5278707 -34.7207064)
>
> Cheers and thanks,
> Stephen Davies
>
> #! /usr/bin/perl
> #
> # args are UID (for mapfile), pic sequence #, image type (extension),
> extent
> #
> use strict;
> #use CGI;
> use mapscript;
> my $uno = $ARGV[0];
> my $seq = $ARGV[1];
> my $ext = $ARGV[2];
> my $minx = $ARGV[3];
> my $miny = $ARGV[4];
> my $maxx = $ARGV[5];
> my $maxy = $ARGV[6];
> #
> # if sequence = 1, create/empty directory (ignoring errors)
> #
> if ($seq == 1){
>   mkdir("/var/www/html/status_images/$uno",0777);
>   unlink </var/www/html/status_images/$uno/*>;
> }
> #
> my $mapfile = "/tmp/$uno.map";
> my $map = mapscript::mapObj->new($mapfile);
> my $i=$map->setExtent($minx,$miny,$maxx,$maxy);
> #
> #my $img = $map->prepareImage();
> my $img = $map->draw();
> my $fname = "/var/www/html/status_images/$uno/$seq.$ext";
> $img->save($fname);
> ===================================================
> MAP
>   NAME perltest
>
>
>     PROJECTION
>         "proj=eqc"
>         "lon_0=139.521e"
>     END
>
>     SIZE 600 600
>     FONTSET "/var/www/html/benparts/fonts.list"
>     SYMBOLSET "/var/www/html/benparts/symbols"
>     UNITS METERS
>     IMAGETYPE  jpeg
>     OUTPUTFORMAT
>         NAME jpeg
>         DRIVER "GD/JPEG"
>         MIMETYPE "image/jpeg"
>         IMAGEMODE RGB
>         EXTENSION "jpg"
>         FORMATOPTION "QUALITY=75"
>     END
>     IMAGECOLOR 255 255 255
>
>     WEB
>         template /var/www/html/benparts/templates/test1.html
>         imagepath "/var/www/html/tmp/"
>         imageurl  "/tmp/"
>     END
>
>     LAYER
>       TYPE RASTER
>       NAME "bkgrnd"
>       STATUS DEFAULT
>       PROJECTION
>        "init=epsg:28354"
>       END
>       DATA "/var/www/html/benparts/rasters/walker.ecw"
> #      OFFSITE 0 0 0
>       PROCESSING "DITHER=YES"
>     END
>
>     LAYER
>       CONNECTIONTYPE postgis
>       NAME "probe"
>       DATA "geom from probe"
>       CONNECTION "user=scldad dbname=benparts"
>       STATUS DEFAULT
>       TYPE POINT
> #      FILTER "id in (0)"
>       PROJECTION
>         "init=epsg:4284"
>       END
>       MAXSCALE 5000000
>       LABELITEM "location"
>       CLASS
>         NAME       "Probe (Right Click to select)"
>         STYLE
>           COLOR        0 214 0
>           SYMBOL 'circle'
>           SIZE 7
>         END
>         LABEL
>           MINDISTANCE 15
>           POSITION CR
>           SIZE SMALL
>           COLOR 0 0 0
>           FORCE TRUE
>         END
>       END
>     END
>
>     LAYER
>       NAME 'copyright'
>       TYPE ANNOTATION
>       STATUS DEFAULT
>       TRANSFORM FALSE # coordinates are in pixels
>       FEATURE
>         POINTS 10 595 END
>       END
>       CLASS
>         LABEL
>           TYPE TRUETYPE
>           FONT arial
>           SIZE 8
>           COLOR 255 0 0
>           POSITION CR
>         END
>         TEXT 'Photography supplied by MAPLAND, Environment
> Information, Dept Environment & Heritage'
>       END
>     END
> END
> --
> =====================================================================
>=== This email is for the person(s) identified above, and is
> confidential to the sender and the person(s).  No one else is
> authorised to use or disseminate this email or its contents.
>
> Stephen Davies Consulting                            Voice: 08-8177
> 1595 Adelaide, South Australia.                             Fax:
> 08-8177 0133 Computing & Network solutions.                      
> Mobile:0403 0405 83

-- 
 =======================================================================
This email is for the person(s) identified above, and is confidential to
the sender and the person(s).  No one else is authorised to use or
disseminate this email or its contents.

Stephen Davies Consulting                            Voice: 08-8177 1595
Adelaide, South Australia.                             Fax: 08-8177 0133
Computing & Network solutions.                       Mobile:0403 0405 83



More information about the MapServer-users mailing list