PERL/Mapscript postGIS examples?

Eric Bridger eric at GOMOOS.ORG
Tue Mar 21 08:53:53 EST 2006


I think the question is what does postgis think the srid is?

select srid from geometry_columns where f_table_name = 'probe';

On Mon, 2006-03-20 at 20:55, Stephen Davies wrote:
> Good pick Eric.
> 
> I did as you suggested and changed the projection to "latlong" and it 
> worked - from mapscript and from CGI mapserv.
> 
> (The extent is passed in as args in both cases. That's why you don't see 
> an extent statement in the mapfile.)
> 
> The question now has to be why?
> I only changed the one line - well replaced two with one.
> 
> I then replaced the original PROJ entries in the mapfile and called 
> setProjection("proj=latlong"); in the PERL and it worked again.
> 
> The original eqc projection still works with CGI mapserv.
> 
> What is different with mapscript?
> 
> Cheers and thanks,
> Stephen
> 
> On Tuesday 21 March 2006 08:32, Eric Bridger wrote:
> > Not sure why this would work in CGI mode.
> > shp2img is the best tool for debugging postgis layers. Well, turning
> > on postgres logging works as well.
> >
> > Just a guess but I suspect a projection issue.
> >
> > Does your postgis data really have an SRID of 4284?  You many need to
> > change your DATA statement in the postgis layer to something like:
> > DATA "the_geom (select * from probe) using unique oid using
> > SRID=4284"
> >
> > The postgis queries below look like they are attempting to use the
> > standard SRID of -1 or lat/lon projection.
> >
> > Also I don't see any EXTENT in your map file. That should throw an
> > error.
> >
> > I would try getting it all to work with no projection (proj=latlong
> > or EPGS:4326) first then start messing with the projections.
> >
> > Eric
> >
> > On Sat, 2006-03-18 at 01:15, Stephen Davies wrote:
> > > 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
> 
> -- 
> ========================================================================
> 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