[DEVEXPRESS/WINFORM] ShapefileDataAdapter 클래스 : SourceCoordinateSystem 속성을 사용해 직교 데이터(Cartesian Data) 제공하기
DevExpress/WinForm 2020. 6. 17. 20:08728x90
반응형
728x170
▶ MapData.cs
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
}
}
728x90
▶ MainForm.cs
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
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요