Where are you setting the map size? $map->setSize($pwide,$ptall);
You may need to set the size of the map before you set the extents. Paul On Oct 26, 2009, at 11:44 AM, Chuck Jungmann wrote: > I am using MapScript with PHP because I want to be able to request a > map > with a url, change the content-type and send saveImage directly to > STDOUT. > > An example (relative) URL: > map.php?lat=42.056542&lon=-88.035765&ext=300&pwide=500&ptall=500 > > Where "ext" is the width, in meters, on the ground (difference in > longitude), "ptall" and "pwide" are the pixel dimensions of the > desired > map bitmap. If my server returns the map image I request, I can have > the client calculate the coordinates of any pixel on the map image > without having to bother the server. > > The server uses pwide/ptall and ext to determine difference in > latitude, > then the corners of the rectangle for MapObj::setextent(). > > Before I got your response, I was doing everything in lat/lon > coordinates, but something in your note made me realize that I should > use the native projection which is in meters for fewer calculations > and > an easier set of numbers to check the output. > > Here is the stripped-out code (functions merged, error-checking > removed): > > // load a minimal map, add layer with specific map: > $map = ms_newMapObj("/mapdata/minmap.map"); > $map->setProjection("init=epsg:26916"); > $lay = ms_newLayerObj($map); > $lay->set("name", "tempRaster"); > $lay->set("status", MS_ON); > $lay->set("type", MS_LAYER_RASTER); > $lay->set("data", "taxmap.tif"); > $lay->setProjection("init=epsg:26916"); > > // projection objects for converting point > $projlatlon = ms_newprojectionobj("proj=latlong"); > $proj26916 = ms_newprojectionobj("init=epsg:26916"); > > $pt = ms_newPointObj(); > $pt->setXY($lon,$lat); > $pt->project($projlatlon, $proj26916); > > $halfTall = $ext * $pwide / $ptall / 2; > $halfWide = $ext / 2; > > $map->setextent($pt->x-$halfWide, $pt->y-$halfTall, $pt->x+$halfWide, > $pt->y+$halfTall); > > Given the example above, the extent values I use are: > 414145.897891, 4656422.994605, 414445.897891, 4656722.994605, > exactly 300 meters X and Y. > > Immediately after $map->setextent(), I look at the values of > $map->extent and the values are: > 414095.793507, 4656422.994605, 414496.002275, 4656722.994605 > the differences are 400.21 X, 300 Y. 4/3 is familiar as screen ratio, > but I don't see why that would apply here. > > Here is the .tfw file for the map (confirming square pixels): > 0.205001999999928690 > 0.0 > 0.0 > -0.205001999999928690 > 413698.77641943324 > 4656861.2550850855 > > Thanks for your response. I apologize for not including all this > information in my first note, but too many times I have spent a lot of > time writing a note like this only to get no responses. > > Chuck Jungmann > > > > > > My MapServer version info: > MapServer version 5.0.3 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP > OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE > SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER > SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=FASTCGI > SUPPORTS=THREADS SUPPORTS=GEOS INPUT=EPPL7 INPUT=POSTGIS INPUT=OGR > INPUT=GDAL INPUT=SHAPEFILE > > > > On Sun, 2009-10-25 at 01:06 -0400, Stephen Woodbridge wrote: >> Chuck Jungmann wrote: >>> I am a new user of MapServer, using version 5.0.3 from the Ubuntu >>> repositories. I attempted to compile everything from source, had >>> some >>> trouble, then decided to use the repository shortcut at least >>> until I >>> understood how the application works. >>> >>> I am writing an application where the browser requests a map by >>> setting >>> the src attribute of an img object. Identifying locations on the >>> resulting map requires that the application knows the extent. >>> >>> I calculate the extent of the map from various values, and use the >>> same >>> algorithms on the server so the browser and the server agree on the >>> dimensions without having to negotiate. However, when I request >>> the map >>> from MapServer, the extent of the resulting map is always larger >>> (both x >>> and y dimensions) than what I requested, although still centered >>> on the >>> same point. >>> >>> Is this behavior normal (I don't want to beat my head against the >>> wall >>> searching for an irrelevant math error)? Is there some setting that >>> might cause MapServer to more closely match my requested extent? >>> Could >>> this be an error that was fixed in a more recent version of >>> MapServer? >>> >>> Any words of wisdom would be appreciated. >> >> Chuck, >> >> There are a number of conditions that may make mapserver checnge the >> extents requested. >> >> 1) mapserver assumes square pixels, so if you ask for an extents that >> has a different aspect ratio than that of you image size then >> mapserver >> will make adjusts. >> >> 2) if you ask for extents and a scale, I think, mapserver will use >> the >> extents to determine the center and then adjust the extents to the >> scale >> >> Are you using the CGI interface? what does you request look like? You >> need to give us more concrete examples that we can try here to test >> out >> and explain what is happening. What version of mapserver are you >> using? >> >> /path/to/mapserv -v >> >> Will report how it was build with options and version number. >> >> -Steve W. >> > > _______________________________________________ > mapserver-users mailing list > mapserver-users@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/mapserver-users _______________________________________________ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users