MCPcopy Index your code
hub / github.com/MapServer/MapServer / msCalculateScale

Function msCalculateScale

mapscale.c:77–111  ·  view source on GitHub ↗

** Calculate the approximate scale based on a few parameters. Note that this assumes the scale is ** the same in the x direction as in the y direction, so run msAdjustExtent(...) first. */

Source from the content-addressed store, hash-verified

75** the same in the x direction as in the y direction, so run msAdjustExtent(...) first.
76*/
77int msCalculateScale(rectObj extent, int units, int width, int height, double resolution, double *scale)
78{
79 double md, gd, center_y;
80
81 /* if((extent.maxx == extent.minx) || (extent.maxy == extent.miny)) */
82 if(!MS_VALID_EXTENT(extent)) {
83 msSetError(MS_MISCERR, "Invalid image extent, minx=%lf, miny=%lf, maxx=%lf, maxy=%lf.", "msCalculateScale()", extent.minx, extent.miny, extent.maxx, extent.maxy);
84 return(MS_FAILURE);
85 }
86
87 if((width <= 0) || (height <= 0)) {
88 msSetError(MS_MISCERR, "Invalid image width or height.", "msCalculateScale()");
89 return(MS_FAILURE);
90 }
91
92 switch (units) {
93 case(MS_DD):
94 case(MS_METERS):
95 case(MS_KILOMETERS):
96 case(MS_MILES):
97 case(MS_NAUTICALMILES):
98 case(MS_INCHES):
99 case(MS_FEET):
100 center_y = (extent.miny+extent.maxy)/2.0;
101 md = (width-1)/(resolution*msInchesPerUnit(units, center_y)); /* remember, we use a pixel-center to pixel-center extent, hence the width-1 */
102 gd = extent.maxx - extent.minx;
103 *scale = gd/md;
104 break;
105 default:
106 *scale = -1; /* this is not an error */
107 break;
108 }
109
110 return(MS_SUCCESS);
111}
112
113double msInchesPerUnit(int units, double center_lat)
114{

Callers 12

msDrawScalebarFunction · 0.85
msPrepareImageFunction · 0.85
msLegendCalcSizeFunction · 0.85
mainFunction · 0.85
checkWebScaleFunction · 0.85
generateLegendTemplateFunction · 0.85
msWMSFeatureInfoFunction · 0.85
msMapSetExtentFunction · 0.85
php_mapscript.cFile · 0.85
map.cFile · 0.85
mapObj_prepareQueryFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msInchesPerUnitFunction · 0.85

Tested by

no test coverage detected