Beispiel #1
0
/*
** 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.
*/
int msCalculateScale(rectObj extent, int units, int width, int height, double resolution, double *scale)
{
    double md, gd, center_y;

    /* if((extent.maxx == extent.minx) || (extent.maxy == extent.miny))   */
    if(!MS_VALID_EXTENT(extent)) {
        msSetError(MS_MISCERR, "Invalid image extent, minx=%lf, miny=%lf, maxx=%lf, maxy=%lf.", "msCalculateScale()", extent.minx, extent.miny, extent.maxx, extent.maxy);
        return(MS_FAILURE);
    }

    if((width <= 0) || (height <= 0)) {
        msSetError(MS_MISCERR, "Invalid image width or height.", "msCalculateScale()");
        return(MS_FAILURE);
    }

    switch (units) {
    case(MS_DD):
    case(MS_METERS):
    case(MS_KILOMETERS):
    case(MS_MILES):
    case(MS_NAUTICALMILES):
    case(MS_INCHES):
    case(MS_FEET):
        center_y = (extent.miny+extent.maxy)/2.0;
        md = (width-1)/(resolution*msInchesPerUnit(units, center_y)); /* remember, we use a pixel-center to pixel-center extent, hence the width-1 */
        gd = extent.maxx - extent.minx;
        *scale = gd/md;
        break;
    default:
        *scale = -1; /* this is not an error */
        break;
    }

    return(MS_SUCCESS);
}
Beispiel #2
0
int msMapSetExtent( mapObj *map,
                    double minx, double miny, double maxx, double maxy)
{

  map->extent.minx = minx;
  map->extent.miny = miny;
  map->extent.maxx = maxx;
  map->extent.maxy = maxy;

  if (!MS_VALID_EXTENT(map->extent)) {
    msSetError(MS_MISCERR, "Given map extent is invalid. Check that it " \
               "is in the form: minx, miny, maxx, maxy", "setExtent()");
    return MS_FAILURE;
  }

  map->cellsize = msAdjustExtent(&(map->extent), map->width,
                                 map->height);

  /* if the map size is also set, recompute scale, ignore errors? */
  if( map->width != -1 || map->height != -1 )
    msCalculateScale(map->extent, map->units, map->width, map->height,
                     map->resolution, &(map->scaledenom));

  return msMapComputeGeotransform( map );
}