三维开发实例之洪水淹没 AE + C#.docx
- 文档编号:9376599
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:28
- 大小:30.78KB
三维开发实例之洪水淹没 AE + C#.docx
《三维开发实例之洪水淹没 AE + C#.docx》由会员分享,可在线阅读,更多相关《三维开发实例之洪水淹没 AE + C#.docx(28页珍藏版)》请在冰豆网上搜索。
三维开发实例之洪水淹没AE+C#
三维代码
焦志锋
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.Controls;
usingESRI.ArcGIS.SystemUI;
usingESRI.ArcGIS.Output;
usingESRI.ArcGIS.Display;
usingESRI.ArcGIS.Geometry;
usingESRI.ArcGIS.esriSystem;
usingESRI.ArcGIS.Geodatabase;
usingESRI.ArcGIS.Analyst3D;
usingESRI.ArcGIS.Animation;
usingESRI.ArcGIS.DataSourcesRaster;
usingstdole;
usingSystem.Text.RegularExpressions;
namespaceESRI项目开发竞赛
{
publicpartialclassFrcSence:
Form
{
publicFrcSence()
{
InitializeComponent();
}
#region//全局变量
publicBooleanscenePan=false;
publicintclickSceneTime=0;
publicIPointscenePanPoints1=newPointClass();
publicIPointscenePanPoints2=newPointClass();
publicIPointCameraObs=newPointClass();
publicIAnimationTrackPlaytrl=newAnimationTrackClass();
publicBooleanCreaterKeyFrameSwitch=false;
publicintKeyIndex;
//publicAxSceneControlpaxSceneControl;
publicdoublestartHeight;
publicdoubleendHeight;
publicdoublenowHeight;
//privateILegendClasspLegendClass;
//privateILayerpLayer;
publicISymbolpSymbol;
publicImagepSymbolImage;
//privateboolp;
privateILayerTOCRightLayer;
publicISceneControlmSceneControl;
//FrmIdentifypFrmIdentify=newFrmIdentify();
publicBooleanpIdnetifyIsOrNot;
//publicIScenepScene;
#endregion
#region//菜单功能
///
///打开Raster文件
///
///
///
privatevoid打开Raster文件ToolStripMenuItem_Click(objectsender,EventArgse)
{
try
{
openFileDialog1=newOpenFileDialog();
openFileDialog1.Title="添加raster数据";
openFileDialog1.Filter="TIFF格式(*.tif)|*.tif|Img格式(*.img)|*.img|Bmp格式(*.bmp)|*.bmp|Jpeg格式(*.jpg)|*.jpg";
openFileDialog1.ShowDialog();
stringsFilePath=openFileDialog1.FileName;
IRasterLayerpRaster;
pRaster=newRasterLayerClass();
pRaster.CreateFromFilePath(sFilePath);
axSceneControl1.Scene.AddLayer(pRaster,true);
}
catch(Exceptionex)
{
MessageBox.Show(ex.ToString());
}
}
///
///打开Feature文件
///
///
///
privatevoid打开Feature文件ToolStripMenuItem_Click(objectsender,EventArgse)
{
try
{
OpenFileDialogpOpenfile=newOpenFileDialog();
pOpenfile.Title="添加shapefile文件";
pOpenfile.Filter="*(.shp)|*.shp";
pOpenfile.ShowDialog();
ILayerFactoryHelperpLayerFactoryHelper=newLayerFactoryHelperClass();
IFileNamefilename=newFileNameClass();
filename.Path=pOpenfile.FileName;
IEnumLayerenumlayer=pLayerFactoryHelper.CreateLayersFromName(filenameasIName);
ILayerlayer;
enumlayer.Reset();
layer=enumlayer.Next();
while(layer!
=null)
{
axSceneControl1.SceneGraph.Scene.AddLayer(layer,false);
layer=enumlayer.Next();
axSceneControl1.SceneGraph.RefreshViewers();
}
}
catch
{
return;
}
}
///
///打开TIN文件
///
///
///
privatevoid打开TIN文件ToolStripMenuItem_Click(objectsender,EventArgse)
{
//stringdirName;
//ILayerpLayer;
//FolderBrowserDialogfolderBrowserDialog1=newFolderBrowserDialog();
//if(folderBrowserDialog1.ShowDialog()==DialogResult.OK)
//{
//dirName=folderBrowserDialog1.SelectedPath;
//pLayer=AddData.openTinLayer(dirName);
//if(pLayer!
=null)
//{
////axMapControl1.AddLayer(pLayer,0);
//axSceneControl1.Scene.AddLayer(pLayer,0);
//}
//}
try
{
FolderBrowserDialogopenFileDialog1=newFolderBrowserDialog();
//openFileDialog1.Title="添加TIN数据";
//openFileDialog1.Filter="TIFF格式(*.tif)|*.tif|Img格式(*.img)|*.img|Bmp格式(*.bmp)|*.bmp|Jpeg格式(*.jpg)|*.jpg";
openFileDialog1.ShowDialog();
stringsFilePath;
sFilePath=openFileDialog1.SelectedPath;
ITinpTIN=newTin3DPropertiesClass()asITin;
ITinLayerpTINLyr=newTinLayerClass();
pTINLyr.Dataset=pTIN;
//pTINLyr.
axSceneControl1.Scene.AddLayer(pTINLyr);
axSceneControl1.Refresh();
}
catch(Exceptionex)
{
MessageBox.Show(ex.ToString());
}
//ITinpTIN=newpTIN();
//ITinLayerpTINLyr=newTinLayerClass();
//pTINLyr.Dataset=pTIN;
//axSceneControl1.Scene.AddLayer(pTINLyr);
}
///
///保存场景图片
///
///
///
privatevoid保存场景图片ToolStripMenuItem_Click(objectsender,EventArgse)
{
try
{
stringsFileName;
SaveFileDialogpSaveFile=newSaveFileDialog();
pSaveFile.Title="保存图片";
pSaveFile.Filter="BMP图片(*.bmp)|*.bmp|JPEG图片(*.jpg)|*.jpg|TIF图片(*.tif)|*.tif";
pSaveFile.ShowDialog();
sFileName=pSaveFile.FileName;
if(pSaveFile.FilterIndex==1)
{
axSceneControl1.SceneViewer.GetScreenShot(esri3DOutputImageType.BMP,sFileName);
}
else
if(pSaveFile.FilterIndex==2)
{
axSceneControl1.SceneViewer.GetScreenShot(esri3DOutputImageType.JPEG,sFileName);
}
MessageBox.Show("成功保存图片至:
"+sFileName);
}
catch
{
MessageBox.Show("出现错误返回");
}
}
///
///退出
///
///
///
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
{
}
#endregion
#region//基本操作
//放大
privatevoidbutton1_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Zoom(0.9);
axSceneControl1.Refresh();
}
//缩小
privatevoidbutton2_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Zoom(1.1);
axSceneControl1.Refresh();
}
//漫游
privatevoidbutton3_Click(objectsender,EventArgse)
{
axSceneControl1.Navigate=true;
}
//平移
privatevoidbutton4_Click(objectsender,EventArgse)
{
scenePan=true;
}
//窗体事件
privatevoidaxSceneControl1_OnMouseDown(objectsender,ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvente)
{
//鼠标漫游
if(scenePan)
{
//if(CreaterKeyFrameSwitch)
//{
//CreateKeyFrame(axSceneControl1.Scene,Playtrl,KeyIndex);
//KeyIndex=KeyIndex+1;
//}
if(clickSceneTime==0)
{
scenePanPoints1.PutCoords(e.x,e.y);
clickSceneTime=1;
}
elseif(clickSceneTime==1)
{
scenePanPoints2.PutCoords(e.x,e.y);
axSceneControl1.Camera.Pan(scenePanPoints1,scenePanPoints2);
axSceneControl1.Refresh();
clickSceneTime=0;
scenePan=false;
}
}
//鼠标点击查询
if(pIdnetifyIsOrNot==true)
{
IHit3DSetpHit3DSet;
axSceneControl1.SceneGraph.LocateMultiple(axSceneControl1.SceneGraph.ActiveViewer,e.x,e.y,esriScenePickMode.esriScenePickAll,false,outpHit3DSet);
pHit3DSet.OnePerLayer();
if(pHit3DSet.Hits.Count==0)
{
MessageBox.Show("当前点未能查找到任何要素");
}
IHit3DpHit3D=pHit3DSet.Hits.get_Element(0)asIHit3D;
pIdnetifyIsOrNot=false;
MessageBox.Show("X="+pHit3D.Point.X+",Y="+pHit3D.Point.Y+",Z="+pHit3D.Point.Z);
}
if(e.button==2)
{
contextMenuSence.Show(this.axSceneControl1,e.x,e.y);
}
}
//自动旋转
privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse)
{
if(checkBox1.Checked)
{
timer1.Enabled=true;
}
else
{
timer1.Enabled=false;
}
}
//自动旋转的速率控制
privatevoidtimer1_Tick(objectsender,EventArgse)
{
axSceneControl1.Camera.Rotate(Convert.ToDouble(comboBox2.Text));
axSceneControl1.Refresh();
}
#endregion
#region//方向控制
//上移
privatevoidbutton9_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveUp,0.01);
axSceneControl1.Refresh();
}
//左移
privatevoidbutton10_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveLeft,0.01);
axSceneControl1.Refresh();
}
//右移
privatevoidbutton12_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveRight,0.01);
axSceneControl1.Refresh();
}
//下移
privatevoidbutton11_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveDown,0.01);
axSceneControl1.Refresh();
}
//前进
privatevoidbutton13_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveAway,0.01);
axSceneControl1.Refresh();
}
//后退
privatevoidbutton14_Click(objectsender,EventArgse)
{
axSceneControl1.Camera.Move(esriCameraMovementType.esriCameraMoveToward,0.01);
axSceneControl1.Refresh();
}
//点击查询
//publicBooleanpIdnetifyIsOrNot;
privatevoidbutton15_Click(objectsender,EventArgse)
{
pIdnetifyIsOrNot=true;
}
#endregion
#region//视屏输出
//保存视频文件
privatevoidbutton16_Click(objectsender,EventArgse)
{
try
{
SaveFileDialogsaveVedioFile=newSaveFileDialog();
saveVedioFile.Filter="视屏文件(*.avi)|*.avi";
saveVedioFile.Title="输出AVI文件";
saveVedioFile.ShowDialog();
ISceneExporter3dp3Dexporter=newAVIExporterClass();
p3Dexporter.ExportFileName=saveVedioFile.FileName;
ISceneVideoExporterpExporter;
pExporter=p3DexporterasISceneVideoExporter;
pExporter.Viewer=axSceneControl1.Scene.SceneGraph.ActiveViewer;
pExporter.VideoDuration=100*Convert.ToDouble(comboBox6.Text);
pExporter.FrameRate=10*trackBar1.Value;
IAVIExporterpAVIExporter;
pAVIExporter=p3DexporterasIAVIExporter;
pAVIExporter.Quality=50*trackBar2.Value;
p3Dexporter.ExportScene(axSceneControl1.Scene);
MessageBox.Show("输出AVI视屏完成");
}
catch
{
return;
}
}
#endregion
#region//TOC右键功能
privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)
{
esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;
IBasicMapmap=null;ILayerlayer=null;
objectother=null;objectindex=null;
axTOCCont
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 三维开发实例之洪水淹没 AE C# 三维 开发 实例 洪水 淹没