Opened 15 years ago

Closed 15 years ago

#3131 closed defect (fixed)

Bug with mapObj.zoomScale() does not set the scale to the desired value.

Reported by: kfaschoway Owned by: aboudreault
Priority: normal Milestone: 5.6 release
Component: MapScript-PHP Version: 5.4
Severity: normal Keywords:
Cc: aboudreault, dmorissette, assefa

Description

The function mapObj.zoomScale(...) does not set the scale to the desired value. If the desired scale is 20,000,000 then the function would set the scale to something slightly different like 20,000,063 after the function call.

Attachments (2)

zoomScaleTestData.zip (4.2 KB ) - added by kfaschoway 15 years ago.
MapServerTest.zip (199.9 KB ) - added by kfaschoway 15 years ago.

Download all attachments as: .zip

Change History (21)

comment:1 by sdlime, 15 years ago

Component: MapServer C LibraryMapScript-PHP
Owner: changed from sdlime to mapserverbugs

Assuming this is in PHP/MapScript. Those functions all originated there... I would think this is rounding error related. Given that MapServer requires square pixels it may not be possible to achieve a scale exactly with a given aspect ratio.

Steve

comment:2 by dmorissette, 15 years ago

Cc: aboudreault added
Milestone: 5.6 release

Can you please provide a test case to reproduce? A small mapfile + PHP script should be enough in this case.

BTW, you marked this ticket as version 5.2. Is this really the version you are using? Would it be possible for you to retest this with a more recent version?

comment:3 by kfaschoway, 15 years ago

Version: 5.25.4

We retested with version 5.4.2 and got the same result. We are in the process of creating a suitable test case.

comment:4 by aboudreault, 15 years ago

kfaschoway, I would like to check that ticket. Is your test case ready? Thanks!

by kfaschoway, 15 years ago

Attachment: zoomScaleTestData.zip added

comment:5 by kfaschoway, 15 years ago

aboudreault, I have attached test data. Let me know if you need anything else.

comment:6 by dmorissette, 15 years ago

Cc: dmorissette assefa added
Owner: changed from mapserverbugs to aboudreault

comment:7 by aboudreault, 15 years ago

Is my test script is ok? Is it supposed to fail?

$szMapFile =  "./test.map";
$oMap = ms_newMapObj($szMapFile);
$oMap->draw();
echo "Current Scale: ".$oMap->scaledenom."<br/>";
$p1 = ms_newPointObj();
$p1->setXY(100,50);
$r = ms_newRectObj();
$r->setextent(-1541932.35654056,-1756849.79208326,2966774.81854162, 3051857.38299892);
$oMap->zoomScale(20000000, $p1, 500,700, $r);
$oMap->draw();
echo "Modified Scale: ".$oMap->scaledenom;

output

Current Scale: 28452741.021
Modified Scale: 20000000

by kfaschoway, 15 years ago

Attachment: MapServerTest.zip added

comment:8 by kfaschoway, 15 years ago

I have attached a VS2005 C# app that does similar to your php code but for some reason the scaledenom does not get set to the desired value of 20,000,000. It returns as 20,040,080.1603206.

comment:9 by dmorissette, 15 years ago

It is possible that PHP MapScript and SWIG MapScript handle things differently. Alan, can you redo the test with Python? That should call more or less the same SWIG wrapper code as C#.

comment:10 by dmorissette, 15 years ago

May I also ask why this was filed as a PHP MapScript ticket if it happens with C#?

comment:11 by kfaschoway, 15 years ago

I started it accidentally at MapServer C Library...look at comment 1.

comment:12 by dmorissette, 15 years ago

Ah, I see that Steve switched the component. Sorry.

comment:13 by aboudreault, 15 years ago

I confirm that the problem is related to the swig related bindings. Here's the python output:

Current Scale: 28452741.020975
Modified scale: 20040080.160321

comment:14 by sdlime, 15 years ago

The swig stuff was a straight port of the PHP functions by Sean way back. Does PHP not return the same values as the swig bindings?

Steve

comment:15 by aboudreault, 15 years ago

Steve, swig and PHP do not return the same values. The problem is that the dfDeltaExt is not calculated as it is in PHP. In PHP (PHP uses its own function to calculate the delta extents using scale: I modified the code below to easily compare it to swig):

dfDeltaExt=scale*((nTmp-1)/(self->resolution*msInchesPerUnit(self->units,dfGeoPosY)));

in the swig function:

dfDeltaExt=scale*nTmp/(self->resolution*msInchesPerUnit(self->units,0));

Is it ok to change the zoomScale function (and all other functions in mapzoom.i: zoomRectangle, etc.) to do the same calcul as PHP does (which I assume the right result) ?

comment:16 by aboudreault, 15 years ago

FYI, I've already done the test and doing that change make the proper scaledenom after the function call. (Tested in Python).

comment:17 by sdlime, 15 years ago

Keeping zoomScale consistent across the board is important so your change makes perfect sense to me. We should note the need to change those functions in both places somehow. Perhaps comments in both environments?

Steve

comment:18 by aboudreault, 15 years ago

The Delta Extents is now calculated the same way as php does. I've also fixed the zoomRectangle function, which had the same bug and also an error check mistake.

Fixed and committed in r9444.

comment:19 by aboudreault, 15 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.