<!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">
<font face="Verdana"><small>Tom, that PPT linked from your example is
filled with good stuff.&nbsp; Anyway, I took your example and did some minor
changes to make it work with mapscript as Fedora installs it and my
data. Then I added the ability to turn projection on &amp; off. With
the projection off, everything works great. But, I'm still getting a
blank image with the projection turned on. If anyone has any pointers
on what's wrong with the code (below) I'd appreciate it.<br>
<br>
Tim Wood</small><br>
<br>
<small><font face="Courier New, Courier, monospace">---------------------------------------------------------------------<br>
&lt;?PHP<br>
<br>
// Where my key directories are located<br>
$doc_root = '/var/www/html';<br>
$rel_path = "example1/round2";<br>
$base_path = "$doc_root/$rel_path";<br>
<br>
// An empty map file<br>
$base_map = "$base_path/data/empty.map";<br>
<br>
// The data I'm using (Statistics Canada's 2006 FSA files)<br>
$shape_path = "$base_path/data/zcta/zt08_d00_shp/";&nbsp;&nbsp;&nbsp;&nbsp; // 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;&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 (Canada)<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>
<br>
<br>
// Load MapScript extension <br>
if (!extension_loaded("MapScript"))&nbsp;
dl('php_mapscript.'.PHP_SHLIB_SUFFIX); <br>
<br>
// add map<br>
$map = ms_newMapObj( $base_map );<br>
<br>
// tdw temp<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>
<br>
// This line hides a bunch of errors that appear iff $output_projection
is set<br>
$layer-&gt;set("template", "ttt");<br>
$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>
if( $output_projection != '' ) {&nbsp;&nbsp; // Project and Draw<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // create new rect to query against the new layer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $rect = ms_newRectObj();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $rect-&gt;setExtent( $ex0, $ex1, $ex2, $ex3 );<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // query new layer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $layer-&gt;queryByRect( $rect );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map-&gt;queryByRect( $rect );<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // set projection of output map<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map-&gt;setProjection($output_projection, MS_TRUE);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // draw<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $image = $map-&gt;drawQuery();<br>
} else {&nbsp;&nbsp; &nbsp;&nbsp; // Just draw the map<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // draw<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $image = $map-&gt;draw();<br>
}<br>
<br>
// Save the image<br>
$image-&gt;saveImage( $output_file_path ); <br>
<br>
?&gt;<br>
&lt;html&gt;<br>
&lt;body&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;img src="&lt;?PHP print $output_file_rel; ?&gt;"&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
---------------------------------------------------------------------</font></small><br>
<br>
<br>
Kralidis,Tom [Ontario] wrote:</font>
<blockquote cite="mid:DDA8F0C2655CB14DA8C7B84CDC6759A61824ADE2@dowexch2"
 type="cite">
  <pre wrap=""><font face="Verdana">I've added a small example at:

<a class="moz-txt-link-freetext" href="http://trac.osgeo.org/mapserver/wiki/PHPMapscriptAddLayerQueryReproject">http://trac.osgeo.org/mapserver/wiki/PHPMapscriptAddLayerQueryReproject</a>

Hope this helps.

..Tom



-----Original Message-----
From: <a class="moz-txt-link-abbreviated" href="mailto:mapserver-users-bounces@lists.osgeo.org">mapserver-users-bounces@lists.osgeo.org</a> on behalf of Tim Wood
Sent: Sat 07-Feb-09 22:55
To: <a class="moz-txt-link-abbreviated" href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a>
Subject: [mapserver-users] Problems with MapScript and setProjection
 
I've been round and round with setProjection in MapScript and 
setProjection today. I either get the infamous blank image  or the image 
returns in the same proportions as the original lat/long data. Proj 
seems to be (at least partially) working because if I forget something 
like +ellps=[blah blah], it throws an error.

I'd like to look at a simple php mapscript example of creating a map, 
adding a layer, adding something to that layer (e.g. my a simple query 
against a lat/long shapefile) and then project that another way (tmerc, 
lcc, whatever). But, I have yet to find one. Can someone share a working 
example or know of one on the web?

Tim Wood

</font></pre>
</blockquote>
<font face="Verdana"><br>
</font>
</body>
</html>