[mapserver-users] Problems with MapScript and setProjection

Pietro Giannini pgiannini at bytewise.it
Tue Feb 10 05:53:17 EST 2009


Tim,
maybe you set a map extent wich don't coincides with the extent of the
dataset.

If you change the projection of the map you should change the extent
according with the new projection.

Try reproject the extent of the map:

$oMapProjection = ms_newProjectionObj($map->getProjection());
$oNewProjection = ms_newProjectionObj("+proj=tcc +lon_0=90w +ellps=GRS80");
$oRect = $map->extent;
$oRect->project($oMapProjection,$oNewProjection);
$map->setExtent($oRect->minx,$oRect->miny,$oRect->maxx,$oRect->maxy);
$map->setProjection("+proj=tcc +lon_0=90w +ellps=GRS80");

let me know, ciao
...................pg

STOP !! ERRATA CORRIGE:
Now I read the new php MapScript documentation and found a new
implementation of the setprojection() function:

   int setProjection(string proj_params, boolean bSetUnitsAndExtents)

bSetUnitsAndExtents (default false), if true force the map to update
Extents and Units based on the new projection (I suppose it works with the
last release, 5.2.1)

bye .......pg

-- 
Pietro Giannini
Bytewise srl - Area GIS
41°50'38.58"N 12°29'13.39"E


On Lun, Febbraio 9, 2009 19:19, Tim Wood wrote:
> Tom, that PPT linked from your example is filled with good stuff.
> 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 & 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.
>
> Tim Wood
>
> ---------------------------------------------------------------------
> <?PHP
>
> // Where my key directories are located
> $doc_root = '/var/www/html';
> $rel_path = "example1/round2";
> $base_path = "$doc_root/$rel_path";
>
> // An empty map file
> $base_map = "$base_path/data/empty.map";
>
> // The data I'm using (Statistics Canada's 2006 FSA files)
> $shape_path = "$base_path/data/zcta/zt08_d00_shp/";     // goofy path
> I'm too lazy to fix
> $shape_file = "gfsa000b06a_e";                          // works with or
> w/o the extension
> $shape_file_projection = "+proj=longlat +datum=NAD83";
>
> // The Extents (area) I want in latitude, longitude (Canada)
> list( $ex0, $ex1, $ex2, $ex3 ) = array(-140, 40, -50, 55 );
>
> // Describe the rest of my output
> $output_projection = '';
> $output_projection = "+proj=tcc +lon_0=90w +ellps=GRS80";
> $output_file_rel = "output/index2.png";
> $output_file_path = "$base_path/$output_file_rel";
> list($output_width, $output_height ) = array( 600, 500 );
>
>
>
> // Load MapScript extension
> if (!extension_loaded("MapScript"))
> dl('php_mapscript.'.PHP_SHLIB_SUFFIX);
>
> // add map
> $map = ms_newMapObj( $base_map );
>
> // tdw temp
> $map->setExtent( $ex0, $ex1, $ex2, $ex3 );
>
> // Set the shapepath
> $map->set( 'shapepath', $shape_path );
> // Set the output format and size
> $map->selectOutputFormat( 'png' );
> $map->setSize( $output_width, $output_height );
>
> // add new layer to map
> $layer = ms_newLayerObj($map);
> $layer->set("name", "foo");
> $layer->set("status", MS_ON);
> $layer->set("data", $shape_file );
> $layer->set("type", MS_SHAPE_POLYGON );
> $layer->setProjection( $shape_file_projection );
>
> // This line hides a bunch of errors that appear iff $output_projection
> is set
> $layer->set("template", "ttt");
> $layer->set("dump", "true");
>
> // add new class to new layer
> $class = ms_newClassObj($layer);
> $class->set("name", "foo");
>
> // add new style to new class
> $style = ms_newStyleObj($class);
> $style->color->setRGB(255, 0, 0);
> $style->outlinecolor->setRGB( 128,128,128 );
>
> if( $output_projection != '' ) {   // Project and Draw
>         // create new rect to query against the new layer
>         $rect = ms_newRectObj();
>         $rect->setExtent( $ex0, $ex1, $ex2, $ex3 );
>
>         // query new layer
>         $layer->queryByRect( $rect );
>         $map->queryByRect( $rect );
>
>         // set projection of output map
>         $map->setProjection($output_projection, MS_TRUE);
>
>         // draw
>         $image = $map->drawQuery();
> } else {      // Just draw the map
>         // draw
>         $image = $map->draw();
> }
>
> // Save the image
> $image->saveImage( $output_file_path );
>
> ?>
> <html>
> <body>
>         <img src="<?PHP print $output_file_rel; ?>">
> </body>
> </html>
> ---------------------------------------------------------------------
>
>
> Kralidis,Tom [Ontario] wrote:
>> I've added a small example at:
>>
>> http://trac.osgeo.org/mapserver/wiki/PHPMapscriptAddLayerQueryReproject
>>
>> Hope this helps.
>>
>> ..Tom
>>
>>
>>
>> -----Original Message-----
>> From: mapserver-users-bounces at lists.osgeo.org on behalf of Tim Wood
>> Sent: Sat 07-Feb-09 22:55
>> To: mapserver-users at lists.osgeo.org
>> 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
>>
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>




More information about the mapserver-users mailing list