本科生实验报告-GIS课程设计(开发)_第1页
本科生实验报告-GIS课程设计(开发)_第2页
本科生实验报告-GIS课程设计(开发)_第3页
本科生实验报告-GIS课程设计(开发)_第4页
本科生实验报告-GIS课程设计(开发)_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

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

文档简介

1、本科生实验报告实验课程 GIS课程设计(开发) 学院名称 地球科学学院 专业名称 地理信息科学 学生姓名 学生学号 指导教师 实验地点 实验成绩 二一六年 12月 二一七年1月摘 要针对GIS空间分析与建模课程讲授的基本算法设计和软件使用要求,本实验报告分别就多边形裁剪线段、多边形裁剪多边形、点与线的关系判断、泰森多边形的构建、求解最短路径等重要空间分析算法和提取中心线等进行了上机实验,通过实验对这些空间分析算法的基本思想、算法分析及算法实现过程有了更深入的理解。从理论和实践角度加深了对GIS空间分析与建模课程的认知程度,学会了如何分析现实的GIS问题及设计相应的数据结构和算法来解决问题。关键

2、词:空间分析、算法、裁剪、多边形、线、点、tin、最短路径 目录 TOC o 1-3 h z u HYPERLINK l _Toc471309269 ArcEngine二次开发实验:地物分类统计 ArcEngine二次开发实验:地物分类统计一. 实验目的(1)熟练搭建ArcEngine开发环境,了解ArcEngine和ArcObjects相关接口和实体类(2)利用ArcEngine实现地物分类统计,缓冲区运算,拓扑运算和地图导出等功能(3)进一步熟悉ArcEngine开发接口以及高级功能,加深对GIS空间分析和空间统计的理解二. 实验内容利用C#语言、VS开发工具、ArcEngine开发平台实

3、现地物分类统计三. 地物分类统计技术流程3.1 算法思想及算法流程图算法基本思想: (1)二次开发Com组件ITool,分别是用于线统计和面统计两类的工具(2)数据输入及相关初始化 ,选择统计工具(3)如果统计工具是面统计,则获取地图控件的轨迹多边形,否则就是线统计,获取地图控件的轨迹线,并对线做35的缓冲区。使用IElement接口绘图,然后使用IActivView导出地图(4)使用IQueryFilter进行空间查询,然后使用IDataStatistics接口统计地类名称字段的值集合(5)遍历上步中的值集合,每个迭代中通过值构造sql语句where条件”地类名称=值”,同时结合(3)步中的

4、轨迹多边形或者缓冲区,运用ISpatialFilter进行空间查询。遍历每个要素,统计该要素与轨迹多边形或缓冲区的相交图形的距离,从而得出每类地物的面积(6)使用IArea求出轨迹多边形或者缓冲区的总面积(7)相关结果可视化展示(8)算法结束算法流程图:图 SEQ 图 * ARABIC 1地物分类统计流程图3.2 关键代码实现该算法的核心代码如下:统计工具:/ / Summary description for StaticTool. / Guid(0428808a-4782-4f81-a0b3-93be6e9226dc) ClassInterface(ClassInterfaceType.N

5、one) ProgId(GisStatistics.Com.StaticTool) public sealed class PolygonStaticTool : BaseTool #region COM Registration Function(s) ComRegisterFunction() ComVisible(false) static void RegisterFunction(Type registerType) / Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistratio

6、n(registerType); / / TODO: Add any COM registration code here / ComUnregisterFunction() ComVisible(false) static void UnregisterFunction(Type registerType) / Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); / / TODO: Add any COM unregistration code

7、 here / #region ArcGIS Component Category Registrar generated code / / Required method for ArcGIS Component Category registration - / Do not modify the contents of this method with the code editor. / private static void ArcGISCategoryRegistration(Type registerType) string regKey = string.Format(HKEY

8、_CLASSES_ROOTCLSID0, registerType.GUID); MxCommands.Register(regKey); ControlsCommands.Register(regKey); / / Required method for ArcGIS Component Category unregistration - / Do not modify the contents of this method with the code editor. / private static void ArcGISCategoryUnregistration(Type regist

9、erType) string regKey = string.Format(HKEY_CLASSES_ROOTCLSID0, registerType.GUID); MxCommands.Unregister(regKey); ControlsCommands.Unregister(regKey); #endregion #endregion private IHookHelper m_hookHelper = null; private IMapControl3 mapControl = null; private IToolbarControl toolBarControl = null;

10、 public PolygonStaticTool() / / TODO: Define values for the public properties / base.m_category = ; /localizable text base.m_caption = 面统计; /localizable text base.m_message = 面统计; /localizable text base.m_toolTip = 使用多边形进行统计; /localizable text base.m_name = 面统计; /unique id, non-localizable (e.g. MyC

11、ategory_MyTool) try / / TODO: change resource name if necessary / string bitmapResourceName = GetType().Name + .bmp; base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + .cur); catch (Exception ex) System.Diagnostics.T

12、race.WriteLine(ex.Message, Invalid Bitmap); #region Overridden Class Methods / / Occurs when this tool is created / / Instance of the application public override void OnCreate(object hook) try m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; if (m_hookHelper.ActiveView = null) m_hookH

13、elper = null; catch m_hookHelper = null; if (m_hookHelper = null) base.m_enabled = false; else base.m_enabled = true; / TODO: Add other initialization code this.toolBarControl = hook as IToolbarControl; this.mapControl = this.toolBarControl.Buddy as IMapControl3; / / Occurs when this tool is clicked

14、 / public override void OnClick() / TODO: Add StaticTool.OnClick implementation this.mapControl.CurrentTool = this; public override void OnMouseDown(int Button, int Shift, int X, int Y) / TODO: Add StaticTool.OnMouseDown implementation if (Button = 1) IGeometry pGeometry = this.mapControl.TrackPolyg

15、on(); SymbolUtil.InsertNormalLineElement(mapControl, TopologicOpreatorUtil.GetGeometryBoundary(pGeometry) ,255, 0, 0); new StatisForm(pGeometry, this.mapControl, OutputImage(pGeometry).ShowDialog(); SymbolUtil.ClearElement(mapControl); private void outPutArea(IGeometry pGeometry) ITopologicalOperato

16、r pTopologicOperator = pGeometry as ITopologicalOperator; pTopologicOperator.Simplify(); / pTopologicOperator.Clip IActiveView pActiveView = this.mapControl as IActiveView; / PictureBox p=new PictureBox(); / pActiveView.Output(); public override void OnMouseMove(int Button, int Shift, int X, int Y)

17、/ TODO: Add StaticTool.OnMouseMove implementation public override void OnMouseUp(int Button, int Shift, int X, int Y) / TODO: Add StaticTool.OnMouseUp implementation private Image OutputImage(IGeometry pGeometry) return MapImageUtil.SaveCurrentToImage(mapControl.Map, 331, 151, pGeometry.Envelope); #

18、endregion / / Summary description for PolylineStaticTool. / Guid(62751d8d-07b3-4d84-a559-5ebdafbb4e0e) ClassInterface(ClassInterfaceType.None) ProgId(GisStatistics.Com.PolylineStaticTool) public sealed class PolylineStaticTool : BaseTool #region COM Registration Function(s) ComRegisterFunction() Com

19、Visible(false) static void RegisterFunction(Type registerType) / Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); / / TODO: Add any COM registration code here / ComUnregisterFunction() ComVisible(false) static void UnregisterFunction(Type registerTyp

20、e) / Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); / / TODO: Add any COM unregistration code here / #region ArcGIS Component Category Registrar generated code / / Required method for ArcGIS Component Category registration - / Do not modify the c

21、ontents of this method with the code editor. / private static void ArcGISCategoryRegistration(Type registerType) string regKey = string.Format(HKEY_CLASSES_ROOTCLSID0, registerType.GUID); MxCommands.Register(regKey); ControlsCommands.Register(regKey); / / Required method for ArcGIS Component Categor

22、y unregistration - / Do not modify the contents of this method with the code editor. / private static void ArcGISCategoryUnregistration(Type registerType) string regKey = string.Format(HKEY_CLASSES_ROOTCLSID0, registerType.GUID); MxCommands.Unregister(regKey); ControlsCommands.Unregister(regKey); #e

23、ndregion #endregion private IHookHelper m_hookHelper = null; private IMapControl3 mapControl = null; private IToolbarControl toolBarControl = null; public PolylineStaticTool() / / TODO: Define values for the public properties / base.m_category = ; /localizable text base.m_caption = 线统计; /localizable

24、 text base.m_message = 线统计; /localizable text base.m_toolTip = 使用线段缓冲区进行统计; /localizable text base.m_name = 线统计; /unique id, non-localizable (e.g. MyCategory_MyTool) try / / TODO: change resource name if necessary / string bitmapResourceName = GetType().Name + .bmp; base.m_bitmap = new Bitmap(GetTyp

25、e(), bitmapResourceName); base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + .cur); catch (Exception ex) System.Diagnostics.Trace.WriteLine(ex.Message, Invalid Bitmap); #region Overridden Class Methods / / Occurs when this tool is created / / Instance of the application publ

26、ic override void OnCreate(object hook) try m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; if (m_hookHelper.ActiveView = null) m_hookHelper = null; catch m_hookHelper = null; if (m_hookHelper = null) base.m_enabled = false; else base.m_enabled = true; / TODO: Add other initialization

27、 code this.toolBarControl = hook as IToolbarControl; this.mapControl = this.toolBarControl.Buddy as IMapControl3; / / Occurs when this tool is clicked / public override void OnClick() / TODO: Add PolylineStaticTool.OnClick implementation public override void OnMouseDown(int Button, int Shift, int X,

28、 int Y) / TODO: Add PolylineStaticTool.OnMouseDown implementation if (Button = 1) IGeometry pGeometry = this.mapControl.TrackLine(); ITopologicalOperator pTopoOpreator = pGeometry as ITopologicalOperator; IGeometry newGeometry= pTopoOpreator.Buffer(35); SymbolUtil.InsertNormalLineElement(mapControl,

29、 pGeometry, 255, 0, 0); SymbolUtil.InsertNormalLineElement(mapControl, TopologicOpreatorUtil.GetGeometryBoundary(newGeometry), 0, 255, 0); new StatisForm(newGeometry, this.mapControl, OutputImage(pGeometry).ShowDialog(); SymbolUtil.ClearElement(mapControl); public override void OnMouseMove(int Butto

30、n, int Shift, int X, int Y) / TODO: Add PolylineStaticTool.OnMouseMove implementation public override void OnMouseUp(int Button, int Shift, int X, int Y) / TODO: Add PolylineStaticTool.OnMouseUp implementation #endregion private Image OutputImage(IGeometry pGeometry) return MapImageUtil.SaveCurrentT

31、oImage(mapControl.Map, 331, 151, pGeometry.Envelope); 核心统计类:/ / 空间查询与操作帮助类 / 2015/12/11 fhr / class FeatureDealUtil public static bool UpdateFeature(IList pfeatuers, DataTable dataTable) for (int i = 0; i dataTable.Rows.Count; i+) IFeature pFeature = pfeatuersi; DataRow dRow = dataTable.Rowsi; bool

32、isUpdate = false; for (int j = 0; j dRow.ItemArray.Count(); j+) IField pField = pFeature.Fields.get_Field(j); if (!pField.Editable) continue; if (pField.Type = esriFieldType.esriFieldTypeBlob | pField.Type = esriFieldType.esriFieldTypeRaster | pField.Type = esriFieldType.esriFieldTypeGeometry) conti

33、nue; if (pFeature.get_Value(j) != dRowj) isUpdate = true; object value=dRowj; if (pFeature.Fields.get_Field(j).CheckValue(value) pFeature.set_Value(j, value); if (isUpdate) pFeature.Store(); return true; / / 统计某一段各值的个数 / / / / public static IDictionary QueryLayerCountForUnikevalues(IFeatureLayer lay

34、er,string fieldName,IGeometry pGeometry) IDictionary result = new Dictionary(); IList values = GetUnikeValues(layer, fieldName); foreach (string value in values) string where = string.Format(0 = 1, fieldName, value); Int32 count = GetLayerCount(layer,pGeometry, where,fieldName); result.Add(value, co

35、unt); return result; public static IDictionary QueryLayerAreaForUnikevalues(IFeatureLayer layer, string fieldName, IGeometry pGeometry) IDictionary result = new Dictionary(); IList values = GetUnikeValues(layer, fieldName); foreach (string value in values) string where = string.Format(0 = 1, fieldNa

36、me, value); double count = GetLayerClipArea(layer, pGeometry, where, fieldName); result.Add(value, count); return result; public static IList GetUnikeValues(IFeatureLayer layer, string fieldName) IList values = new List(); IFeatureCursor pFeatureCursor = QueryFeatureInLayer(layer, ); IDataStatistics

37、 dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = pFeatureCursor as ICursor ; dataStatistics.Field = fieldName; / IStatisticsResults result = dataStatistics.Statistics; IEnumerator myEnumerator = dataStatistics.UniqueValues; List myValueList = new List(); myEnumerator.Reset(); whi

38、le (myEnumerator.MoveNext() if (myEnumerator.Current != null) values.Add(myEnumerator.Current.ToString(); / IStatisticsResults result= dataStatistics.Statistics; return values; public static Int32 GetLayerCount(IFeatureLayer layer, IGeometry pGeometry, string where, string fieldName) ICursor pCursor

39、=QueryFeatureInLayer(layer, pGeometry, where) as ICursor; / return GetLayerCount(pCursor, fieldName); return GetLayerCount(pCursor); public static double GetLayerClipArea(IFeatureLayer layer, IGeometry pGeometry, string where, string fieldName) ICursor pCursor = QueryFeatureInLayer(layer, pGeometry,

40、 where) as ICursor; / return GetLayerCount(pCursor, fieldName); return GetLayerClipArea(pCursor, pGeometry); public static Int32 GetLayerCount(ICursor pCursor,string fieldName) IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.SimpleStats = true; dataStatistics.Cursor = pCur

41、sor; dataStatistics.Field = fieldName; IStatisticsResults pStatisticsResult = dataStatistics.Statistics; return pStatisticsResult.Count; public static Int32 GetLayerCount(ICursor pCursor) int count = 0; IFeatureCursor cursor = pCursor as IFeatureCursor; while (cursor.NextFeature()!=null) count+; ret

42、urn count; public static double GetLayerClipArea(ICursor pCursor,IGeometry originGeo) double area = 0; IFeatureCursor cursor = pCursor as IFeatureCursor; IFeature pFeature = cursor.NextFeature(); while (pFeature != null) ITopologicalOperator pTopo = pFeature.Shape as ITopologicalOperator; IGeometry

43、geometry = pTopo.Intersect(originGeo, esriGeometryDimension.esriGeometry2Dimension); area += (geometry as IArea).Area; pFeature = cursor.NextFeature(); return area; / / 利用语句进行查询 返回游标和查询过滤类 / / / / public static IFeatureCursor QueryFeatureInLayer(IFeatureLayer featureLayer, String whereClause) IFeatu

44、reCursor featureCursor = null; IQueryFilter2 queryFilter = new QueryFilterClass(); queryFilter.WhereClause = whereClause; IFeatureClass featureClass = featureLayer.FeatureClass; featureCursor = featureClass.Search(queryFilter, false); return featureCursor; / / 利用语句进行查询 返回游标和查询过滤类 / / / / / public st

45、atic IFeatureCursor QueryFeatureInLayer(IFeatureLayer featureLayer, String whereClause,ref IQueryFilter queryFilterCopy) IFeatureCursor featureCursor = null; IQueryFilter2 queryFilter = new QueryFilterClass(); queryFilter.WhereClause = whereClause; IFeatureClass featureClass = featureLayer.FeatureCl

46、ass; featureCursor=featureClass.Search(queryFilter, false); queryFilterCopy = queryFilter; return featureCursor; / / 利用空间位置进行查询 返回游标和查询过滤类 / / / / / public static IFeatureCursor QueryFeatureInLayer(IFeatureLayer featureLayer, IGeometry geometry, ref IQueryFilter queryFilterCopy) IFeatureCursor featu

47、reCursor = null; ISpatialFilter spatialFilter = new SpatialFilter(); switch (featureLayer.FeatureClass.ShapeType) case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel

48、 = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; spatialFilter.Geometry = geometry; IFeatureClass featureClass = featureLayer.FeatureClass; featureCursor = featureClass.Sea

49、rch(spatialFilter, false); queryFilterCopy = spatialFilter; return featureCursor; / / 利用空间位置进行查询 返回游标和查询过滤类 / / / / public static IFeatureCursor QueryFeatureInLayer(IFeatureLayer featureLayer, IGeometry geometry) IFeatureCursor featureCursor = null; ISpatialFilter spatialFilter = new SpatialFilter()

50、; switch (featureLayer.FeatureClass.ShapeType) case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeo

51、metryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; spatialFilter.Geometry = geometry; IFeatureClass featureClass = featureLayer.FeatureClass; featureCursor = featureClass.Search(spatialFilter, false); return featureCursor; / / 利用空间位置进行查询 返回游

52、标和查询过滤类 / / / / / public static IFeatureCursor QueryFeatureInLayer(IFeatureLayer featureLayer, IGeometry geometry,string where) IFeatureCursor featureCursor = null; ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.WhereClause = where; switch (featureLayer.FeatureClass.ShapeType) case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeom

温馨提示

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

评论

0/150

提交评论