<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<small><font face="Verdana">Pietro, that was exactly what I needed.
Thanks.<br>
<br>
The example below pulls everything together and works under MapServer
5.2.1 (tested under Fedora 10). If someone hits this in the mailing
list archive later and is trying to figure out reprojection, start at
the end with the comment "reproject (if needed) and draw".<br>
<br>
If someone who already has a wiki login, wants to add it to the page
that Tom Kralidis set up, feel free.<br>
<br>
Tim Wood</font></small><br>
<small><font face="Courier New, Courier, monospace"><br>
<br>
&lt;?PHP<br>
<br>
/**<br>
&nbsp;* Code to create a map from a shapefile<br>
&nbsp;* and then (optionally) reproject the whole thing<br>
&nbsp;*<br>
&nbsp;* If you just want to look at the reprojection stuff, start<br>
&nbsp;* with the "reproject (if needed) and draw" section at the end.<br>
&nbsp;* The rest <br>
&nbsp;*<br>
&nbsp;* Created by Tim Wood from code and input <br>
&nbsp;* by Tom Kralidis [Ontario], Pietro Gianninni and Stephen Jones.<br>
&nbsp;*<br>
&nbsp;* No copyright restrictions<br>
&nbsp;*/<br>
<br>
<br>
// ---------------------------<br>
// Configuration<br>
// aka set a bunch of variables and load the mapscript extension<br>
//<br>
<br>
// Where my key directories are located<br>
$doc_root = '/var/www/html';<br>
$rel_path = "example1/round2";<br>
<br>
$base_path = "$doc_root/$rel_path";<br>
<br>
<br>
// An empty map file<br>
$base_map = "$base_path/data/empty.map";&nbsp;&nbsp; // just the words MAP and
END on dif. lines... really<br>
<br>
// The data I'm using<br>
$shape_path&nbsp;&nbsp;&nbsp; = "$base_path/data/zcta/zt08_d00_shp/";&nbsp;&nbsp;&nbsp; // a goofy
path I'm too lazy to fix<br>
$shape_file = "gfsa000b06a_e";&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // works with
or w/o the extension<br>
$shape_file_projection = "+proj=longlat +datum=NAD83";<br>
<br>
// The Extents (area) I want in latitude, longitude<br>
list( $ex0, $ex1, $ex2, $ex3 ) = array(-140, 40, -50, 55 );<br>
<br>
// Describe the rest of my output<br>
$output_projection = '';<br>
$output_projection = "+proj=tcc +lon_0=90w +ellps=GRS80";<br>
$output_file_rel = "output/index2.png";<br>
$output_file_path = "$base_path/$output_file_rel";<br>
list($output_width, $output_height ) = array( 600, 500 );<br>
<br>
</font></small><small><font face="Courier New, Courier, monospace">//
Load MapScript extension <br>
if (!extension_loaded("MapScript"))&nbsp;
dl('php_mapscript.'.PHP_SHLIB_SUFFIX); </font></small><br>
<small><font face="Courier New, Courier, monospace"><br>
<br>
</font></small><small><font face="Courier New, Courier, monospace"><br>
<br>
// ---------------------------<br>
// Function(s)<br>
//<br>
</font></small><small><font face="Courier New, Courier, monospace"><br>
/**<br>
&nbsp;* Reproject a $map from </font></small><small><font
 face="Courier New, Courier, monospace">$shape_file_projection to
$output_projection</font></small><br>
&nbsp;*/<br>
<small><font face="Courier New, Courier, monospace">function
reproject_map( &amp;$map, $shape_file_projection, $output_projection ) {<br>
&nbsp;&nbsp;&nbsp; $origProjObj = ms_newProjectionObj( $shape_file_projection );<br>
&nbsp;&nbsp;&nbsp; $newProjObj = ms_newProjectionObj( $output_projection );<br>
<br>
&nbsp;&nbsp;&nbsp; $oRect = $map-&gt;extent;<br>
&nbsp;&nbsp;&nbsp; $oRect-&gt;project( $origProjObj, $newProjObj );<br>
&nbsp;&nbsp;&nbsp; $map-&gt;setExtent( $oRect-&gt;minx, $oRect-&gt;miny,
$oRect-&gt;maxx, $oRect-&gt;maxy );<br>
&nbsp;&nbsp;&nbsp; $map-&gt;setProjection( $output_projection&nbsp; );<br>
}<br>
<br>
<br>
</font></small><br>
<small><font face="Courier New, Courier, monospace">//
---------------------------<br>
// The Main Code<br>
//<br>
<br>
</font></small><small><font face="Courier New, Courier, monospace">//
add map<br>
$map = ms_newMapObj( $base_map );<br>
$map-&gt;set( 'name', 'my_map' );&nbsp;&nbsp;&nbsp; </font></small><small><font
 face="Courier New, Courier, monospace">// If we're using a blank map
file, give it a name</font></small><br>
<small><font face="Courier New, Courier, monospace"><br>
// Set the extent<br>
$map-&gt;setExtent( $ex0, $ex1, $ex2, $ex3 );<br>
<br>
// Set the shapepath<br>
$map-&gt;set( 'shapepath', $shape_path );<br>
// Set the output format and size<br>
$map-&gt;selectOutputFormat( 'png' );<br>
$map-&gt;setSize( $output_width, $output_height );<br>
<br>
// add new layer to map<br>
$layer = ms_newLayerObj($map);<br>
$layer-&gt;set("name", "foo");<br>
$layer-&gt;set("status", MS_ON);<br>
$layer-&gt;set("data", $shape_file );<br>
$layer-&gt;set("type", MS_SHAPE_POLYGON );<br>
$layer-&gt;setProjection( $shape_file_projection );<br>
$layer-&gt;set("template", "ttt");&nbsp;&nbsp;&nbsp; </font></small><small><font
 face="Courier New, Courier, monospace">// hide errors that appear iff
$output_projection is set?</font></small><br>
<small><font face="Courier New, Courier, monospace">$layer-&gt;set("dump",
"true");<br>
<br>
// add new class to new layer<br>
$class = ms_newClassObj($layer);<br>
$class-&gt;set("name", "foo");<br>
<br>
// add new style to new class<br>
$style = ms_newStyleObj($class);<br>
$style-&gt;color-&gt;setRGB(255, 0, 0);<br>
$style-&gt;outlinecolor-&gt;setRGB( 128,128,128 );<br>
<br>
// reproject (if needed) and draw<br>
if( $output_projection != '' ) {<br>
&nbsp;&nbsp;&nbsp; reproject_map( $map, $shape_file_projection, $output_projection );<br>
&nbsp;&nbsp;&nbsp; $image = $map-&gt;drawQuery();<br>
} else {<br>
&nbsp;&nbsp;&nbsp; // draw<br>
&nbsp;&nbsp;&nbsp; $image = $map-&gt;draw();<br>
}<br>
</font></small><small><font face="Courier New, Courier, monospace"><br>
<br>
</font></small><br>
<small><font face="Courier New, Courier, monospace">//
---------------------------<br>
// Output the image<br>
//<br>
</font></small><br>
<small><font face="Courier New, Courier, monospace">$image-&gt;saveImage(
$output_file_path ); <br>
<br>
?&gt;<br>
&lt;html&gt;<br>
&lt;body&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;img src="&lt;?PHP print $output_file_rel; ?&gt;"&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;</font></small><br>
</body>
</html>