Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Provide Cylindrical Equal-Area Projections

  • 3 minutes to read

This example illustrates how to get equal-area map projections (Lambert, Behrmann, Tristan Edwards, Peters, Gall orthographic and Balthasart) for the shapes loaded from the Shapefiles (Countries.shp, Countries.dbf).

To accomplish this task, create an EqualAreaProjection object and assign it to the ((GeoMapCoordinateSystem)MapControl.CoordinateSystem).Projection property. Then, specify the Width/height aspect ratio for each equal area projection using the MapControl.InitialMapSize property.

To learn more about the equal-area projections, see Cylindrical_equal-area_projection.

using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace AvoidMapDistortion {
    public partial class MainWindow : Window {
        public struct WidthHeightRatio {
            public string Name { get; set; }
            public double Value { get; set; }
        }

        int defaultSideSize = 512;
        List<WidthHeightRatio> ratios = new List<WidthHeightRatio>() {
            new WidthHeightRatio() { Name = "(Default)", Value = 1 },
            new WidthHeightRatio() { Name = "Lambert", Value = 3.14 },
            new WidthHeightRatio() { Name = "Behrmann", Value = 2.36 },
            new WidthHeightRatio() { Name = "Trystan Edwards", Value = 2.0 },
            new WidthHeightRatio() { Name = "Gall-Peters", Value = 1.57 },
            new WidthHeightRatio() { Name = "Balthasart", Value = 1.3 }
        };
        public List<WidthHeightRatio> Ratios { get { return ratios; } }

        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            this.DataContext = Ratios;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            mapControl.InitialMapSize = new Size() {
                Width = defaultSideSize,
                Height = (int)(defaultSideSize / ((WidthHeightRatio)lbRatio.SelectedValue).Value)
            };
        }
    }
}
<Window x:Class="AvoidMapDistortion.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
        Title="MainWindow" Height="557" Width="707" Loaded="Window_Loaded">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <dxm:MapControl Name="mapControl" Margin="4,4,2,4"
                        Grid.Row="0" Grid.Column="0">
            <dxm:VectorLayer>
                <dxm:ShapefileDataAdapter 
                    FileUri="Shapefiles/Countries.shp"/>
            </dxm:VectorLayer>
        </dxm:MapControl>
        <StackPanel Orientation="Vertical" Margin="2,4,4,4"
                    Grid.Row="0" Grid.Column="1">
            <Label Content="Width/Height Ratio:"/>
            <ListBox Name="lbRatio" ItemsSource="{Binding}" 
                     DisplayMemberPath="Name" SelectedIndex="0" 
                     SelectionChanged="ListBox_SelectionChanged"/>
        </StackPanel>
    </Grid>
</Window>
See Also