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: Specify a Map Projection

  • 2 minutes to read

This example demonstrates how to specify the map projection that is used to display geographical data for a Map Control.

To configure a map projection, specify the GeoMapCoordinateSystem.Projection property of the GeoMapCoordinateSystem object. Assign it to the MapControl.CoordinateSystem property.

One of the following predefined map projections can be used.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraMap;

namespace MapProjections {
    public partial class Form1 : Form {
        const string filepath = @"..\..\Data\Countries.shp";
        List<ProjectionBase> mapProjections = new List<ProjectionBase>() {
            new BraunStereographicProjection(),
            new EllipticalMercatorProjection(),
            new EqualAreaProjection(),
            new EquidistantProjection(),
            new EquirectangularProjection(),
            new KavrayskiyProjection(),
            new LambertCylindricalEqualAreaProjection(),
            new MillerProjection(),
            new SinusoidalProjection(),
            new SphericalMercatorProjection(),
            new Etrs89LambertAzimuthalEqualAreaProjection()
        };

        GeoMapCoordinateSystem CoordinateSystem { get { return mapControl.CoordinateSystem as GeoMapCoordinateSystem; } }

        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            lbProjection.DataSource = mapProjections;
            lbProjection.SetSelected(0, true);

            Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);         
            Uri uri = new Uri(baseUri, filepath);
            mapControl.Layers.Add(new VectorItemsLayer() {
                Data = new ShapefileDataAdapter() {
                    FileUri = uri
                }
            });
        }

        private void lbProjection_SelectedIndexChanged(object sender, EventArgs e) {
            CoordinateSystem.Projection = lbProjection.SelectedValue as ProjectionBase;
        }
    }
}