失量转栅格_密度图的实现.doc_第1页
失量转栅格_密度图的实现.doc_第2页
失量转栅格_密度图的实现.doc_第3页
失量转栅格_密度图的实现.doc_第4页
失量转栅格_密度图的实现.doc_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

地理信息系统生产实习报告编程第二组专业:地理信息系统年级: 620802姓 名:周海、李秀峰、赵乾坤学号: 62080224、62080203、62080210指导教师:杨长保实习单位:吉林大学朝阳校区 时 间: 2011年7月4日2011年8月28日本小组主要负责叠加分析部分:4.5.3叠加分析的实现叠加分析包括五项功能矢量转栅格、生成密度图、生成距离图、重分类、栅格计算。本阶段实习实现了失量转栅格、生成密度图等。在菜单栏中加入如下菜单项:在主菜单空间分析下加入叠加分析选项,在叠加分析子选项中添加矢量转栅格、生成密度图、生成距离图、重分类、栅格计算。添加空间分析下加入叠加分析,添加叠加分析子菜单如图: 矢量转栅格的实现“矢量转栅格” 的click代码实现如下: Feature_to_Raster ftr = new Feature_to_Raster(this); ftr.Show();打开新建窗体对话框,在此窗体的类别中选择Visual C#项目类,在右侧的模板中选择windows窗体,窗体名称为Feature_to_Raster,单击添加按钮,向项目中添加一个名为Feature_to_Raster的windows窗体。右键单击Feature_to_Raster,单击右键菜单中的“view code”。在public partial class Feature_to_Raster:后粘入如下代码DevComponents.DotNetBar.Office2007Form,样式变为Office2007的窗体样式。设其属性中的Text及name改为“Feature_to_Raster”。 向窗体中加入四个Label、两个TextBox、两个ComboBox和四个Button控件并设置其属性如下:NameTextLable1Lable1输入图层Lable2Lable2选择字段Lable3Lable3像元大小Lable4Lable4栅格输出TextBox1txtCellSizeTextBox2txtOutPathComboBox1comboBoxInDataComboBox2comboBoxFieldButton1btnOpen输入Button2btnSave输出Button3btnGO确定Button4btnCancel取消窗体的样式如下图所示:在Feature_to_Raster的代码中加入如下引用代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesRaster;using ESRI.ArcGIS.GeoAnalyst;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.SpatialAnalyst;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.NetworkAnalyst;using ESRI.ArcGIS.Utility;using ESRI.ArcGIS.NetworkAnalysis;using ESRI.ArcGIS.Analyst3D;如图所示:添加变量:private campusGISFrm pMainFrm = null;private bool bFeatDataPath = false;private bool bRasterDataPath = false;修改Public Feature_to_Raster ()函数如下所示:public Feature_to_Raster(campusGISFrm _pMainFrm) pMainFrm = _pMainFrm; InitializeComponent(); 给窗体load事件添加函数,双击窗体加入代码:private void Feature_to_Raster_Load(object sender, EventArgs e) comboBoxField.Items.Add(无); PopulateComboWithMapLayers(comboBoxInData, true); /调用函数 PopulateComboWithMapLayers /txtCellSize.Text = (string)0; /pMainFrm.SAoption.RasterCellSize.ToString(); txtOutPath.Text = System.IO.Path.GetTempPath(); /pMainFrm.SAoption.AnalysisPath; 返回窗体界面,分别双击四个Button控件,在代码窗口得到这三个按钮的Click事件,在这三个控件的Click事件中加入如下代码: private void btnOpen_Click(object sender, EventArgs e) OpenFileDialog openFileDialog1 = new OpenFileDialog(); /新建打开路径 openFileDialog1.InitialDirectory = System.IO.Path.GetTempPath(); /pMainFrm.SAoption.AnalysisPath; /使打开路径初始为主窗体分析路径 openFileDialog1.Filter = Shape Files (*.shp)|*.shp|All files (*.*)|*.*; /筛选文件 if (openFileDialog1.ShowDialog() = DialogResult.OK) comboBoxInData.Text = openFileDialog1.FileName; /使打开路径显示打开的文件名 bFeatDataPath = true; /改bFeatDataPath为真 private void btnSave_Click(object sender, EventArgs e) SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = System.IO.Path.GetTempPath(); / pMainFrm.SAoption.AnalysisPath; /设路径为主窗体分析路径 saveFileDialog1.Filter = Image Files (*.img)|*.img|All files (*.*)|*.*; /过滤文件格式 if (saveFileDialog1.ShowDialog() = DialogResult.OK) txtOutPath.Text = saveFileDialog1.FileName; bRasterDataPath = true; /改bRasterDataPath为真 private void btnGO_Click(object sender, EventArgs e) string fileName; string shpFile; int startX, endX; string shpDir; IFeatureClass pFClass = null; if (bFeatDataPath = true) /数据输入为真 fileName = comboBoxInData.Text; /令fileName等于输入文件名 shpDir = fileName.Substring(0, fileName.LastIndexOf(); / startX = fileName.LastIndexOf(); /令startX等于输入文件名最后字段 endX = fileName.Length; /文件名字段 shpFile = fileName.Substring(startX + 1, endX - startX - 1); / pFClass = OpenFeatureClassFromShapefile(shpDir, shpFile); /使pFClass等于打开的Shapefile文件的要数 else pFClass = GetFeatureFromMapLyr(comboBoxInData.Text);/GetFeatureFromMapLyr函数 if (bRasterDataPath = true) fileName = txtOutPath.Text; shpDir = fileName.Substring(0, fileName.LastIndexOf(); startX = fileName.LastIndexOf(); endX = fileName.Length; shpFile = fileName.Substring(startX + 1, endX - startX - 1); else shpDir = txtOutPath.Text; shpFile = 特征转栅格; IGeoDataset pTempDS = pFClass as IGeoDataset; /数据集pTempDS等于pFClass(见上) IFeatureLayer pFeatLayer = new FeatureLayerClass(); /建pFeatLayer要素层为矢量类 pFeatLayer.FeatureClass = pFClass; /使pFeatLayer的FeatureClass等于 pFClass IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass(); /新建矢量描述集pFeatClsDes if (comboBoxField.Text != 无) pFeatClsDes.Create(pFClass, null, comboBoxField.Text); /若字段为空则新建 else pFeatClsDes.Create(pFClass, null, ); /新建 pTempDS = pFeatClsDes as IGeoDataset; /使pTempDS数据集等于pFeatClsDes try IConversionOp pConversionOp = new RasterConversionOpClass();/新建转换函数 string sCellSize = txtCellSize.Text; double dCellSize = Convert.ToDouble(sCellSize); pConversionOp = SetFeatToRasterAnalysisEnv(shpDir, dCellSize, pFeatLayer); /调用矢量转栅格函数 if (File.Exists(shpDir + + shpFile + .img) = true) File.Delete(shpDir + + shpFile + .img); /若文件已存在则删除 IWorkspace pWS = setRasterWorkspace(shpDir); /新建栅格工作空间 IRasterDataset pRasterDs = pConversionOp.ToRasterDataset(pTempDS, IMAGINE Image, pWS, shpFile); /新建栅格数据集并等于转换函数转换的数据集 ITemporaryDataset pTempRaster = pRasterDs as ITemporaryDataset; /新建临时数据集并等于pRasterDs if (pTempRaster.IsTemporary() = true) /临时数据集为真 pTempRaster.MakePermanent(); /保存临时数据集 IRaster pOutRaster = pRasterDs.CreateDefaultRaster(); /输出栅格 IRasterLayer pRasterLayer = SetStretchRenderer(pOutRaster); /新建栅格图层 pMainFrm.getMainAxMapControl().AddLayer(pRasterLayer, 0); /在主窗体中添加栅格图层 catch (Exception ex) MessageBox.Show(ex.Message); private void btnCancel_Click(object sender, EventArgs e) this.Dispose(); 双击“comboBoxInData”给其添加下面代码实现输入图层选择:private void comboBoxInData_SelectedIndexChanged(object sender, EventArgs e) string sLayerName = comboBoxInData.Text; /定义图层名并初始化sLayerName为输入数据名 AxMapControl axMap = pMainFrm.getMainAxMapControl();/. / axMapControl(); /建axMap,使它等于主窗体MainAxMapControl IFeatureLayer pFeatLyr = null; /新建矢量图层并设为空 comboBoxField.Items.Clear(); /清除图层字段 comboBoxField.Items.Add(无); try /添加图层字段“无” for (int i = 0; i = axMap.LayerCount - 1; i+) /依次添加图层 ILayer pLyr = axMap.get_Layer(i); /获取axMap的图层 if (pLyr.Name = sLayerName) /如果获取axMap的图层pLyr与sLayerName相同 if (pLyr is IFeatureLayer) /若pLyr为矢量图层 pFeatLyr = pLyr as IFeatureLayer; IFeatureClass m_pFeatCls = pFeatLyr.FeatureClass; /新建要素类m_pFeatCls for (int j = 0; j = m_pFeatCls.Fields.FieldCount - 1; j+) /将m_pFeatCls的字段名添加到字段下拉菜单中 comboBoxField.Items.Add(m_pFeatCls.Fields.get_Field(j).Name); catch (Exception ex) MessageBox.Show(ex.Message); /弹出消息 添加自定义函数: private void PopulateComboWithMapLayers(ComboBox Layers, bool bLayer /自定义加载函数 Layers.Items.Clear(); ILayer aLayer; /新建图层 AxMapControl axMap = pMainFrm.getMainAxMapControl(); /定义AxMapControl axMap for (int i = 0; i = axMap.LayerCount - 1; i+) / Get the layer name and add to combo /将图层名添加到下拉菜单中 aLayer = axMap.get_Layer(i); if (aLayer.Valid = true) if (bLayer = true) if (aLayer is IFeatureLayer) Layers.Items.Add(aLayer.Name); private IFeatureClass GetFeatureFromMapLyr(string sLyrName) /从地图图层中获得特征类数据图层 AxMapControl axMap = pMainFrm.getMainAxMapControl(); /.getMainAxMapControl(); IFeatureClass pFeatCls = null; for (int i = 0; i = axMap.LayerCount - 1; i+) ILayer pLyr = axMap.get_Layer(i); if (pLyr != null) if (pLyr.Name = sLyrName) if (pLyr is IFeatureLayer) IFeatureLayer pFLyr = pLyr as IFeatureLayer; pFeatCls = pFLyr.FeatureClass; return pFeatCls; public static IFeatureClass OpenFeatureClassFromShapefile(string sPath, string sShapeName) IFeatureClass rltFClass = null; IWorkspaceFactory pWSFact; IWorkspace pWS; IFeatureWorkspace pFWS; try pWSFact = new ShapefileWorkspaceFactoryClass(); pWS = pWSFact.OpenFromFile(sPath, 0); pFWS = pWS as IFeatureWorkspace; rltFClass = pFWS.OpenFeatureClass(sShapeName); catch (Exception e) MessageBox.Show(e.Message); return null; return rltFClass; /设置特征转换栅格分析环境public static IConversionOp SetFeatToRasterAnalysisEnv(string rasterpath, double cellsize, IFeatureLayer pFeatLayer) object Missing = Type.Missing; IWorkspace pWorkspace = setRasterWorkspace(rasterpath); IConversionOp pConversionOp = new RasterConversionOpClass(); IRasterAnalysisEnvironment pRsEnv = pConversionOp as IRasterAnalysisEnvironment; pRsEnv.OutWorkspace = pWorkspace; /装箱操作 object objCellSize = cellsize; pRsEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objCellSize); IEnvelope pEnv = new EnvelopeClass(); pEnv.XMin = pFeatLayer.AreaOfInterest.XMin; pEnv.XMax = pFeatLayer.AreaOfInterest.XMax; pEnv.YMin = pFeatLayer.AreaOfInterest.YMin; pEnv.YMax = pFeatLayer.AreaOfInterest.YMax; object objExtent = pEnv; pRsEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref Missing); return pConversionOp; /设置栅格分析环境public static IWorkspace setRasterWorkspace(string sPath) IWorkspaceFactory pWSF; pWSF = new RasterWorkspaceFactoryClass() as IWorkspaceFactory; / if(pWSF.IsWorkspace(sPath) return pWSF.OpenFromFile(sPath, 0) as IWorkspace;/ /else / return null; public static IRasterLayer SetStretchRenderer(IRaster pRaster) try /创建着色类和QI栅格着色 IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRendererClass(); IRasterRenderer pRasRen = pStretchRen as IRasterRenderer;/为着色和更新设置栅格数据 pRasRen.Raster = pRaster; pRasRen.Update(); /定义起点和终点颜色 IColor pFromColor = new RgbColorClass(); IRgbColor pRgbColor = pFromColor as IRgbColor; pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; IColor pToColor = new RgbColorClass(); pRgbColor = pToColor as IRgbColor; pRgbColor.Red = 0; pRgbColor.Green = 255; pRgbColor.Blue = 0; /创建颜色分级 IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool ok = true; pRamp.CreateRamp(out ok); /把颜色分级插入着色中并选择一个波段 pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; pRasRen.Update(); IRasterLayer pRLayer = new RasterLayerClass(); pRLayer.CreateFromRaster(pRaster); pRLayer.Renderer = pStretchRen as IRasterRenderer; return pRLayer; catch (Exception ex) Console.WriteLine(ex.Message); return null; 在注窗体中campusGISFrm添加如下函数:public ESRI.ArcGIS.Controls.AxMapControl getMapControl() return axMapControl; public ESRI.ArcGIS.Controls.AxMapControl getMainAxMapControl() return axMapControl; 到此,完成矢量转栅格功能。运行程序,加载一个校区的平面图,或加载其他矢量数据,主界面如图所示,点击空间分析下矢量转栅格按钮,打开是来那个转栅格对话框,如下图所示:通过输入添加数据,我们选择朝阳校区教学楼,像元大小为20,选择输出路径,点击确定按钮,如下图:结果如图:生成密度图的实现双击空间分析叠加分析生成密度图,加入以下代码:frmDensity fds = new frmDensity(this);fds.Show();打开新建窗体对话框,在此窗体的类别中选择Visual C#项目类,在右侧的模板中选择windows窗体,窗体名称为frmDensity,单击添加按钮,向项目中添加一个名为frmDensity的windows窗体。右键单击frmDensity,单击右键菜单中的“view code”。在public partial class frmDensity:后粘入如下代码DevComponents.DotNetBar.Office2007Form,样式变为Office2007的窗体样式。设其属性中的Text及name改为“frmDensity”。向窗体中加入七个Label控件,三个TextBox控件,三个ComboBox控件,四个Button控件及两个radioButton并设置其属性如下:NameTextLable1Lable1输入数据:Lable2Lable2分析字段:Lable3Lable3密度计算类型:Lable4Lable4搜索半径Lable5Lable5面积单位:Lable6Lable6输出象素大小:Lable7Lable7输出栅格位置:TextBox1txtSearchRadiusTextBox2txtCellSizeTextBox3txtRasterPathComboBox1comboBoxInDataComboBox2comboBoxFieldComboBox3comboBoxAreaUnitButton1btnOpenSourceDataButton2btnSaveRasterButton3btnGO确定Button4btnCancel取消radioButtonrdoKernelKernelradioButtonrdoSimpleSimple视图如下:在Feature_to_Raster的代码中覆盖如下引用代码:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.DataSourcesGDB;using ESRI.ArcGIS.DataSourcesFile;using ESRI.ArcGIS.NetworkAnalyst;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesRaster;using ESRI.ArcGIS.GeoAnalyst;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.SpatialAnalyst;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Controls;在下图位置添加变量:private campusGISFrm pMainFrm = null;private bool bDataPath;修改Public frmDensity ()函数如下所示:public frmDensity(campusGISFrm _pMainFrm) / / Windows 窗体设计器支持所必需的 / pMainFrm = _pMainFrm; InitializeComponent(); 首先添加自定义函数:/*添加自定义函数* public static IFeatureClass OpenFeatureClassFromShapefile(string sPath, string sShapeName) IFeatureClass rltFClass = null; IWorkspaceFactory pWSFact; IWorkspace pWS; IFeatureWorkspace pFWS; try pWSFact = new ShapefileWorkspaceFactoryClass(); pWS = pWSFact.OpenFromFile(sPath, 0); pFWS = pWS as IFeatureWorkspace; rltFClass = pFWS.OpenFeatureClass(sShapeName); catch (Exception e) MessageBox.Show(e.Message); return null; return rltFClass; /新建工作空间 public static IWorkspace setRasterWorkspace(string sPath) IWorkspa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论