一、系統概述
1、系統簡介
系統是在VS2008中利用ArcGIS Engine10.1進行的二次開發。系統主要有菜單欄、內容列表、鷹眼視圖、操作面板、地圖視圖、佈局視圖等六大功能模塊區。
2、功能簡介
系統主要功能包括:
基礎操作:新建文檔、打開文檔、保存文檔、另存爲、添加XY數據、影像導入、退出系統;
地圖製圖輸出:添加文字、添加圖例、添加數字比例尺、添加文字比例尺、添加指北針、輸出JPG、輸出BMP、輸出PNG、輸出PDF;
系統設置:皮膚選擇、內容顯示;
幫助:幫助文檔、關於、在線支持、聯繫我們;
地圖操作:選擇、放大、縮小、平移、全幅顯示;
佈局操作:選擇、、放大、縮小、平移、全幅顯示、固定比例尺放大、固定比例尺縮小、前一視圖、後一視圖、1:1顯示。
3、系統界面介紹
系統使用DevExpress第三方控件進行系統界面搭建。DevExpress開發的控件有很強的實力,不僅功能豐富,應用簡便,而且界面華麗,更可方便定製。對於編程人員來說是個不錯的選擇。它的菜單欄控件更具代表,完全可以替代開發環境提供的基本控件,而讓您編寫的程序或軟件更顯專業化。它還提供完善的幫助系統,資料詳盡,可以快速入手。有些高級控件更是零代碼的,非常易於使用。
圖1:系統主界面
圖2:系統皮膚選擇
二、系統環境及功能亮點
1、系統環境
開發平臺 | ArcGIS Engine10.1 |
開發工具 | VS2008、IDL、DevExpress |
開發語言 | C#、IDL8.0 |
運行環境 | Windows 7 |
數據庫 | 無 |
其他(可擴充) | 無 |
2、功能亮點
1)、 系統基礎功能較爲完善。基礎文檔操作、地圖佈局設置功能豐富、地圖輸出格式多樣;
2)、 實現圖層添加、移除以及屬性表查看等功能;
3)、 通過調用GP工具實現“添加XY數據”功能;
4)、 通過調用IDL程序實現遙感影像波段合成功能;
圖3:圖層屬性查看
圖4:屬性查看代碼實現
//屬性查看
private void FormAttribute_Load(object sender, EventArgs e)
{
try
{
//pLayer:存儲當前查詢圖層名稱
pFeatureLayer = pLayer as IFeatureLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
pLayerFields = pFeatureLayer as ILayerFields;
DataSet ds = new DataSet("dsTest");
DataTable dt = new DataTable(pFeatureLayer.Name);
DataColumn dc = null;
for (int i = 0; i < pLayerFields.FieldCount; i++)
{
dc = new DataColumn(pLayerFields.get_Field(i).Name);
dt.Columns.Add(dc);
dc = null;
}
IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < pLayerFields.FieldCount; j++)
{
if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
{
dr[j] = pFeatureClass.ShapeType.ToString();
}
else
{
dr[j] = pFeature.get_Value(j);
}
}
dt.Rows.Add(dr);
pFeature = pFeatureCursor.NextFeature();
}
gridControl1.DataSource = dt;
this.Text = pLayer.Name + "屬性表";
}
catch (Exception ex)
{
MessageBox.Show("屬性表讀取失敗:" + ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();//釋放資源
}
}
圖5:添加XY數據
圖6:代碼實現
//確定,創建點圖層
private void btOk_Click(object sender, EventArgs e)
{
if (textEditExcel.Text == "" || ComboBoxEditX.Text == "" || ComboBoxEditY.Text == "" || textEditName.Text == "" || txyPath == null)
{
MessageBox.Show("輸入有誤,請重新填寫!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
try
{
this.progressBar.EditValue = 5;
//bgWorker.RunWorkerAsync();
Geoprocessor GP = new Geoprocessor();
//添加XY事件
MakeXYEventLayer MxyLayer = new MakeXYEventLayer();
//直接獲取Excel表格中第一個表名
MxyLayer.table = textEditExcel.Text +"\\"+ ReadExcel.GetExcelFirstTableName(textEditExcel.Text);
this.progressBar.EditValue = 15;
//獲取經度字段
MxyLayer.in_x_field = ComboBoxEditX.Text;
//獲取緯度字段
MxyLayer.in_y_field = ComboBoxEditY.Text;
this.progressBar.EditValue = 25;
MxyLayer.out_layer = "result";
GP.Execute(MxyLayer, null);
this.progressBar.EditValue = 35;
//複製要素
ESRI.ArcGIS.DataManagementTools.CopyFeatures cf = new ESRI.ArcGIS.DataManagementTools.CopyFeatures();
cf.in_features = "result";
this.progressBar.EditValue = 45;
cf.out_feature_class = txyPath;
GP.Execute(cf, null);
this.progressBar.EditValue = 55;
//添加要素圖層到Map
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
IFeatureWorkspace pws = workspaceFactory.OpenFromFile(gdbPath, 0) as IFeatureWorkspace;
this.progressBar.EditValue = 65;
IFeatureLayer pFeatureLater = new FeatureLayerClass();
pFeatureLater.FeatureClass = pws.OpenFeatureClass("XY點圖層_" + textEditName.Text);
pFeatureLater.Name = "XY點圖層_" + textEditName.Text;
this.progressBar.EditValue = 75;
axMapControlxy.Map.AddLayer(pFeatureLater as ILayer);
axMapControlxy.Extent = axMapControlxy.FullExtent;
this.progressBar.EditValue = 85;
MessageBox.Show("圖層創建成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("圖層創建失敗!"+ex.Message.ToString(),"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
圖8:點圖層創建結果
圖9:波段合成
圖10:結果顯示
//波段合成
private void btOk_Click(object sender, EventArgs e)
{
if (lvFiles.Items.Count < 2 || textImageName.Text == "" || ImgsavePath == null)
{
if (lvFiles.Items.Count < 2)
{
MessageBox.Show("波段選擇有誤,請重新選擇!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lvFiles.Items.Clear();
}
else
{
MessageBox.Show("輸入有誤,請重新填寫!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
try
{
//調用LayerStacking方法實現波段合成
this.LayerStacking(ImgsavePath);
//調用RasterToGDB方法將合成影像導入地理數據庫中
RasterToGDB(ImgsavePath);
//調用DeleteFile方法實現刪除合成影像
DeleteFile("波段合成_" + textImageName.Text.Trim() + ".img");
DeleteFile("波段合成_" + textImageName.Text.Trim() + ".hdr");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
DialogResult re = MessageBox.Show("操作成功!是否添加顯示?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (re == DialogResult.OK)
{
//調用添加顯示功能
AddLayerToMap("波段合成_" + textImageName.Text, gdbPath, axMapControlimg);
this.Close();
this.Dispose();
}
else
{
this.Close();
this.Dispose();
}
}
}
注:一下爲C#封裝的方法,主要實現影柵格數據入庫、Temp數據刪除、柵格數據添加顯示等功能操作!
/// <summary>
/// 調用GP工具將柵格數據導入地理數據庫中
/// </summary>
/// <param name="imagepath">生成的柵格數據路徑</param>
public static void RasterToGDB(string imagepath)
{
Geoprocessor GP = new Geoprocessor();
ESRI.ArcGIS.ConversionTools.RasterToGeodatabase rasterTogeodatabase = new ESRI.ArcGIS.ConversionTools.RasterToGeodatabase();
rasterTogeodatabase.Input_Rasters = imagepath;
rasterTogeodatabase.Output_Geodatabase = FormMain.GDB;
GP.Execute(rasterTogeodatabase, null);
}
/// <summary>
/// 刪除文件
/// </summary>
/// <param name="filename">文件名</param>
public static void DeleteFile(string filename)
{
//判斷文件是否存在
if (File.Exists(FormMain.ImagePath +"\\"+ filename))
{
//如果存在則刪除
File.Delete(FormMain.ImagePath +"\\"+ filename);
}
}
/// <summary>
/// 將產生的柵格數據添加到map中顯示
/// </summary>
/// <param name="filename">柵格數據名稱</param>
///<param name="gdbpath">數據存放路徑</param>
/// <param name="axmapcontrol">Axmapcontrol</param>
public static void AddLayerToMap(string filename,string gdbpath, AxMapControl axmapcontrol)
{
IWorkspaceFactory workspacefactory = new FileGDBWorkspaceFactoryClass();
IRasterWorkspaceEx rasterworkspace = workspacefactory.OpenFromFile(gdbpath, 0) as IRasterWorkspaceEx;
IRasterDataset rasterdataset = rasterworkspace.OpenRasterDataset(filename);
IRasterLayer rasterlayer = new RasterLayerClass();
rasterlayer.CreateFromDataset(rasterdataset);
axmapcontrol.Map.AddLayer(rasterlayer as ILayer);
axmapcontrol.Extent = axmapcontrol.FullExtent;
}
圖11:波段合成IDL代碼實現
pro ENVI_LAYER_STACKING_DOIT_Record,_extra = extra
end
pro LayerStacking,paths,out_path
compile_opt idl2
;嚴格編譯規則
compile_opt idl2
;載入envi的sav文件
envi,/restore_base_save_files
;初始化envi
envi_batch_init,log_file = 'batch.LOG'
fids = lonarr(n_elements(paths))
nbs = lonarr(n_elements(paths))
nses = lonarr(n_elements(paths))
nls = lonarr(n_elements(paths))
dimses = lonarr(5,n_elements(paths))
Sum_nb = 0l
for i = 0,n_elements(paths)-1 do begin
envi_open_file,paths[i],r_fid =r_fid
fids[i] = r_fid
envi_file_query,fids[i],ns=ns, nl=nl, nb=nb,dims = dims
nses[i]=ns
nls[i]=nl
nbs[i]=nb
dimses[*,i]=dims
Sum_nb = Sum_nb + nbs[i]
endfor
pos = lonarr(Sum_nb)
out_proj = envi_get_projection(fid=fids[0],pixel_size=out_ps)
ENVI_DOIT,'ENVI_LAYER_STACKING_DOIT',dims=dimses,FID=fids,pos=pos,OUT_NAME=out_path,$
out_dt=4,interp=2, out_ps=out_ps, $
out_proj=out_proj, r_fid=r_fid
end
圖12:指北針選擇器
圖13:添加文字及檢測輸入是否規範
圖14:系統托盤
圖15:系統關於
三、團隊分工
本系統所有內容均爲本人獨立創作(如有雷同,存屬意外)。
四、心得體會
此處略去一萬字。。。