江西师范大学
三 维 代 码
焦志锋
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
地理信息系统
江西师范大学
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Animation;
using ESRI.ArcGIS.DataSourcesRaster;
using stdole;
using System.Text.RegularExpressions;
namespace ESRI项目开发竞赛
{
public partial class FrcSence : Form
{
public FrcSence()
{
InitializeComponent();
}
#region //全局变量
public Boolean scenePan = false;
public int clickSceneTime = 0;
public IPoint scenePanPoints1 = new PointClass();
public IPoint scenePanPoints2 = new PointClass();
public IPoint CameraObs = new PointClass();
public IAnimationTrack Playtrl = new AnimationTrackClass();
public Boolean CreaterKeyFrameSwitch = false;
public int KeyIndex;
//public AxSceneControl paxSceneControl;
public double startHeight;
public double endHeight;
public double nowHeight;
//private ILegendClass pLegendClass;
//private ILayer pLayer;
public ISymbol pSymbol;
public Image pSymbolImage;
//private bool p;
private ILayer TOCRightLayer;
public ISceneControl mSceneControl;
//FrmIdentify pFrmIdentify = new FrmIdentify();
public Boolean pIdnetifyIsOrNot;
//public IScene pScene;
#endregion
#region //菜单功能
///
地理信息系统
江西师范大学
/// 打开Raster文件
///
///
///
private void 打开Raster文件ToolStripMenuItem_Click(object sender,
EventArgs e)
{
try
{
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "添加raster数据";
openFileDialog1.Filter = "TIFF格式(*.tif)|*.tif|Img格式
(*.img)|*.img|Bmp格式(*.bmp)|*.bmp|Jpeg格式(*.jpg)|*.jpg";
openFileDialog1.ShowDialog();
string sFilePath = openFileDialog1.FileName;
IRasterLayer pRaster;
pRaster = new RasterLayerClass();
pRaster.CreateFromFilePath(sFilePath);
axSceneControl1.Scene.AddLayer(pRaster, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
///
/// 打开Feature文件
///
///
///
private void 打开Feature文件ToolStripMenuItem_Click(object sender,
EventArgs e)
{
try
{
OpenFileDialog pOpenfile = new OpenFileDialog();
pOpenfile.Title = "添加shapefile文件";
pOpenfile.Filter = "*(.shp)|*.shp";
pOpenfile.ShowDialog();
ILayerFactoryHelper pLayerFactoryHelper = new
地理信息系统
江西师范大学
LayerFactoryHelperClass();
IFileName filename = new FileNameClass();
filename.Path = pOpenfile.FileName;
IEnumLayer enumlayer =
pLayerFactoryHelper.CreateLayersFromName(filename as IName);
ILayer layer;
enumlayer.Reset();
layer = enumlayer.Next();
while (layer != null)
{
axSceneControl1.SceneGraph.Scene.AddLayer(layer, false);
layer = enumlayer.Next();
axSceneControl1.SceneGraph.RefreshViewers();
}
}
catch
{
return;
}
}
///
/// 打开TIN文件
///
///
///
private void 打开TIN文件ToolStripMenuItem_Click(object sender, EventArgs
e)
{
//string dirName;
//ILayer pLayer;
//FolderBrowserDialog folderBrowserDialog1 = new
FolderBrowserDialog();
//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
{
FolderBrowserDialog openFileDialog1 = new
FolderBrowserDialog();
//openFileDialog1.Title = "添加TIN数据";
//openFileDialog1.Filter = "TIFF格式(*.tif)|*.tif|Img格式
(*.img)|*.img|Bmp格式(*.bmp)|*.bmp|Jpeg格式(*.jpg)|*.jpg";
openFileDialog1.ShowDialog();
string sFilePath;
sFilePath = openFileDialog1.SelectedPath;
ITin pTIN = new Tin3DPropertiesClass() as ITin ;
ITinLayer pTINLyr = new TinLayerClass();
pTINLyr.Dataset = pTIN;
//pTINLyr.
axSceneControl1.Scene.AddLayer(pTINLyr);
axSceneControl1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
//ITin pTIN = new pTIN();
//ITinLayer pTINLyr = new TinLayerClass();
//pTINLyr.Dataset = pTIN;
//axSceneControl1.Scene.AddLayer(pTINLyr);
}
///
/// 保存场景图片
///
///
///
private void 保存场景图片ToolStripMenuItem_Click(object sender,
地理信息系统
江西师范大学
EventArgs e)
{
try
{
string sFileName;
SaveFileDialog pSaveFile = new SaveFileDialog();
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("出现错误返回");
}
}
///
/// 退出
///
///
///
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
#endregion
地理信息系统
江西师范大学
#region //基本操作
//放大
private void button1_Click(object sender, EventArgs e)
{
axSceneControl1.Camera.Zoom(0.9);
axSceneControl1.Refresh();
}
//缩小
private void button2_Click(object sender, EventArgs e)
{
axSceneControl1.Camera.Zoom(1.1);
axSceneControl1.Refresh();
}
//漫游
private void button3_Click(object sender, EventArgs e)
{
axSceneControl1.Navigate = true;
}
//平移
private void button4_Click(object sender, EventArgs e)
{
scenePan = true;
}
//窗体事件
private void axSceneControl1_OnMouseDown(object sender,
ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvent e)
{
//鼠标漫游
if (scenePan)
{
//if (CreaterKeyFrameSwitch)
//{
//
CreateKeyFrame(axSceneControl1.Scene, Playtrl, KeyIndex);
KeyIndex = KeyIndex + 1;
//
//}
if (clickSceneTime == 0)
{
scenePanPoints1.PutCoords(e.x, e.y);
地理信息系统
江西师范大学
clickSceneTime = 1;
}
else if (clickSceneTime == 1)
{
scenePanPoints2.PutCoords(e.x, e.y);
axSceneControl1.Camera.Pan(scenePanPoints1,
scenePanPoints2);
axSceneControl1.Refresh();
clickSceneTime = 0;
scenePan = false;
}
}
//鼠标点击查询
if (pIdnetifyIsOrNot == true)
{
IHit3DSet pHit3DSet;
axSceneControl1.SceneGraph.LocateMultiple(axSceneControl1.SceneGraph.ActiveView
er, e.x, e.y, esriScenePickMode.esriScenePickAll, false, out pHit3DSet);
pHit3DSet.OnePerLayer();
if (pHit3DSet.Hits.Count == 0)
{
MessageBox.Show("当前点未能查找到任何要素");
}
IHit3D pHit3D = pHit3DSet.Hits.get_Element(0) as IHit3D;
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);
}
}
//自动旋转
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
timer1.Enabled = true;
}
地理信息系统