wiki:PerlMapScriptExamples35

Perl Mapscript 3.5+ Examples

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.

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.

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.

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.

Queryable point objects as layer Features with no shapefile or database connection. Mapscript 3.6.4. This is a CGI script.

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.

Perl subroutine to convert reference map mouse click to full map extents. A clone of 3.6.4. maptemplate.c::setExtent() case FROMREFPT

A simple but complete example of using Perl/Mapscript?? and HTML::Template to create a mapping application

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.

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().

Last modified 13 years ago Last modified on Jan 29, 2009, 7:16:23 AM