■ CartesianSourceCoordinateSystem 클래스의 CoordinateConverter 속성을 사용해 좌표 변환기(Coordinate Converter)를 수동으로 설정하는 방법을 보여준다.
▶ MapData.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using System; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 맵 데이터 /// </summary> public class MapData { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 파일 경로 - FilePath /// <summary> /// 파일 경로 /// </summary> public string FilePath { get; set; } #endregion #region 소스 좌표계 - SourceCoordinateSystem /// <summary> /// 소스 좌표계 /// </summary> public SourceCoordinateSystem SourceCoordinateSystem { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return String.Format("{0}; with {1}", FilePath, SourceCoordinateSystem.CoordinateConverter); } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
using System; using System.Collections.Generic; using System.Drawing; using System.Reflection; using DevExpress.XtraEditors; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 빙 맵 키 /// </summary> private string bingKey = "INPUT YOUR BING KEY"; /// <summary> /// 도형 파일 데이터 어댑터 /// </summary> private ShapefileDataAdapter shapefileDataAdapter = new ShapefileDataAdapter(); /// <summary> /// 맵 데이터 리스트 /// </summary> private List<MapData> mapDataList = new List<MapData> { new MapData() { FilePath = "DATA/Albers/switzerland.shp", SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new AlbersEqualAreaConticCartesianToGeoConverter() { StandardParallelN = 60, StandardParallelS = 20, Ellipsoid = Ellipsoid.GRS80, ProjectionCenter = new GeoPoint(40, -96) } } }, new MapData() { FilePath = "DATA/Lambert/Belize.shp", SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new LambertConformalConicCartesianToGeoConverter() { StandardParallelN = 60, StandardParallelS = 20, Ellipsoid = Ellipsoid.GRS80, ProjectionCenter = new GeoPoint(40, -96) } } }, new MapData() { FilePath = "DATA/TransverseMercator/israel.shp", SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new TransverseMercatorCartesianToGeoConverter() { Ellipsoid = Ellipsoid.WGS84, ProjectionCenter = new GeoPoint(0, 33), ScaleFactor = 0.9996, FalseNorthing = 0, FalseEasting = 500000 } } }, new MapData() { FilePath = "DATA/TransverseMercator/israel.shp", SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new UTMCartesianToGeoConverter() { UtmZone = 36, Hemisphere = Hemisphere.Northern } } }, new MapData() { FilePath = "DATA/MercatorAux/montenegro.shp", SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new MercatorAuxiliarySphereCartesianToGeoConverter() { SphereType = 0, ProjectionCenter = new GeoPoint(0,0) } } } }; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Load += Form_Load; this.mapDataComboBox.SelectedIndexChanged += mapDataComboBox_SelectedIndexChanged; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { this.mapDataComboBox.DataSource = this.mapDataList; this.bingMapDataProvider.BingKey = this.bingKey; VectorItemsLayer vectorItemsLayer = new VectorItemsLayer(); vectorItemsLayer.ItemStyle.Fill = Color.FromArgb(40, 255, 128, 0); vectorItemsLayer.Data = this.shapefileDataAdapter; vectorItemsLayer.DataLoaded += vectorItemsLayer_DataLoaded; this.mapControl.Layers.Add(vectorItemsLayer); } #endregion #region 맵 데이터 콤보 박스 선택 인덱스 변경시 처리하기 - mapDataComboBox_SelectedIndexChanged(sender, e) /// <summary> /// 맵 데이터 콤보 박스 선택 인덱스 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void mapDataComboBox_SelectedIndexChanged(object sender, EventArgs e) { MapData mapData = this.mapDataComboBox.SelectedValue as MapData; if(mapData == null) { return; } Uri baseURI = new Uri(Assembly.GetEntryAssembly().Location); Uri fileURI = new Uri(baseURI, mapData.FilePath); this.shapefileDataAdapter.FileUri = fileURI; this.shapefileDataAdapter.SourceCoordinateSystem = mapData.SourceCoordinateSystem; } #endregion #region 벡터 항목 레이어 데이터 로드시 처리하기 - vectorItemsLayer_DataLoaded(sender, e) /// <summary> /// 벡터 항목 레이어 데이터 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void vectorItemsLayer_DataLoaded(object sender, DataLoadedEventArgs e) { this.mapControl.ZoomToFitLayerItems(0.4); } #endregion } } |