alphamale

size of scalebar in lat/lon?

Discussion created by alphamale on Mar 26, 2013
My data is in lat/lon but I'd like my scalebar in miles.  A rough estimate is good enough.  I figure that if I take the latitudes of my
extent, a degree of latitude is fairly constant.  But it appears that no matter how I scale the data, the scalebar is ~2 inches long. 
Is it hard-coded that way?  Here is a bare-bones version of my code:

Dim pAV As IActiveView = pMxDocument.FocusMap
Dim qEnvelope = pAV.Extent
Dim yhi As Double = qEnvelope.YMax
Dim ylo As Double = qEnvelope.YMin
Dim ys As Double = (yhi - ylo) * 111195 / 1609 'we could quibble about this conversion
Dim zs As Double = ys / 7.5 'map is landscape - runs from 8.0 to 0.5.
Dim xs As Double = 1 + 120 / zs 'want 120 mile scale bar, starting at 1 inch.

Dim envelope As ESRI.ArcGIS.Geometry.IEnvelope = New ESRI.ArcGIS.Geometry.EnvelopeClass
envelope.PutCoords(1, 1, xs, 1.5) ' Specify the location and size of the scalebar
Dim uid As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UIDClass
uid.Value = "esriCarto.AlternatingScaleBar"

' Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
' Activate it and add it to the PageLayout's graphics container
Dim graphicsContainer As IGraphicsContainer = TryCast(pPageLayout, IGraphicsContainer) 'Carto: Dynamic Cast
Dim activeView As IActiveView = TryCast(pPageLayout, IActiveView) ' Carto: Dynamic Cast
Dim frameElement As IFrameElement = graphicsContainer.FindFrame(pMap)
Dim mapFrame As IMapFrame = TryCast(frameElement, IMapFrame) ' Dynamic Cast
Dim mapSurroundFrame As IMapSurroundFrame = mapFrame.CreateSurroundFrame(TryCast(uid, UID), Nothing) ' Dynamic Cast
Dim mapSurround As IMapSurround = mapSurroundFrame.MapSurround

Dim markerScaleBar As IScaleBar = (CType(mapSurround, IScaleBar)) ' Explicit Cast
markerScaleBar.LabelPosition = ESRI.ArcGIS.Carto.esriVertPosEnum.esriBottom
markerScaleBar.UseMapSettings()

With markerScaleBar
            .Units = esriUnits.esriMiles
            .UnitLabel = "Miles"
            .UnitLabelGap = 6  'points
            .UnitLabelPosition = esriScaleBarPos.esriScaleBarBelow
            .UnitLabelSymbol = pUnitsTextSymbol
            .BarHeight = 5    'points
            .BarColor = pColor
            .Division = 30    'miles
            .Divisions = 4     ' 4 divisions + 1 before zero = 5
            .Subdivisions = 2  ' 2 subdiv. shown => one subdiv. marks b/w each division mark
            .DivisionsBeforeZero = 0
            .LabelSymbol = pLabelTextSymbol
            .LabelGap = 6      'points
            .LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisions
            'esriScaleBarDivisions    ' place label on each division
            .NumberFormat = pNumericFormat
            .ResizeHint = esriScaleBarResizeHint.esriScaleBarAutoDivisionAndDivisions
End With

Dim element As ESRI.ArcGIS.Carto.IElement = TryCast(mapSurroundFrame, ESRI.ArcGIS.Carto.IElement) ' Dynamic Cast
element.Geometry = envelope
element.Activate(activeView.ScreenDisplay)
graphicsContainer.AddElement(element, 0)

Outcomes