[Mapserver-users] converting to perl

Lowell Filak lfilak at medinaco.org
Mon Mar 3 15:13:28 EST 2003


Disclaimer: These are all snippets, putting them together is left as an exercise for the user.
What the following modules do is to take a given click on a parcel polygon -> grab the shape number -> query a mysql db by shape number and retrieve the parcel information ->
merge a map and the tabular information into a single resulting html page.
This is very similar to the example in the wiki except the wiki example queries the dbf file instead of an rdbms and is not broken into different modules:
http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PerlMapScriptExamples35ex7
HTH
Lowell F.

qry_pic.pm:
..
#
# Create point object for pick query.
# Note: coords are & need-to-be realworld by the time this routine is called.
$pnt = new pointObj();
$pnt->{x} = $pickx;
$pnt->{y} = $picky;
#
# Get layer for parcel query.
$idx = $imap->getLayerByName('parcelp') or die('Unable to Open Parcel Query Layer!');
$idx->{status} = $mapscript::MS_ON;
$idx->queryByPoint($imap,$pnt,$mapscript::MS_SINGLE,0);
$icache = $idx->{resultcache};
$irslt = $idx->getResult(0);
$idx->{status} = $mapscript::MS_OFF;
#
# Query db for parcel info.
$dbh = DBI->connect("DBI:mysql:db:host:port#", "user", "password");
#
# Record number to retrieve is shape number.
my $ishpno = $irslt->{shapeindex};
#
# Grab the correct record number.
$sth = $dbh->prepare("SELECT tdn,bkn,pgn,spn FROM parcelp WHERE recno = $ishpno");
$sth->execute();
@row = $sth->fetchrow_array;
my $rtdn = $row[0];
my $rbkn = $row[1];
my $rpgn = $row[2];
my $rspn = $row[3];
$rppn = $rtdn.$rbkn.$rpgn.$rspn;
#
# Print the parcel information.
&prt_prcl($dbh,$rppn,$rtdn,$rbkn,$rpgn,$rspn);
..
#
# Create image of parcel.
$rppn = uc $rppn;
$rmap = &plt_prcl($imapeminxf,$imapeminyf,$imapemaxxf,$imapemaxyf,$shpfname,$rppn);
..
return;
}

prt_prcl.pm:
..
#
# Loop through each column.
$sth = $dbh->prepare("SELECT DISTINCT deed_acre FROM parcelp WHERE tdn=\'$tdn\' AND bkn=\'$bkn\' AND pgn=\'$pgn\' AND spn=\'$spn\'");
$sth->execute();
$acre = $row[0];
..
print REPORT "Acreage: <strong>$acre</strong>\n<br>";
..
#
# Return.
return;
}

plt_prcl.pm:
..
#
# Create image of parcel.
my $rmap = new mapObj('mche.map');
$rmap->{interlace} = $mapscript::MS_FALSE;
..
$rimg = $rmap->draw();
#
$rimg->saveImage("../html$image_name",$mapscript::MS_PNG,$rmap->{transparent},$rmap->{interlace},0);
..
return $rmap;
}

The following message was sent by Jon Shorie <jshorie at medinaco.org> on Tue, 25 Feb 2003 12:55:45 -0500.

> I will be more specific.  I currently have a mapserver application up on a 
> local network.  My eventual goal is to integrate mapserver into some of our 
> backend database processing applications.  Initially I am just looking to be 
> able to run some perl code of a user of the mapserver queries on a layer.  
> What I would like to do is to use the layer information to issue a query to a 
> backend database which would pull up service information for hydrants if the 
> user clicks on the hydrant.  
> 
> The way that I am handling this currently is to have an html page called by 
> the query on the layer like so:
> 
> <tr><td>[ID]</td><td>[NUMBER]</td><td>[NEWFIELD1]</td>
> <td>[NAME]</td><td>Click <a 
> href=http://172.16.40.17/cgi-bin/publichydrants/resultshydrant.cgi?sort=none&hydrantname=[NAME]>
> Here</a> for data on this hydrant<td></tr>
> 
> Here is the reference in the mcse.map file.
> 
> LAYER
>   NAME hydrants
>   TYPE POINT
>   MAXSCALE 300000
>   STATUS DEFAULT
>   DATA hydrants
> 
>   CLASS
>     NAME "Hydrants"
>     TEMPLATE "hydrants.html"
>     COLOR 255 0 0
>     SYMBOL 'circle'
>     SIZE 7
>   END
> 
> What this method does is if the user queries a hydrants feature they get a 
> page that says clieck here for data on this hydrant.  If the user then clicks 
> on the link sends the hydrantname to a perl script that queries the database.
> 
> What I would prefer to do is to have the query to directly to the perl script 
> and not even bring up the intermediate page.
> 
> Is this possible?
> 
> 
> 
> 
> 
> 
> 
> 
> On Tuesday 25 February 2003 11:17, you wrote:
> > OK - if you can explain a bit about what you're trying to do, we'll try to
> > help.
> >
> > 	- Ed
> >
> > Ed McNierney
> > President and Chief Mapmaker
> > TopoZone.com / Maps a la carte, Inc.
> > 73 Princeton Street, Suite 305
> > North Chelmsford, MA  01863
> > ed at topozone.com
> > (978) 251-4242
> >
> > -----Original Message-----
> > From: Jon Shorie [mailto:jshorie at medinaco.org]
> > Sent: Tuesday, February 25, 2003 11:21 AM
> > To: mapserver-users at lists.gis.umn.edu
> > Subject: Re: [Mapserver-users] converting to perl
> >
> >
> > I am trying to use Perl to generate input for mapserver
> >
> > On Tuesday 25 February 2003 11:09, you wrote:
> > > Jon -
> > >
> > > I'm not quite sure what your question is.  Are you trying to get
> > > MapServer to process template files to generate Perl output that then
> > > gets processed and sent to the client?  Or are you trying to use Perl to
> > > generate input for MapServer?
> > >
> > > 	- Ed
> > >
> > > Ed McNierney
> > > President and Chief Mapmaker
> > > TopoZone.com / Maps a la carte, Inc.
> > > 73 Princeton Street, Suite 305
> > > North Chelmsford, MA  01863
> > > ed at topozone.com
> > > (978) 251-4242
> > >
> > > -----Original Message-----
> > > From: Jon Shorie [mailto:jshorie at medinaco.org]
> > > Sent: Tuesday, February 25, 2003 10:50 AM
> > > To: mapserver-users at lists.gis.umn.edu
> > > Subject: [Mapserver-users] converting to perl
> > >
> > >
> > > I am in the process of trying to convert a mapserver application to perl
> > > from raw html.  Here is a portion of my mcse.map file.
> > >
> > > WEB
> > >   HEADER mcse_header.html
> > >   TEMPLATE mcse.html
> > >   FOOTER mcse_footer.html
> > >   MINSCALE 1000
> > >   MAXSCALE 1550000
> > >   IMAGEPATH "set in mcse_init.html"
> > >   IMAGEURL "set in mcse_init.html"
> > >   METADATA
> > >     WMS_TITLE "MCSE GIS Application"
> > >     WMS_ABSTRACT "This is the Demo of a GIS System for MCSE.  It is based
> > > on the mapserver demo application."
> > >     WMS_ACCESSCONSTRAINTS none
> > >
> > >     # change this value to match your setup
> > >     WMS_ONLINERESOURCE
> > > "http://172.16.40.17/cgi-bin/mcsegis/mcse_init.cgi"
> > >
> > >     WMS_SRS "EPSG:26915"
> > >   END
> > > END
> > >
> > >
> > > _______________________________________________
> > > Mapserver-users mailing list
> > > Mapserver-users at lists.gis.umn.edu
> > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> >
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at lists.gis.umn.edu
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users




More information about the mapserver-users mailing list