Perl Mapscript 3.5+ Examples
- create tileindex.pl submitted by Markus W. Spring <m.spring@…>
create_tileindex.pl creates a tileindex shapefile for the usage of tiled georeferenced images in mapserver. It needs as arguments the name of the tileindex shapefile to be created. Please specify no extension for the tileindex argument! The argument for the image extension can be omitted, it defaults to 'tif'. Additionally the imagedir can be given, it defaults to the current directory. When the verbosity argument is given, the names of the processed files are printed. Two or more -v's on the commandline additionally print the coordinates of the images.
- mapquakes.pl submitted by Stephen Lime <steve.lime@…>
The orignal mapscript demo. Maps global earth quakes from data stored at the USGS on top of data stored locally. Data is not included but is available upon request.
- dump.pl submitted by Lowell.Filak <lfilak@…> originally by Stephen Lime <steve.lime@…> (verified to run under 3.5 & 3.6.1)
Given a shapefile name this routine will dump out the shapefile type, members, & applicable coordinate information.
- find.pl submitted by Lowell.Filak <lfilak@…> (verified to run under 3.5 & 3.6.1)
Given a shapefile name, item name, & item value this routine will dump out the matching records.
- shpinfo.pl submitted by Lowell.Filak <lfilak@…> originally by Stephen Lime <steve.lime@…> (verified to run under 3.5, 3.6.1, & 3.6.5)
Given a shapefile name this routine will dump out the attribute information.
- resize_orthos.pl submitted by Lowell.Filak <lfilak@…>
Given a directory containing tiff(s) and tfw(s), the original pixel size, the destination directory for resized & recolored tiff(s), & the new pixel size this routine will resize & recolor the tiff(s) and write new wld files to match.
- qry_point.pl submitted by Lowell.Filak <lfilak@…> (verified to run under 3.5 & 3.6.1)
Given a shapefile name, a coordinate, & an item name this routine will select a shape, select all the shapes with the same item value, & create a shapefile of the selected shape(s).
- tcounts.pl submitted by Lowell.Filak <lfilak@…> (verified to run under 3.5 & 3.6.1)
Given the name of an existing palm database and the name of an existing point shapefile this routine will append the points in the pdb to the shapefile. Given just the name of an existing shapefile the routine will attempt to use pilot-xfer to download the pdb file and append the points to the shapefile. Given just the name of an existing pdb file this routine will create a new shapefile of the points in the pdb file. Given neither name this routine will attempt to use pilot-xfer to download the pdb file and create a new point shapefile from it.
- tcheck.pl submitted by Lowell.Filak <lfilak@…> (verified to run under 3.5 & 3.6.1)
Given the name of an existing point shapefile, the name of an existing line shapefile, a radius distance, a field name in the point shapefile, a filed name in the line shapefile, & optionally an accuracy field name in the point shapefile this routine will search within a circular buffer of each point (of specified radius + optional accuracy) for a line with a matching field value and then assign the point a 0 error for a single match. Otherwise the point will be assigned an error of 1 for no matches & x for a number of matches > 1 where x is the number of matches.
- anno_crvt.pl (verified to run under 3.5 & 3.6.1)
Given an arcinfo coverage name this routine will convert the annotations (TX6/TX7 ONLY) from the first annotation subclass into a line shapefile.
- project.pl (runs under 3.6 and should be fine with 3.5)
Simple script to project a shapefile given 2 Proj.4 projection definition strings.
- plsscalc.pl submitted by Puneet Kishor <pkishor@…> (Not really a MapScript example, but potentially useful for mapping apps)
Given a township, range, section, quarter-section, and a search radius in miles, this script will spit out all the quarter-sections within the search radius of the origin. Assumes regular and continuous coverage of PLSS.
- thin.pl submitted by Stephen Lime <steve.lime@…>
(thin.pl) is perl mapscript that does line thinning. It's a port of the ArcView thinning script. A bit slow but seems to work fine.
- query_points.pl submitted by Eric Bridger <eric@…>
Queryable point objects as layer Features with no shapefile or database connection. Mapscript 3.6.4. This is a CGI script.
- query_points2.pl submitted by Eric Bridger <eric@…>
A new and improved version of query_points.pl. Shows how to create a dynamic point layer which responds to queryByPoint() and will return your numeric database key values.
Given the name of an existing polygon shapefile this routine will add 4 fields to the dbf file for the least bounding rectangle for each polygon and populate those fields.
- Fetchmap.pl submitted by Chris Stuber (mapsurfer) <mapsurf@…>
Example of a Simple Perl CGI backend Interface using mapscript, to fetch map images from a URL. Demonstrates using and overriding default parameters, error handling and new and old methods.
- ref_to_map_ext.pl submitted by Eric Bridger <eric@…>
Perl subroutine to convert reference map mouse click to full map extents. A clone of 3.6.4. maptemplate.c::setExtent() case FROMREFPT
- MapscriptHTMLTemplate submitted by Puneet Kishor <pkishor@…>
A simple but complete example of using Perl/Mapscript? and HTML::Template to create a mapping application
- lvprint.pl submitted by Steve Lime
The Landview print rotuine - PDF output using pdflib.
Perl Mapscript 4.2+ Examples
There are fairly major changes in Mapserver4.0+, styleObj, colorObj, etc. and many new methods thanks to Sean Giles so I figured it's time for a new section of examples. My experience, with little testing, was that mapscript4.0.2 was not quite ready for prime time, missing some of the newer methods. One major thing to watch out for, Sean made use of Perl's automatic garbage collection, creating destructors for all objects so there is no need to call any free() methods. In fact $imageObj->free() causes a core dump. The free() methods will be going away in the near future.
- query_points42.pl submitted by Eric Bridger <eric@…>
Just a 4.2 version of query_points2.pl, above. Shows how to create a dynamic point layer which responds to queryByPoint() and will return your numeric database key values and illustrates the use of the new styleObject and the new setRGB() methods and the new $layerObj->getNumResults().