[mapserver-users] projection weirdness php_mapscript vs. mapserver itself
Alexander Mayrhofer
axelm-mapserver at nona.net
Thu Feb 28 22:41:52 PST 2008
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trace_icon_32.87_9.33_260x150_TEST.jpg
Type: image/jpeg
Size: 13250 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20080229/21a4973b/attachment.jpg>
More information about the MapServer-users
mailing list