Example T202055
Visible to All Users

Chart for WinForms - How to Customize Coordinate Systems of a Map

This example demonstrates how to customize coordinate systems of the map and data source.
Map

Assign a MapCoordinateSystem class descendant object to the MapControl.CoordinateSystem property and a SourceCoordinateSystem class descendant object to the CoordinateSystemDataAdapterBase.SourceCoordinateSystem property.

To display geographic data, a map should have a geo coordinate system. To display Cartesian data, the map should have a Cartesian coordinate system or SourceCoordinateSystem.CoordinateConverter should be specified to convert Cartesian point to a geographic point.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

CoordinateSystems/Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraMap; namespace CoordinateSystems { public partial class Form1 : Form { const string geoMapGeoDataFile = "../../Data/Countries.shp"; const string cartesianMapCartesianDataFile = "../../Data/Hotel1.shp"; const string geoMapCartesianDataShpFile = "../../Data/Sweden_county07.shp"; const string geoMapCartesianDataPrjFile = "../../Data/Sweden_county07.prj"; ShapefileDataAdapter Adapter { get; set; } public Form1() { InitializeComponent(); } private void OnLoad(object sender, EventArgs e) { Adapter = new ShapefileDataAdapter(); vectorLayer.Data = Adapter; vectorLayer.DataLoaded += DataLayer_DataLoaded; } #region #GeoMapGeoData void SetGeoMapGeoData() { imageLayer.Visible = false; Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location); Adapter.FileUri = new Uri(baseUri, geoMapGeoDataFile); Adapter.SourceCoordinateSystem = new GeoSourceCoordinateSystem(); mapControl.CoordinateSystem = new GeoMapCoordinateSystem(); } #endregion #GeoMapGeoData #region #CartesianMapCartesianData void SetCartesianMapCartesianData() { imageLayer.Visible = false; Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location); Adapter.FileUri = new Uri(baseUri, cartesianMapCartesianDataFile); Adapter.SourceCoordinateSystem = new CartesianSourceCoordinateSystem(); mapControl.CoordinateSystem = new CartesianMapCoordinateSystem(); } #endregion #CartesianMapCartesianData #region #GeoMapCartesianData void SetGeoMapCartesianData() { imageLayer.Visible = true; Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location); Adapter.FileUri = new Uri(baseUri, geoMapCartesianDataShpFile); Adapter.SourceCoordinateSystem = ShapefileDataAdapter.LoadPrjFile(new Uri(baseUri, geoMapCartesianDataPrjFile)); mapControl.CoordinateSystem = new GeoMapCoordinateSystem(); } #endregion #GeoMapCartesianData void DataLayer_DataLoaded(object sender, DataLoadedEventArgs e) { mapControl.ZoomToFitLayerItems(0.4); } private void cbDataType_SelectedIndexChanged(object sender, EventArgs e) { switch (cbDataType.SelectedIndex) { case 0: SetGeoMapGeoData(); break; case 1: SetCartesianMapCartesianData(); break; case 2: SetGeoMapCartesianData(); break; default: SetGeoMapGeoData(); break; } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.