Quantcast

projection weirdness php_mapscript vs. mapserver itself

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

projection weirdness php_mapscript vs. mapserver itself

Alexander Mayrhofer

[ this went to another mapserver list this morning - so sorry if you
read that before ]

Hi,

I've found a projection weirdness in php_mapscript vs. Mapserver, and
i'd appreciate any hint (i'm pretty desperate already :-/ )..

i'm using php_mapscript to load a mapfile, and put a marker on the map.
The map (and background raster) is in the (in)famous "Google"
projection, while marker data is in WGS84.

During debugging i noticed that using the _same_ coordinates and
projection, i get two different marker positions on the map, depending
whether i reproject the marker "manually" using php_mapscript or
via Mapserver itself...

The attached example (also available at
http://map.timatio.com/trace_icon_32.87_9.33_260x150_TEST.jpg ) shows
the problem - the "upper" marker is reprojected using Mapserver, and the
"lower" using php_mapscript, even though they use the same coordinates
and projection. The further away from the equator, the
larger the offset becomes (you can play around with the lat/long
parameters after "_icon_" in the above URL).

The respective lines of code look like this (i _think_ the projection is
absolutely identical for both cases - compare the mapscript lines with
the mapfile below..):

       // manual reprojection - weirdness avoidance
       $in_proj = ms_newProjectionObj("proj=longlat, ellps=WGS84,
datum=WGS84, no_defs");
       $out_proj = ms_newProjectionObj("proj=merc, a=6378137, b=6378137,
lat_ts=0.0, lon_0=0.0, x_0=0.0, y_0=0, k=1.0, units=m, nadgrids=@null,
no_defs");
       $centerpoint = ms_newPointObj();
       $centerpoint->setXY($args['lon'], $args['lat']);
       $centerpoint->project($in_proj, $out_proj);

       ...

       // set marker in "manually" projected layer
       $center_layer = $map->getLayerByName("center");
       $point = ms_newPointObj();
       $point->setXY($centerpoint->x, $centerpoint->y);
       $line = ms_newLineObj();
       $line->add($point);
       $shp = ms_newShapeObj(MS_SHAPE_POINT);
       $shp->add($line);
       $center_layer->addFeature($shp);

       // set marker for "mapserver projected" layer
       $centertest_layer = $map->getLayerByName("centertest");
       $pointtest = ms_newPointObj();
       $pointtest->setXY($args['lon'], $args['lat']);
       $linetest = ms_newLineObj();
       $linetest->add($pointtest);
       $shptest = ms_newShapeObj(MS_SHAPE_POINT);
       $shptest->add($linetest);
       $centertest_layer->addFeature($shptest);

And the mapfile looks like this:

#
# Start of map file
#

NAME micromap
STATUS ON
SIZE 176 116
UNITS meters
DEBUG ON
OUTPUTFORMAT
     NAME jpeg
     FORMATOPTION "QUALITY=95"
     FORMATOPTION "INTERLACE=OFF"
     DRIVER "GD/JPEG"
END
PROJECTION
     "proj=merc"
     "a=6378137"
     "b=6378137"
     "lat_ts=0.0"
     "lon_0=0.0"
     "x_0=0.0"
     "y_0=0"
     "k=1.0"
     "units=m"
     "nadgrids=@null"
     "no_defs"
END
EXTENT -300000 -200000 300000 200000
SHAPEPATH "/data/gis/NE2/"
IMAGECOLOR 204 221 238
IMAGETYPE png24

FONTSET /data/gis/brd/fonts.list

SYMBOL
     NAME "punkterl"
     TYPE PIXMAP
     IMAGE assets/punkterl.png
LAYER
     NAME "NE2_modis3"
     STATUS ON
     TILEINDEX "/data/gis/NE2/NE2-modis3-tileindex.shp"
     TILEITEM "Location"
     TYPE RASTER
END

LAYER
     NAME "centertest"
     STATUS on
     TYPE point
     TRANSFORM true
     POSTLABELCACHE true
     PROJECTION
       "proj=latlong"
       "datum=WGS84"
       "ellps=WGS84"
       "no_defs"
     END
     CLASS
       STYLE
         SYMBOL "punkterl"
       END
       LABEL
         ANGLE 0
         SIZE 9
         COLOR 0 0 0
         TYPE truetype
         FONT dejavu
         POSITION uc
         OFFSET 0 2
         FORCE true
         BUFFER 3
         MINFEATURESIZE 10
       END
     END
     TRANSPARENCY alpha
END

LAYER
     NAME "center"
     STATUS on
     TYPE point
     TRANSFORM true
     POSTLABELCACHE true
     CLASS
       STYLE
         SYMBOL "punkterl"
       END
       LABEL
         ANGLE 0
         SIZE 9
         COLOR 0 0 0
         TYPE truetype
         FONT dejavu
         POSITION uc
         OFFSET 0 2
         FORCE true
         BUFFER 3
         MINFEATURESIZE 10
       END
     END
     TRANSPARENCY alpha
END

END


Notice that the projection is (imho) absolutely identical - The
"correct" reprojection seems to be the "manual" reprojection - it aligns
with the background map that was reprojected with gdalwarp...

Mapserver version is 4.10, proj version is 4.4.9d-2 - I do appreciate
any hints on what i could be doing wrong..

thanks,

Alex



trace_icon_32.87_9.33_260x150_TEST.jpg (17K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: projection weirdness php_mapscript vs. mapserver itself

Frank Warmerdam
Alexander Mayrhofer wrote:

> During debugging i noticed that using the _same_ coordinates and
> projection, i get two different marker positions on the map, depending
> whether i reproject the marker "manually" using php_mapscript or
> via Mapserver itself...
>
> The attached example (also available at
> http://map.timatio.com/trace_icon_32.87_9.33_260x150_TEST.jpg ) shows
> the problem - the "upper" marker is reprojected using Mapserver, and the
> "lower" using php_mapscript, even though they use the same coordinates
> and projection. The further away from the equator, the
> larger the offset becomes (you can play around with the lat/long
> parameters after "_icon_" in the above URL).
>
> The respective lines of code look like this (i _think_ the projection is
> absolutely identical for both cases - compare the mapscript lines with
> the mapfile below..):
>
>       // manual reprojection - weirdness avoidance
>       $in_proj = ms_newProjectionObj("proj=longlat, ellps=WGS84,
> datum=WGS84, no_defs");
>       $out_proj = ms_newProjectionObj("proj=merc, a=6378137, b=6378137,
> lat_ts=0.0, lon_0=0.0, x_0=0.0, y_0=0, k=1.0, units=m, nadgrids=@null,
> no_defs");

Alexander,

First, I wish I could convince people to use the 'new style' projection
definitions!  eg. "+proj=merc +a=..."  The multiline/comma based approach
can be flakey in surprising ways.

The problem is clearly that one mechanism is apply an ellipsoid based
transformation while the other is using the @null transformation.  The
question then is why.

Some parsing weirdness breaking the nadgrids=@null might be one
explanation though I don't see any obvious issue with your definitions
so this is a long shot.

Another might be if different versions of PROJ.4 are being used in
MapServer and your php mapscript.  Ellipsoid conversion behavior
changed dramatically between PROJ 4.5.0 and 4.6.0.  But this is a
bit of a long shot too since your definition is explicit about using
@null which should work the same in either version.

The last is whether or not the null file is being found.  Normally this
is done via the PROJ_LIB environment variable.  Keep in mind that a
PROJ_LIB setting in your apache .conf for cgi's won't apply to php_mapscript
run as a non-cgi component.  Perhaps you could try setting this as a
system environment variable or even remove the null file and see if
both start behaving the same.

Good luck,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org
Loading...