■ ProjectionBase 클래스를 사용해 커스텀 맵 투영을 구현하는 방법을 보여준다.
▶ HammerAitoffProjection.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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
using System; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// HAMMER-AITOFF 투영 /// </summary> public class HammerAitoffProjection : ProjectionBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 최소 위도 /// </summary> private const double MINIMUM_LATITUDE = -90.0; /// <summary> /// 최대 위도 /// </summary> private const double MAXIMUM_LATITUDE = 90.0; /// <summary> /// 최소 경도 /// </summary> private const double MINIMUM_LONGITUDE = -180.0; /// <summary> /// 최대 경도 /// </summary> private const double MAXIMUM_LONGITUDE = 180.0; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 오프셋 X - OffsetX /// <summary> /// 오프셋 X /// </summary> [Obsolete] public override double OffsetX { get { return 0.5; } } #endregion #region 오프셋 Y - OffsetY /// <summary> /// 오프셋 Y /// </summary> [Obsolete] public override double OffsetY { get { return 0.5; } } #endregion #region 스케일 X - ScaleX /// <summary> /// 스케일 X /// </summary> [Obsolete] public override double ScaleX { get { return 0.5; } } #endregion #region 스케일 Y - ScaleY /// <summary> /// 스케일 Y /// </summary> [Obsolete] public override double ScaleY { get { return -0.25; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 도 구하기 - GetDegree(value) /// <summary> /// 도 구하기 /// </summary> /// <param name="value">값</param> /// <returns>도</returns> private static double GetDegree(double value) { return value * 180.0 / Math.PI; } #endregion #region 라디안 구하기 - GetRadian(value) /// <summary> /// 라디안 구하기 /// </summary> /// <param name="value">값</param> /// <returns>라디안</returns> private static double GetRadian(double value) { return value * Math.PI / 180.0; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 지도 단위 구하기 - GeoPointToMapUnit(geoPoint) /// <summary> /// 지도 단위 구하기 /// </summary> /// <param name="geoPoint">지리 포인트</param> /// <returns>지도 단위</returns> public override MapUnit GeoPointToMapUnit(GeoPoint geoPoint) { double longitude = GetRadian(Math.Min(MAXIMUM_LONGITUDE, Math.Max(MINIMUM_LONGITUDE, geoPoint.Longitude))); double latitude = GetRadian(Math.Min(MAXIMUM_LATITUDE , Math.Max(MINIMUM_LATITUDE , geoPoint.Latitude ))); double z = Math.Sqrt(1 + Math.Cos(latitude) * Math.Cos(longitude / 2)); double x = Math.Cos(latitude) * Math.Sin(longitude / 2) / z; double y = Math.Sin(latitude) / z; return new MapUnit(x * ScaleX + OffsetX, y * ScaleY + OffsetY); } #endregion #region 지리 포인트 구하기 - MapUnitToGeoPoint(mapUnit) /// <summary> /// 지리 포인트 구하기 /// </summary> /// <param name="mapUnit">지도 단위</param> /// <returns>지리 포인트</returns> public override GeoPoint MapUnitToGeoPoint(MapUnit mapUnit) { double x = (mapUnit.X - OffsetX) / ScaleX; double y = Math.Min(1, Math.Max(-1, (mapUnit.Y - OffsetY) / ScaleY)); if(IsValidPoint(x, y)) { double z = Math.Sqrt(1 - 0.5 * Math.Pow(x, 2) - 0.5 * Math.Pow(y, 2)); double c = Math.Sqrt(2) * z * x / (2 * Math.Pow(z, 2) - 1); double longitude = 2 * Math.Atan(c); double latitude = Math.Asin(Math.Min(Math.Max(Math.Sqrt(2) * z * y, -1), 1)); double latitudeDegree = latitude * 180.0 / Math.PI; double longitudeDegree = longitude * 180.0 / Math.PI; return new GeoPoint ( Math.Min(MAXIMUM_LATITUDE , Math.Max(MINIMUM_LATITUDE , GetDegree(latitude ))), Math.Min(MAXIMUM_LONGITUDE, Math.Max(MINIMUM_LONGITUDE, GetDegree(longitude))) ); } else { int signX = (x < 0) ? -1 : 1; int signY = (y < 0) ? -1 : 1; return new GeoPoint(MAXIMUM_LATITUDE * signY, MAXIMUM_LONGITUDE * signX); } } #endregion #region 킬로미터 크기 구하기 - GeoToKilometersSize(anchorPoint, mapSize) /// <summary> /// 킬로미터 크기 구하기 /// </summary> /// <param name="anchorPoint">앵커 포인트</param> /// <param name="mapSize">맵 크기</param> /// <returns>킬로미터 크기</returns> public override MapSize GeoToKilometersSize(GeoPoint anchorPoint, MapSize mapSize) { return new MapSize ( mapSize.Width * LonToKilometersRatio * Math.Cos(GetRadian(anchorPoint.Latitude)), mapSize.Height * LatToKilometersRatio ); } #endregion #region 지리 크기 구하기 - KilometersToGeoSize(anchorPoint, mapSize) /// <summary> /// 지리 크기 구하기 /// </summary> /// <param name="anchorPoint">앵커 포인트</param> /// <param name="mapSize">맵 크기</param> /// <returns>지리 크기</returns> public override MapSize KilometersToGeoSize(GeoPoint anchorPoint, MapSize mapSize) { return new MapSize ( mapSize.Width / LonToKilometersRatio / Math.Cos(GetRadian(anchorPoint.Latitude)), mapSize.Height / LatToKilometersRatio ); } #endregion //////////////////////////////////////////////////////////////////////////////// Private #region 포인트 검증 여부 구하기 - IsValidPoint(x, y) /// <summary> /// 포인트 검증 여부 구하기 /// </summary> /// <param name="x">X</param> /// <param name="y">Y</param> /// <returns>포인트 검증 여부</returns> private bool IsValidPoint(double x, double y) { if(Math.Pow(x, 2) + Math.Pow(y, 2) > 1) { return false; } else { return true; } } #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 |
using System; using System.Reflection; using DevExpress.XtraEditors; using DevExpress.XtraMap; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); GeoMapCoordinateSystem geoMapCoordinateSystem = this.mapControl.CoordinateSystem as GeoMapCoordinateSystem; geoMapCoordinateSystem.Projection = new HammerAitoffProjection(); Uri baseURI = new Uri(Assembly.GetEntryAssembly().Location); this.shapefileDataAdapter.FileUri = new Uri(baseURI, "Data/Countries.shp"); } #endregion } } |