This project has moved and is read-only. For the latest updates, please go here.

Unpredictable MinVisible values

Topics: SharpMap v2.0
Oct 20, 2010 at 1:42 PM

Trying to set a value for a style that defines either the min or max visible for the layer is unpredictable, as this value is being assessed against the world width, which changes depending on the spatial reference system of the map, and hence the world units per pixel varies greatly.

A standard map scale should be use like that in MapServer where the the denominator from a scale such as 1:10,000 is used. Therefore by setting MinVisible to 10000 will display the feature if the map scale is less than 1:10,000. This should be without regard to the spatial reference system used.

I have come up with the following property that seems to do provide a reasonable map scale value for the MapPresenter2d.

Let me know your thoughts.

private const double InchesPerMeter = 39.3700787;
private const double MetersPerNauticalMile = 1852;
private const double NauticalMilesPerDegree = 60;
private const double InchesPerDegree = NauticalMilesPerDegree * MetersPerNauticalMile * InchesPerMeter;

protected double MapScaleDenominator
        double inchesPerUnit;
        var spatialReference = this.Map.SpatialReference;
        var projCs = spatialReference as IProjectedCoordinateSystem;
        if(projCs != null)
            inchesPerUnit = projCs.LinearUnit.MetersPerUnit * InchesPerMeter;
            var latAdj = 1.0;
            var centerLat = this.GeoCenterInternal[Ordinates.Lat];
            if (centerLat != 0.0)
                double cosLat = Math.Cos(Math.PI * centerLat / 180.0);
                latAdj = Math.Sqrt(1 + cosLat * cosLat) / Math.Sqrt(2.0);
            inchesPerUnit = InchesPerDegree * latAdj;

        double worldInches = this.WorldWidthInternal * inchesPerUnit;

        double screenInches = this.View.ViewSize.Width / this.View.Dpi;

        double scale = worldInches / screenInches;

        return scale;

Oct 21, 2010 at 9:29 AM

Thanks for sharing this