** 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. */
| 75 | ** the same in the x direction as in the y direction, so run msAdjustExtent(...) first. |
| 76 | */ |
| 77 | int 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 | |
| 113 | double msInchesPerUnit(int units, double center_lat) |
| 114 | { |
no test coverage detected