Mapscript Re-Projection on-the-fly (solved)

Stefan Schwarzer stefan.schwarzer at GRID.UNEP.CH
Thu Aug 24 04:36:45 EDT 2006


Jacob, Nicol,

Ahhhh.... bit irritating these different coding possibilities...

Ok, I met the original definition to all layers AND the map file:
	
	PROJECTION
		'init=epsg:4326'
	END

and when using

	$newproj="proj=robin,lon_0=0,x_0=0,y_0=0"; // projection string of  
your new projection
	$map->setProjection($newproj,MS_TRUE);

it indeed works!

Great, thanks a lot guys for that help!!!

Best regards,

Stef
	


On Aug 24, 2006, at 10:05 AM, Delfos, Jacob wrote:

> Hi Stefan,
>
> Yes, you do have to specify which projection each layer is in,  
> otherwise when they are reprojected you will run into trouble (if  
> it doesn't know where to reproject FROM, it won't be able to do i).  
> It's not too hard, though.
>
> You should not have to recalculate the extent; it should be  
> automatic. Definitely don't try to change the numbers (coordinates)  
> without changing the projection (that would be bad).
>
> Try this:
>
> $newproj="proj=robin,lon_0=0,x_0=0,y_0=0"; // projection string of  
> your new projection
> $map->setProjection($newproj,MS_TRUE);
>
> I think that ought to be all.  The MS_TRUE makes it pick the best  
> fit to the current extent in the new projection. Make sure your  
> projection string is valid.
>
> regards,
>
> Jacob
>
>
>
> From: UMN MapServer Users List [mailto:MAPSERVER- 
> USERS at LISTS.UMN.EDU] On Behalf Of Stefan Schwarzer
> Sent: 24 August 2006 15:35
> To: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: Re: [UMN_MAPSERVER-USERS] Mapscript Re-Projection on-the-fly
>
> Jacob & Nicol,
>
> thanks for your feedback.
>
> But I am still struggling. Just to clarify: I wonna reproject not  
> individual layers, but my whole map.
>
> Jacob, does "For this, it is required that your layer has a  
> projection object with the native projection of that layer." that  
> mean that for each single layer I have to specify the original  
> projection? (Geographic in my case)
>
> As Nicol stated I need to "recalculate" the extent, at least when  
> using different units (going from DD to Meters).
>
> But then, I found that piece of code (slightly changed):
>
> $newproj=ms_newprojectionObj("proj=robin,lon_0=0,x_0=0,y_0=0");
> $latlon=ms_newprojectionObj 
> ("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
> $oldext=ms_newRectObj();
> $oldext->setextent(-180,-90,180,90);  //this is the extent of my  
> map in geographic
> $oldext->project($latlon,$newproj);  //reproject to Robinson
> $map->setextent($oldext->minx,$oldext->miny,$oldext->maxx,$oldext- 
> >maxy);  //set the new map extent
>
> And another one going like this:
>
> $projInObj = ms_newProjectionObj( "+proj=tmerc ".
>   "+lat_0=49 ".
>   "+lon_0=-2 ".
>   "+k=0.999601 ".
>   "+x_0=400000 ".
>   "+y_0=-100000 ".
>   "+ellps=airy ".
>   "+towgs84=375,-111,431,0,0,0,0");
>
> with this info in the mapscript documentation...
>  int setProjection(string proj_params, boolean bSetUnitsAndExtents)
>         Set map projection and coordinate system.  Parameters are  
> given as
>         a single string of comma-delimited PROJ.4 parameters.
>         The argument : bSetUnitsAndExtents is used to automatically  
> update
>         the map units and extents based on the new projection.  
> Possible
>         values are MS_TRUE and MS_FALSE. By defualt it is set at  
> MS_FALSE
>
> So, what should I use? And where is coming the
>
> $map -> setProjection
>
> into play?
>
> Thanks for any clarification.
>
> Stefan
>
>
>
> On Aug 24, 2006, at 7:59 AM, Delfos, Jacob wrote:
>
>> Stefan,
>>
>> Your question is not entirely clear. You can not re-project an  
>> individual layer on-the-fly, because php_mapscript does not re- 
>> write the dataset (hence its projection will always be the same);  
>> you CAN however change the projection of the map (using  
>> setProjection, as you did), which means all layers in the map get  
>> re-projected (the dataset     remains unchanged, though). For  
>> this, it is required that your layer has a projection object with  
>> the native projection of that layer. This will cause the layer to  
>> be reprojected along with the map. Is this what you are trying to do?
>>
>> You *may* have to save your mapfile, or your session, in order for  
>> it to take effect, depending on your setup.
>>
>> regards,
>>
>> Jacob
>>
>>
>> From: UMN MapServer Users List [mailto:MAPSERVER- 
>> USERS at LISTS.UMN.EDU] On Behalf Of Stefan Schwarzer
>> Sent: 24 August 2006 13:45
>> To: MAPSERVER-USERS at LISTS.UMN.EDU
>> Subject: Re: [UMN_MAPSERVER-USERS] Mapscript Re-Projection on-the-fly
>>
>> Hey,
>>
>> I can't imagine that such a question stays unanswered in the  
>> mapserver community...
>>
>> I meanwhile added a:
>>
>> $map -> setProjection("init=epsg:26711");
>>
>> to my code, but nothing happens - meaning: no error message but no  
>> reprojection either.
>>
>> Can anyone help me out?
>>
>> Thanks in advance.
>>
>> Stefan
>>
>>
>> On Aug 22, 2006, at 10:47 AM, Stefan Schwarzer wrote:
>>
>>> Gush,
>>>
>>> I couldn't find any precise information about how to re-project  
>>> layers on-the-fly via PHP Mapscript. Here and there (via  
>>> MailingList and Google) bits and pieces, but altogether it didn't  
>>> help me a lot. Though I would have said that this is a basic  
>>> question. But perhaps too basic, so everbody finds out by himself?
>>>
>>> So, can anyone let me know - giving a coding example - how to re- 
>>> project a mapfile on-the-fly from for example Lat/Long (global  
>>> view) to Lambert or Robin?
>>>
>>> Thanks a lot for your help!
>>>
>>>
>>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060824/ba702352/attachment.html


More information about the mapserver-users mailing list