[mapserver-commits] r9444 - in trunk/mapserver: . mapscript/php3
mapscript/swiginc
svn at osgeo.org
svn at osgeo.org
Mon Oct 12 15:56:11 EDT 2009
Author: aboudreault
Date: 2009-10-12 15:56:11 -0400 (Mon, 12 Oct 2009)
New Revision: 9444
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapscale.c
trunk/mapserver/mapscript/php3/php_mapscript.c
trunk/mapserver/mapscript/swiginc/mapzoom.i
trunk/mapserver/mapserver.h
Log:
Fixed mapObj.zoomScale() and mapobj.zoomRectangle() scaling problem in Mapscript (#3131)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2009-10-12 15:52:44 UTC (rev 9443)
+++ trunk/mapserver/HISTORY.TXT 2009-10-12 19:56:11 UTC (rev 9444)
@@ -15,6 +15,9 @@
Current Version (SVN trunk):
----------------------------
+- Fixed mapObj.zoomScale() and mapobj.zoomRectangle() scaling problem in
+ Mapscript (#3131)
+
- Few more fixes for high res output (#3157)
- Allow "DRIVER 'TEMPLATE'" or "DRIVER TEMPLATE" in output formats
Modified: trunk/mapserver/mapscale.c
===================================================================
--- trunk/mapserver/mapscale.c 2009-10-12 15:52:44 UTC (rev 9443)
+++ trunk/mapserver/mapscale.c 2009-10-12 19:56:11 UTC (rev 9444)
@@ -502,3 +502,84 @@
return(0);
}
+
+/************************************************************************/
+/* These two functions are used in PHP/Mapscript and Swig/Mapscript */
+/************************************************************************/
+
+/************************************************************************/
+/* double GetDeltaExtentsUsingScale(double scale, int units, */
+/* double centerLat, int width, */
+/* double resolution) */
+/* */
+/* Utility function to return the maximum extent using the */
+/* scale and the width of the image. */
+/* */
+/* Base on the function msCalculateScale (mapscale.c) */
+/************************************************************************/
+double GetDeltaExtentsUsingScale(double scale, int units, double centerLat, int width, double resolution)
+{
+ double md = 0.0;
+ double dfDelta = -1.0;
+
+ if (scale <= 0 || width <=0)
+ return -1;
+
+ switch (units)
+ {
+ case(MS_DD):
+ case(MS_METERS):
+ case(MS_KILOMETERS):
+ case(MS_MILES):
+ case(MS_INCHES):
+ case(MS_FEET):
+ /* remember, we use a pixel-center to pixel-center extent, hence the width-1 */
+ md = (width-1)/(resolution*msInchesPerUnit(units,centerLat));
+ dfDelta = md * scale;
+ break;
+
+ default:
+ break;
+ }
+
+ return dfDelta;
+}
+
+/************************************************************************/
+/* static double Pix2Georef(int nPixPos, int nPixMin, double nPixMax,*/
+/* double dfGeoMin, double dfGeoMax, */
+/* bool bULisYOrig) */
+/* */
+/* Utility function to convert a pixel pos to georef pos. If */
+/* bULisYOrig parameter is set to true then the upper left is */
+/* considered to be the Y origin. */
+/* */
+/************************************************************************/
+double Pix2Georef(int nPixPos, int nPixMin, int nPixMax,
+ double dfGeoMin, double dfGeoMax, int bULisYOrig)
+{
+ double dfWidthGeo = 0.0;
+ int nWidthPix = 0;
+ double dfPixToGeo = 0.0;
+ double dfPosGeo = 0.0;
+ double dfDeltaGeo = 0.0;
+ int nDeltaPix = 0;
+
+ dfWidthGeo = dfGeoMax - dfGeoMin;
+ nWidthPix = nPixMax - nPixMin;
+
+ if (dfWidthGeo > 0.0 && nWidthPix > 0)
+ {
+ dfPixToGeo = dfWidthGeo / (double)nWidthPix;
+
+ if (!bULisYOrig)
+ nDeltaPix = nPixPos - nPixMin;
+ else
+ nDeltaPix = nPixMax - nPixPos;
+
+ dfDeltaGeo = nDeltaPix * dfPixToGeo;
+
+ dfPosGeo = dfGeoMin + dfDeltaGeo;
+ }
+ return (dfPosGeo);
+}
Modified: trunk/mapserver/mapscript/php3/php_mapscript.c
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.c 2009-10-12 15:52:44 UTC (rev 9443)
+++ trunk/mapserver/mapscript/php3/php_mapscript.c 2009-10-12 19:56:11 UTC (rev 9444)
@@ -485,10 +485,6 @@
DLEXPORT void php_ms_IO_getStdoutBufferBytes(INTERNAL_FUNCTION_PARAMETERS);
-static double GetDeltaExtentsUsingScale(double dfMinscale, int nUnits,
- double dCenterLat,
- int nWidth, double resolution);
-
/*=====================================================================
* PHP Dynamically Loadable Library stuff
*====================================================================*/
@@ -2356,46 +2352,6 @@
/* ==================================================================== */
/************************************************************************/
-/* static double Pix2Georef(int nPixPos, int nPixMin, double nPixMax,*/
-/* double dfGeoMin, double dfGeoMax, */
-/* bool bULisYOrig) */
-/* */
-/* Utility function to convert a pixel pos to georef pos. If */
-/* bULisYOrig parameter is set to true then the upper left is */
-/* considered to be the Y origin. */
-/* */
-/************************************************************************/
-static double Pix2Georef(int nPixPos, int nPixMin, int nPixMax,
- double dfGeoMin, double dfGeoMax, int bULisYOrig)
-
-{
- double dfWidthGeo = 0.0;
- int nWidthPix = 0;
- double dfPixToGeo = 0.0;
- double dfPosGeo = 0.0;
- double dfDeltaGeo = 0.0;
- int nDeltaPix = 0;
-
- dfWidthGeo = dfGeoMax - dfGeoMin;
- nWidthPix = nPixMax - nPixMin;
-
- if (dfWidthGeo > 0.0 && nWidthPix > 0)
- {
- dfPixToGeo = dfWidthGeo / (double)nWidthPix;
-
- if (!bULisYOrig)
- nDeltaPix = nPixPos - nPixMin;
- else
- nDeltaPix = nPixMax - nPixPos;
-
- dfDeltaGeo = nDeltaPix * dfPixToGeo;
-
- dfPosGeo = dfGeoMin + dfDeltaGeo;
- }
- return (dfPosGeo);
-}
-
-/************************************************************************/
/* map->zoomPoint() */
/* */
/* Parmeters are : */
@@ -2848,7 +2804,6 @@
(int)pHeight->value.lval,
poGeorefExt->miny, poGeorefExt->maxy, 1);
-
msAdjustExtent(&oNewGeorefExt, self->width, self->height);
/* -------------------------------------------------------------------- */
@@ -2931,7 +2886,7 @@
self->extent.miny = oNewGeorefExt.miny;
self->extent.maxx = oNewGeorefExt.maxx;
self->extent.maxy = oNewGeorefExt.maxy;
-
+
self->cellsize = msAdjustExtent(&(self->extent), self->width,
self->height);
dfDeltaX = self->extent.maxx - self->extent.minx;
@@ -16811,45 +16766,6 @@
RETURN_DOUBLE(dfScale);
}
-/************************************************************************/
-/* static double GetDeltaExtentsUsingScale(double dfMinscale, int nUnits,*/
-/* int nWidth) */
-/* */
-/* Utility function to return the maximum extent using the */
-/* scale and the width of the image. */
-/* */
-/* Base on the function msCalculateScale (mapscale.c) */
-/************************************************************************/
-static double GetDeltaExtentsUsingScale(double dfScale, int nUnits,
- double dCenterLat,
- int nWidth, double resolution)
-{
- double md = 0.0;
- double dfDelta = -1.0;
-
- if (dfScale <= 0 || nWidth <=0)
- return -1;
-
- switch (nUnits)
- {
- case(MS_DD):
- case(MS_METERS):
- case(MS_KILOMETERS):
- case(MS_MILES):
- case(MS_INCHES):
- case(MS_FEET):
- /* remember, we use a pixel-center to pixel-center extent, hence the width-1 */
- md = (nWidth-1)/(resolution*msInchesPerUnit(nUnits,dCenterLat));
- dfDelta = md * dfScale;
- break;
-
- default:
- break;
- }
-
- return dfDelta;
-}
-
/**********************************************************************
* ms_tokenizeMap()
*
Modified: trunk/mapserver/mapscript/swiginc/mapzoom.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/mapzoom.i 2009-10-12 15:52:44 UTC (rev 9443)
+++ trunk/mapserver/mapscript/swiginc/mapzoom.i 2009-10-12 19:56:11 UTC (rev 9444)
@@ -116,8 +116,11 @@
/* possible using the mincale set in the .map. */
/* ============================================================ */
if (self->web.minscaledenom > 0 && dfNewScale < self->web.minscaledenom && zoomfactor > 1) {
- dfDeltaExt = (self->web.minscaledenom * self->width)/(self->resolution * msInchesPerUnit(self->units,0));
- /* dfDeltaExt = GetDeltaExtentsUsingScale(self->web.minscaledenom, self->units, dfGeoPosY, self->width, self->resolution); */
+ /* To be consistent in swig mapscript and PHP mapscript,
+ use the same function to calculate the delta extents. */
+ dfDeltaExt = GetDeltaExtentsUsingScale(self->web.minscaledenom, self->units, dfGeoPosY,
+ self->width, self->resolution);
+
if (dfDeltaExt > 0.0) {
oNewGeorefExt.minx = dfGeoPosX - (dfDeltaExt/2);
oNewGeorefExt.miny = dfGeoPosY - (dfDeltaExt/2);
@@ -227,7 +230,7 @@
msSetError(MS_MISCERR, "image rectangle minx >= maxx", "mapscript::mapObj::zoomRectangle()");
return MS_FAILURE;
}
- if (poPixRect->maxy >= poPixRect->miny) {
+ if (poPixRect->miny >= poPixRect->maxy) {
msSetError(MS_MISCERR, "image rectangle maxy >= miny", "mapscript::mapObj::zoomRectangle()");
return MS_FAILURE;
}
@@ -262,10 +265,10 @@
dX = dfDeltaX/((double)width);
dY = dfDeltaY/((double)height);
- oNewGeorefExt.minx = poGeorefExt->minx + dX * (double)poPixRect->minx;
- oNewGeorefExt.miny = poGeorefExt->maxy - dY * (double)poPixRect->miny;
- oNewGeorefExt.maxx = poGeorefExt->minx + dX * (double)poPixRect->maxx;
- oNewGeorefExt.maxy = poGeorefExt->maxy - dY * (double)poPixRect->maxy;
+ oNewGeorefExt.minx = Pix2Georef((int)poPixRect->minx, 0, width, poGeorefExt->minx, poGeorefExt->maxx, 0);
+ oNewGeorefExt.maxx = Pix2Georef((int)poPixRect->maxx, 0, width, poGeorefExt->minx, poGeorefExt->maxx, 0);
+ oNewGeorefExt.miny = Pix2Georef((int)poPixRect->miny, 0, height, poGeorefExt->miny, poGeorefExt->maxy, 1);
+ oNewGeorefExt.maxy = Pix2Georef((int)poPixRect->maxy, 0, height, poGeorefExt->miny, poGeorefExt->maxy, 1);
msAdjustExtent(&oNewGeorefExt, self->width, self->height);
@@ -281,10 +284,11 @@
if (self->web.minscaledenom > 0 && dfNewScale < self->web.minscaledenom) {
dfMiddleX = oNewGeorefExt.minx + ((oNewGeorefExt.maxx - oNewGeorefExt.minx)/2);
dfMiddleY = oNewGeorefExt.miny + ((oNewGeorefExt.maxy - oNewGeorefExt.miny)/2);
-
- dfDeltaExt = (self->web.minscaledenom * self->width) / (self->resolution * msInchesPerUnit(self->units,0));
- /* dfDeltaExt = GetDeltaExtentsUsingScale(self->web.minscaledenom, self->units, dfMiddleY, self->width, self->resolution); */
+ /* To be consistent in swig mapscript and PHP mapscript,
+ use the same function to calculate the delta extents. */
+ dfDeltaExt = GetDeltaExtentsUsingScale(self->web.minscaledenom, self->units, dfMiddleY, self->width, self->resolution);
+
if (dfDeltaExt > 0.0) {
oNewGeorefExt.minx = dfMiddleX - (dfDeltaExt/2);
oNewGeorefExt.miny = dfMiddleY - (dfDeltaExt/2);
@@ -331,7 +335,7 @@
self->extent.miny = oNewGeorefExt.miny;
self->extent.maxx = oNewGeorefExt.maxx;
self->extent.maxy = oNewGeorefExt.maxy;
-
+
self->cellsize = msAdjustExtent(&(self->extent), self->width, self->height);
dfDeltaX = self->extent.maxx - self->extent.minx;
dfDeltaY = self->extent.maxy - self->extent.miny;
@@ -439,7 +443,9 @@
else
nTmp = self->height;
- dfDeltaExt=scale*nTmp/(self->resolution*msInchesPerUnit(self->units,0));
+ /* To be consistent in swig mapscript and PHP mapscript,
+ use the same function to calculate the delta extents. */
+ dfDeltaExt = GetDeltaExtentsUsingScale(scale, self->units, dfGeoPosY, nTmp, self->resolution);
if (dfDeltaExt > 0.0) {
oNewGeorefExt.minx = dfGeoPosX - (dfDeltaExt/2);
@@ -476,7 +482,9 @@
/* possible using the mincale set in the .map. */
/* ============================================================ */
if (self->web.minscaledenom > 0 && dfNewScale < self->web.minscaledenom && dfCurrentScale > dfNewScale) {
- dfDeltaExt=scale*nTmp/(self->resolution*msInchesPerUnit(self->units,0));
+ /* To be consistent in swig mapscript and PHP mapscript,
+ use the same function to calculate the delta extents. */
+ dfDeltaExt = GetDeltaExtentsUsingScale(scale, self->units, dfGeoPosY, nTmp, self->resolution);
if (dfDeltaExt > 0.0) {
oNewGeorefExt.minx = dfGeoPosX - (dfDeltaExt/2);
oNewGeorefExt.miny = dfGeoPosY - (dfDeltaExt/2);
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2009-10-12 15:52:44 UTC (rev 9443)
+++ trunk/mapserver/mapserver.h 2009-10-12 19:56:11 UTC (rev 9444)
@@ -1692,6 +1692,8 @@
MS_DLL_EXPORT imageObj *msDrawScalebar(mapObj *map); /* in mapscale.c */
MS_DLL_EXPORT int msCalculateScale(rectObj extent, int units, int width, int height, double resolution, double *scaledenom);
+MS_DLL_EXPORT double GetDeltaExtentsUsingScale(double scale, int units, double centerLat, int width, double resolution);
+MS_DLL_EXPORT double Pix2Georef(int nPixPos, int nPixMin, int nPixMax, double dfGeoMin, double dfGeoMax, int bULisYOrig);
MS_DLL_EXPORT double msInchesPerUnit(int units, double center_lat);
MS_DLL_EXPORT int msEmbedScalebar(mapObj *map, imageObj *img);
More information about the mapserver-commits
mailing list