■ ShapefileDataAdapter 클래스의 SourceCoordinateSystem 속성을 사용해 직교 데이터(Cartesian Data)를 제공하는 방법을 보여준다.
▶ 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 |
using System; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 맵 데이터 /// </summary> public class MapData { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 파일 URI - FileURI /// <summary> /// 파일 URI /// </summary> public Uri FileURI { get; set; } #endregion #region 소스 좌표계 - SourceCoordinateSystem /// <summary> /// 소스 좌표계 /// </summary> public SourceCoordinateSystem SourceCoordinateSystem { get; set; } #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 |
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 List<MapData> mapDataList = new List<MapData>(); /// <summary> /// 도형 파일 데이터 어댑터 /// </summary> private ShapefileDataAdapter shapefileDataAdapter = new ShapefileDataAdapter(); #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) { #region 맵 데이터 리스트를 설정한다. Uri baseURI = new Uri(Assembly.GetEntryAssembly().Location); this.mapDataList.Add ( new MapData() { Name = "자동으로 로드된 좌표계", FileURI = new Uri(baseURI, "DATA/Albers/switzerland.shp") } ); this.mapDataList.Add ( new MapData() { Name = "LoadPrjFile 메소드 호출시 로드된 좌표계", FileURI = new Uri(baseURI, "DATA/Lambert/Belize.shp"), SourceCoordinateSystem = ShapefileDataAdapter.LoadPrjFile(new Uri(baseURI, "DATA/Lambert/Projection.prj")) } ); this.mapDataList.Add ( new MapData() { Name = "수동으로 생성된 좌표계", FileURI = new Uri(baseURI, "DATA/TransverseMercator/israel.shp"), SourceCoordinateSystem = new CartesianSourceCoordinateSystem() { CoordinateConverter = new UTMCartesianToGeoConverter() { Hemisphere = Hemisphere.Northern, UtmZone = 36 } } } ); #endregion this.mapDataComboBox.DisplayMember = "Name"; this.mapDataComboBox.DataSource = this.mapDataList; this.bingMapDataProvider.BingKey = this.bingKey; VectorItemsLayer vectorItemsLayer = new VectorItemsLayer(); vectorItemsLayer.ItemStyle.Fill = Color.FromArgb(60, 255, 128, 0); vectorItemsLayer.Data = 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; } this.shapefileDataAdapter.FileUri = mapData.FileURI; if(mapData.SourceCoordinateSystem != null) { 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 } } |