Parallel MapScript Translations

A simple example is shown in this section using multiple scripting programming languages. Examples 14-5 through 14-9 provide a reference point for programmers who want to see how MapScript can be used in various languages. All these examples do the exact same thing—open a map file, draw the map, and save it to an image file. They are meant to be run in the same folder as the global.map map file, and they all produce an image file called worldmap.png.

Example 14-5. Python MapScript basic example

# map1.py
# Python MapScript Example 1

import mapscript

# Set the map file to use
mapfile = "global.map"

# Create a mapObj, initialized with the mapfile above
mapobject = mapscript.mapObj(mapfile)

# Create an imgObj that has an image of the map
mapimage = mapobject.draw()

# Save the mapimage to a file
mapimage.save("worldmap.png")

Example 14-6. Perl MapScript basic example

# map1.pl
# Perl MapScript Example 1

use mapscript;

# Set the map file to use
$mapfile = "global.map";

# Create a mapObj, initialized with the mapfile above
$mapobject = new mapscript::mapObj($mapfile);

# Create an imgObj that has an image of the map
$mapimage = $mapobject->draw();

# Save the mapimage to a file
$mapimage->save("worldmap.png");

Example 14-7. PHP MapScript basic example

<?PHP // map1.php // PHP MapScript Example 1 // MapScript extension could also be loaded in php.ini if (!extension_loaded("MapScript")) dl('php_mapscript.'.PHP_SHLIB_SUFFIX); // Set the map file to use $mapfile = ...

Get Web Mapping Illustrated now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.