GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx

上传人:夺命阿水 文档编号:889820 上传时间:2024-01-08 格式:DOCX 页数:19 大小:124.03KB
返回 下载 相关 举报
GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx_第1页
第1页 / 共19页
GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx_第2页
第2页 / 共19页
GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx_第3页
第3页 / 共19页
GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx_第4页
第4页 / 共19页
GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx》由会员分享,可在线阅读,更多相关《GIS课程设计(开发)实验报告--ArcEngine二次开发实验:地物分类统计.docx(19页珍藏版)》请在课桌文档上搜索。

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

2、地物分类统计1-实验目的1二 .实验内容1三 .地物分类统计技术流程13.1 算法思想及算法流程图13.2 关键代码23.3 3算法实现17四 .实验总结18ArCEngine二次开发实验:地物分类统计实验目的(1)熟练搭建ArCEngine开发环境,了解ArCEngine和ArCObjeCtS相关接口和实体类(2)利用ArCEngine实现地物分类统计,缓冲区运算,拓扑运算和地图导出等功能(3)进一步熟悉ArCEngine开发接口以及高级功能,加深对GIS空间分析和空间统计的理解二.实验内容利用C#语言、VS开发工具、ArCEngine开发平台实现地物分类统计三.地物分类统计技术流程3.1算

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

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

5、edclassPolygonStaticTool:BaseTool(#regionCOMRegistrationEunction(s)ComRegisterFunctionOComVisible(false)staticvoidRegisterFunction(TyperegiSterType)(/RequiredforArcGISComponentCategoryRegistrarsupportArcGISCategoryRegistration(registerType);/TODO:AddanyCOMregistrationcodehere/)ComUnregiSterFunctionO

6、ComVisible(false)staticvoidUnregisterFunction(TyperegiSterType)/RequiredforArcGISComponentCategoryRegistrarsupportArcGlSCategoryUnregistration(registerType);/TODO:AddanyCOMunregistrationCodehere/#regionArcGISComponentCategoryRegistrargeneratedcodeIII/RequiredmethodforArcGISComponentCategoryregistrat

7、ion-/Donotmodifythecontentsofthismethodwiththecodeeditor.IllprivatestaticvoidArcGISCategoryRegistration(TyperegiSterType)(stringregKey=string.Format(*HKEY_CLASSES_ROOTCLSID0,regiSterType.GUID);MxCommands.Register(regKey);ControlsCommands.RegisterCregKey);/RequiredmethodforArcGISComponentCategoryunre

8、gistration-/Donotmodifythecontentsofthismethodwiththecodeeditor./privatestaticvoidArcGlSCategoryUnregistration(TyperegisterTye)(stringregKey=string.Format(*IIKEY_CLASSES_ROOTCLSID0*,registerType.GUID);MxCommands.UnregisterCregKey);ControlsCommands.Unregister(regKey);)ftendregionSendregionprivateIUoo

9、kHelperm_hookllelper=null;privateIMapControl3mapControl=null;privateIToolbarControltooIBarControl=null;publicPolygonStaticToolO/TODO:Definevaluesforthepublicproperties/base.m_category=;/localizabletextbase.m_caption=面统计;/localizabletextbase.m_message=而统计;/localizabletextbase.m_toolTip=使用多边形进行统计;/loc

10、alizabletextbase.m_name=面统计;/uniqueid,non-localizable(e.g.*MyCategory_MyTool*)try(/TODO:changeresourcenameifnecessary/stringbitmapResourceName=GetTypeO.Name+”.bmp;base.m_bitmap=newBitmap(GetTypeO,bitmapResourceName);base.m_cursor=newSystem.Windows.Forms.Cursor(GetTypeO,GetType().Name+”.cur);catch(Ex

11、ceptionex)(System.Diagnostics.Trace.WriteLine(ex.Message,*InvalidBitmap*);)#regionOverriddenClassMethods/Occurswhenthistooliscreated/InstanceoftheappIicationpublicoverridevoidOnCreate(objecthook)(trym_hookllelper=newHookHelperClassO;m_hookHelpcr.Hook=hook;if(m_hookllelper.ActiveView=null)m_hookHelpe

12、r=null;)catchm_hookHelpcr=null;if(m_hookHelper=null)base,m-enabled=false;elsebase.m_enabled=true;/TODO:Addotherinitializationcodethis.IoolBarControl=hookasIToolbarControl;this.mapControl=this.toolBarControl.BuddyasIMapControl3;)/OccurswhenthistoolisclickedIIIpublicoverridevoidOnClickO(/TODO:AddStati

13、cTooLOnClickimplementationthis.mapControl.CurrentTool=this;publicoverridevoidOnMouseDownCintButton,intShift,intX,intY)(/TODO:AddStaticTool.OnMouseDownimplementationif(Button=1)!GeometrypGeometry=this.mapControl.TrackPolygonO;SymbolUtil.InsertNormalLineElement(mapControl,TopologicOpreatorUtil.GetGeom

14、etryBoundary(PGeometry),255,O,O);newStatisForm(pGeometry,this.mapControl,OutputImage(pGeometry).ShowDialogO;SymbolUtil.ClearElement(mapContro1);)privatevoidOutPutArea(!GeometrypGeometry)(ITopologicalOperatorpTopoIogicOperator=pGeometryasITopologicalOperator;PTopologicOperator.Simplify();/pTopoIogicO

15、perator.ClipIActiveViewpActiveView=this.mapControlasIActiveView;/PicturcBoxp=newPictureBoxO;/pActiveView.OutputO;)publicOVerridevoidOnMouseMove(intButton,intShift,intX,intY)/TODO:AddStaticTool.OnMouseMoveimplementationpublicoverridevoidOnMouseUp(intButton,intShift,intX,intY)(/TODO:AddStaticTool.OnMo

16、useUp加PIementatiOnprivateImageOutputImage(!GeometrypGeometry)return MapImageUtil. SaveCurrentToImagc(mapControl. Map,331,151,pGeometry.Envelope);#endregionIII/SummarydescriptionforPolylineStaticTool.IllGuid(*62751d8d-07b3-4d84-a559-5ebdafbb4e0e*)Classinterface(ClassInterfaceType.None)ProgId(GisStati

17、stics.Com.PolylineStaticTool*)ublicsealedclassPolylineStaticTool:BaseToolregionCOMRegistrationFunction(s)ComRegisterFunction()ComVisible(false)staticvoidRegisterFunction(TyperegiSterType)(/RequiredforArcGISComponentCategoryRegistrarsupportArcGisCategoryRegistration(FegisterType);/TODO:AddanyCOMregis

18、trationcodehereComUnregiSterFunction()ComVisible(false)staticvoidUnregisterFunction(TyperegiSterType)(/RequiredforArcGISComponentCategoryRegistrarsupportArcGlSCategoryUnregistration(registerType);/TODO:AddanyCOMunregistrationcodehere/#regionArcGISComponentCategoryRegistrargeneratedcodeIII/Requiredme

19、thodforArcGISComponentCategoryregistration-/Donotmodifythecontentsofthismethodwiththecodeeditor./privatestaticvoidArcGISCategoryRegistration(TyperegiSterType)(stringregKey=string.Format(HKEY_CLASSES_ROOTCLSID0registerType.GUID);MxCounands.Register(regKey);ControlsCominands.Register(regKey);/Required

20、methodforArcGISComponentCategoryunregistration-IIIDonotmodifythecontentsofthismethodwiththecodeeditor./privatestaticvoidArcGlSCategoryUnregistration(TyperegiSterType)(stringregKey=string.Format(*IIKEY_CLASSES_ROOTCLSID0)*,regiSterType.GUID);MxCommands.Unregister(regKey);ControlsCommands.Unregister(r

21、egKey);#CndregionftendregionprivateIHookHelperm_hookllelper=null;privateIMapControl3mapControl=null;privateIToolbarControltooIBarControl=null;publicPolylineStaticToolO(/TODO:Definevaluesforthepublicproperties/base.m_category=;/localizabletextbase.m_caption=线统计;/localizabletextbase,mJneSSage=线统计;/loc

22、alizabletextbase.m_toolTip=使用线段缓冲区进行统计;/localizabletextbase.m_name=线统计;/uniqueid,non-localizable(e.g.*MyCategory-MyToo1*)try(/TODO:changeresourcenameifnecessary/stringbitmapResourceName=GetTypeO.Name+”.bmp;base.m_bitmap-newBitmap(GetTypeO,bitmapResourceName);base.m_cursor=newSystem.Windows.Forms.Cur

23、sor(GetTypeO,GetType().Name+”.cur*);catch(Exceptionex)(System.Diagnostics.Trace.WriteLine(ex.Message,*InvalidBitmap*);#regionOverriddenClassMethods/Occurswhenthistooliscreated/InstanceoftheapplicationpublicoverridevoidOnCreate(objecthook)try(m_hookllelper=newHookHelperClassO;m_hookHelper.Hook=hook;i

24、f(m_hookHelper.ActiveView=null)(m_hookllelper=null;catch(m-hook11elper=null;)if(m-hookHelper=null)base.m_enabled=false;elsebase.m_enabled=true;/TODO:Addotherinitializationcodethis,tooIBarControl-hookasIToolbarControl;this.mapControl=this.toolBarControl.BuddyasIMapControl3;IIIIIIOccurswhenthistoolisc

25、licked/publicoverridevoidOnClickO(/TODO:AddPolylineStaticTool.OnClickimplementationpublicOVerridevoidOnMouseDown(intButton,intShift,intX,intY)(/TODO:AddPolylineStaticTool.OnMouseDownimplementationif(Button=1)!GeometrypGeometry=this.mapControl.TrackLineO;ITopologicalOperatorTooOreator=pGeometryasITop

26、ologicalOperator:!GeometrynewGeometry=pTopoOpreator.Buffer(35);SymbolUtil.InsertNormalLineElement(mapControl,pGeometry,255,O,O);SymbolUtil.InsertNormalLineElement(mapControl,TopologicOpreatorUti1.GetGeometryBoundary(newGeometry),O,255,O);newStatisForm(newGeometry,this.mapControl,OutputImage(pGeometr

27、y).ShowDialogO;SymbolUtil.ClearElement(mapContro1);)publicoverridevoidOnMouseMove(intButton,intShift,intX,intY)(/TODO:AddPolylineStaticTool.OnMouseMoveimplementationpublicoverridevoidOnMouseUp(intButton,intShift,intX,intY)/TODO:AddPolylineStaticTool.OnMouseUpimplementation)#CndregiOnprivateImageOutp

28、utImagedGeometrypGeometry)(returnMapImageUtiLSaveCurrentToImage(mapControl.Map,331,151,pGeometry.Envelope);核心统计类:III/空间查询与操作都助类Ill2015/12/11fhr/classFeatureDealUtilpublicstaticboolUpdateFeature(IListpfeatuers,DataTabledataTable)(for(inti=0;idataTable.Rows.Count;i+)(!FeaturepFeature=pfeatuersi;DataRo

29、wdRow=dataTable.Rowsi;boolisUpdate=false;for(intj=0;jdRow.ItemArray.CountO;j+)(IFieldpField=pFeature.Fields.get_Field(j);if(!pField.Editable)(continue;)if(pField.Type=esriFieldTye.CsriFieldTypeBlobpField.Type=esriFie1dType.esriFie1dTypeRasterIpField.Type=esriFie1dTye.esriFie1dTypeGeometry)(continue;

30、)if(pFeature.get_Value(j)!=dRowj)(isUpdate=true;objectValUe=dRowj;if(pFeature.Fields.get-Field(j).CheckValue(value)(pFeature.set_Value(j,value);)if(isUpdate)pFeature.StoreO;returntrue;/统计某一段各值的个数/III/publicstaticIDictionaryQueryLayercountForUnikevaluesdFeatureLayerlayer,stringfieldName,!GeometrypGeo

31、metry)(IDictionaryresult=newDictionary();IListvalues=GetUnikeValues(layer,fieldName);foreach(stringvalueinvalues)stringwhere=string.Format(*0=,1,*,fieldName,value);Int32count=GetLayerCount(layer,pGeometry,where,fieldName);result.Add(value,count);returnresult;)publicstaticIDictionaryQueryLayerAreaFor

32、UnikevaluesdFeatureLayerlayer,stringfieldName,!GeometrypGeometry)(IDictionaryresult=newDictionary();IListvalues=GetUnikeValues(layer,fieldName);foreach(stringvalueinvalues)(stringwhere=string.Format(*0=1,*,fieldName,value);doublecount=GetLayerClipAreadayer,pGeometry,where,fieldName);result.Add(value

33、,count);)returnresult;publicstaticIListGetUnikeValuesdFeatureLayerlayer,stringfieldName)(IListvalues=newList();IFeatureCursorFeatureCursor=QueryFeatureInLayerdayer,);IDataStatistics(IataStatistics=newDatastatisticsClassO;(IataStatistics.Cursor=pFeatureCursoras!Cursor;dataStatistics.Field=fieldName;/

34、IStatisticsResultsresult=dataStatistics.Statistics;!EnumeratormyEnumerator=dataStatistics.UniqueValues;ListmyValueList=newList();myEnumerator.ResetO;while(myEnumerator.MoveNextO)if(myEnumerator.Current!=null)values.Add(myEnumerator.Current.ToStringO);/IStatisticsResultsresult=dataStatistics.Statisti

35、cs;returnvalues;publicstaticInt32GetLayerCount(IFeatureLayerlayer,!GeometrypGeometry,stringwhere,stringfieIdName)!CursorPCursor=QueryFeatureInLayer(layer,pGeometry,where)as!Cursor;/returnGetLayerCount(pCursor,fielJName);returnGetLayerCount(pCursor);)publicstaticdoubleGetLayerClipArea(IFeatureLayerla

36、yer,!GeometrypGeometry,stringwhere,stringfieldName)(!CursorpCursor=QueryFeatureInLayer(1ayer,pGeometry,where)as!Cursor;/returnGetLayerCount(pCursor,fieldName);returnGetLayerC1ipArea(pCursor,pGeometry);)publicstaticInt32GetLayerCount(!CursorpCursor,stringfieldName)(IDataStatisticsdataStatistics=newDa

37、tastatisticsClassO;dataStatistics.SimpleStats=true;dataStatistics.Cursor=pCursor;dataStatistics.Field=fieldName;IStatisticsResultsPStatiStiCSReSUIt=dataStatistics.Statistics;returnpStatisticsResult.Count;publicstaticInt32GetLayerCount(!CursorpCursor)(intcount=O;IFeatureCursorcursor=pCursorasIFeature

38、Cursor;while(cursor.NextFeatureO!=null)(count+;returncount;publicstaticdoubleGetLayerClipArea(!CursorpCursor,!GeometryoriginGeo)doublearea=0;IFeatureCursorcursor=pCursorasIFeatureCursor;!FeaturepFeature=cursor.NextFeatureO;while(pFeature!=null)ITopologicalOperatorpTopo=pFeature.ShapeasITopologicalOp

39、erator;!Geometrygeometry=pTopo.Intersect(originGeo,esriGeometryDimension.esriGeometry2Dimension);area+=(geometryas!Area).Area;pFeature=cursor.NextFeatureO;)returnarea;)III/利用语句进行查询返回游标和查询过滤类/publicstaticIFeatureCursorQueryFeatureInLayerdFeatureLayerfeatureLayer,StringWhereClause)(IFeatureCursorfeatu

40、reCursor=null;IQueryFilter2queryFiIter=newQueryFilterClassO;queryFiIter.WhereClause=WhereClause;IFeatureClassfeatureclass=featureLayer.FeatureClass;featureCursor=featureclass.Search(queryFiIter,false);returnfeatureCursor;)III/利用语句进行查询返回游标和查询过滤类/publicstaticIFeatureCursorQueryFeatureInLayerdFeatureLa

41、yerfeatureLayer,StringWhereClause,refIQueryFilterqueryFiIterCopy)(IFeatureCursorfeatureCursor=null;IQueryFiIter2queryFiIter=newQueryFiiterClassO;queryFiIter.WhcreClause=whereClause;IFeatureClassFeatureClass=featureLayer.FeatureClass;featureCursor=featureClass.Search(queryFi1ter,false);queryFiIterCop

42、y=queryFilter;returnfeatureCursor;/利用空间位置进行查询返回游标和查询过滤类/publicstaticIFeatureCursorQueryFeatureInLayerdFeatureLayerfeatureLayer,!Geometrygeometry,refIQueryFilterqueryFiIterCopy)(IFeatureCursorfeatureCursor=null;ISpatialFilterSpatialFilter=newSpatialFilterO;switch(featureLayer.FeatureClass.ShapeType)caseesriGeometryType.esriGeometryPoint:SpatialFilter.SpatialRel=esriSpatia1Re1Enum.esriSpatialRelContains;break;caseesriGeometryTye.esriGeometryPolyline:SpatialFilter.SpatialRel=esriSatialRelEnun.esriSpatialRelIntersects;break;caseesriGeometryType.esriGeometryPolygon:SpatialFilter.Spat

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号