2

I am trying to figure out what is the conversion formula between scale and resolution used by GeoServer, specifically when creating a new gridset for Tile Caching. One would expect that the conversion formula for a given resolution expressed in m/px would be:

ScaleDenominator = Resolution * (PPI / 0.0254)

However, I have discovered that the following formula gives exactly the correlation between scale and resolution found in GeoServer:

ScaleDenominator = Resolution * (90 / 0.0252)

The value of 90 for PPI is understandable because you can find in GeoServer's documentation (here) that

The OGC standard output resolution is 90 DPI.

However, I can't understand the value 0.0252. From my point of view there are 2 possibilities:

  • Either there's a bug in GeoServer because 0.0252 is used for conversion between meters and inches, instead of 0.0254.
  • Or GeoServer is correctly using a conversion ratio of 0.0254 between meters and inches, but it is using a PPI of 90.71428571428571, which doesn't make much sense to me either.

Can someone help with this? I am using GeoServer 2.13.1, and similar results have consistently been obtained when using different coordinate systems.

J. L.
  • 43
  • 9
  • Check the code? – Ian Turton Sep 19 '18 at 17:50
  • The scale formulas come from the SLD specification, check it out. Also mind, you've been discussing the scale denominator for projected coordinate systems, but there is a different one for geographic ones. Check out http://portal.opengeospatial.org/files/?artifact_id=1188 and http://portal.opengeospatial.org/files/?artifact_id=16700 – Andrea Aime Sep 21 '18 at 06:18

1 Answers1

3

Looking at the code seems to indicate that GeoTools (and hence GeoServer) uses 0.0254 in the scale calculation.

public static double calculatePixelsPerMeterRatio(double scaleDenominator, Map hints) {
    if (scaleDenominator <= 0.0)
        throw new IllegalArgumentException("The scale denominator must be positive.");
    double scale = 1.0 / scaleDenominator;
    return scale * (getDpi(hints) / 0.0254);
}

and unless you have set a hint for the DPI you will be using 90.714 which is possibly to do with US vs International Inches.

public static double getDpi(Map hints) {
    if (hints != null && hints.containsKey("dpi")) {
        return ((Number) hints.get("dpi")).doubleValue();
    } else {
        return 25.4 / 0.28; // 90 = OGC standard
    }
}
Ian Turton
  • 81,417
  • 6
  • 84
  • 185
  • 1
    Thanks @IanTurton. Given that GeoServer uses a DPI of 25.4 / 0.28 when there's no hints, the conversion formula gets reduced to

    ScaleDenominator = Resolution * (1 / 0.00028)

    – J. L. Sep 20 '18 at 10:04