Arcgis 功能类代码.docx

上传人:b****4 文档编号:27486359 上传时间:2023-07-02 格式:DOCX 页数:24 大小:50.61KB
下载 相关 举报
Arcgis 功能类代码.docx_第1页
第1页 / 共24页
Arcgis 功能类代码.docx_第2页
第2页 / 共24页
Arcgis 功能类代码.docx_第3页
第3页 / 共24页
Arcgis 功能类代码.docx_第4页
第4页 / 共24页
Arcgis 功能类代码.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

Arcgis 功能类代码.docx

《Arcgis 功能类代码.docx》由会员分享,可在线阅读,更多相关《Arcgis 功能类代码.docx(24页珍藏版)》请在冰豆网上搜索。

Arcgis 功能类代码.docx

Arcgis功能类代码

目录:

1.打点,Element类2

2.清除所有元素,Element类3

3.画线,Element类3

4.根据传入的点集画面,Element类,目前没有实现4

5.在图层上添加点,feature类5

6.显示当前选中图元属性,feature类6

7.删除当前选中图元,feature类7

8.查询图元并闪烁,feature类8

9.得到符号9

10.渲染图元,feature类10

11.获取图片element,element类11

12.element旋转,element类12

13.加载SHP文件12

14.判断图形B是否包含在图形A中,feature类13

15.获得点14

16.element沿线移动,element类15

17.元素移动,element类15

 

Arcgis功能类代码

usingESRI.ArcGIS.esriSystem;

usingESRI.ArcGIS.Carto;

usingESRI.ArcGIS.Controls;

usingESRI.ArcGIS.SystemUI;

usingESRI.ArcGIS.Display;

usingESRI.ArcGIS.Geodatabase;

usingESRI.ArcGIS.Geometry;

usingESRI.ArcGIS.DataSourcesFile;

 

/////////////////////////////////////////////////////////////////////////////////////////////////Arcgis功能代码

///

1.打点,Element类

///

///点的X坐标

///点的Y坐标

privatevoidDrawPoint(doublex,doubley)

{

IActiveViewactiveView=this.axMapControl1.ActiveView.FocusMapasIActiveView;

IElementpElement;

IPointpt=newPointClass();

pt.PutCoords(x,y);

//设置点颜色

IRgbColorpColor=newRgbColorClass();

pColor.Red=255;

//设置点的样式

ISimpleMarkerSymbolpSMS=newSimpleMarkerSymbolClass();

pSMS.Size=9;

pSMS.Color=pColor;

pSMS.Style=esriSimpleMarkerStyle.esriSMSCircle;

IMarkerElementpME=newMarkerElementClass();

pME.Symbol=pSMS;

pElement=pMEasIElement;

pElement.Geometry=pt;

activeView.GraphicsContainer.AddElement(pElement,0);

activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);

}

///

2.清除所有元素,Element类

///

privatevoidDeleteAllElements()

{

IActiveViewactiveView=this.axMapControl1.ActiveView.FocusMapasIActiveView;

activeView.GraphicsContainer.DeleteAllElements();

activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography,null,null);

}

///

3.画线,Element类

///

///点集

///点集点的数目

privatevoidDrawLine(double[,]pointArray,intarrayCount)

{

if(arrayCount<=0)

{

return;//点坐标数组不能为空

}

IActiveViewactiveView=this.axMapControl1.ActiveView.FocusMapasIActiveView;

//设置颜色

IRgbColorcolor=newRgbColorClass();

color.Red=255;

color.Blue=255;

color.Transparency=255;

//线样式

ISimpleLineSymbollineSymbol=newSimpleLineSymbolClass();

lineSymbol.Color=color;

lineSymbol.Style=esriSimpleLineStyle.esriSLSInsideFrame;

lineSymbol.Width=1;

//点对象

IPointpPoint=newPointClass();

//线元素

ILineElementlineElement=newLineElementClass();

lineElement.Symbol=lineSymbol;

//线对象

IPolylinem_Polyline=newPolylineClass();

//点集合对象

IPointCollectionm_PointCollection=newPolylineClass();

objectmissing=Type.Missing;

for(inti=0;i

{

pPoint.PutCoords(pointArray[i,0],pointArray[i,1]);

m_PointCollection.AddPoint(pPoint,refmissing,refmissing);

}

m_Polyline=m_PointCollectionasIPolyline;

IElementelement=lineElementasIElement;

element.Geometry=m_Polyline;

activeView.GraphicsContainer.AddElement(element,0);

activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);

}

///

4.根据传入的点集画面,Element类,目前没有实现

///

///

///

privatevoidDrawPolygon(double[,]pointArray,intarrayCount)

{

ILayerpLayer=this.axMapControl1.get_Layer(0);

IFeatureLayerpFLayer=pLayerasIFeatureLayer;

IFeatureClasspFC=pFLayer.FeatureClass;

//点对象

IPointpPoint=newPointClass();

//点集合对象

IPointCollectionm_PointCollection=newPolylineClass();

objectmissing=Type.Missing;

for(inti=0;i

{

pPoint.PutCoords(pointArray[i,0],pointArray[i,1]);

m_PointCollection.AddPoint(pPoint,refmissing,refmissing);

}

//由于要画面,所以polygon的最后一个点和第一个点是同一个点,因此代码多余用到图元复制,也可以把第一个点再添加一遍就可以了

//把第一个点再添加一遍,此代码节俭,用这个

pPoint.PutCoords(pointArray[0,0],pointArray[0,1]);

m_PointCollection.AddPoint(pPoint,refmissing,refmissing);

////下面这个用图元复制,不节俭,所以注释起来留待以后参考

//IClonepClone=m_PointCollection.get_Point(0)asIClone;

//IPointpEndPoint=pClone.Clone()asIPoint;

//m_PointCollection.AddPoint(pEndPoint,refmissing,refmissing);

IWorkspaceEditpWE=(pFCasIDataset).WorkspaceasIWorkspaceEdit;

pWE.StartEditing(false);

pWE.StartEditOperation();

IFeaturepFeature=pFC.CreateFeature();

pFeature.Shape=m_PointCollectionasIPolygon;

pFeature.Store();

pFeature.set_Value(pFeature.Fields.FindField("类型"),"新加图元");

pFeature.Store();

pFeature.set_Value(pFeature.Fields.FindField("面积"),130);

pFeature.Store();

pWE.StopEditOperation();

pWE.StopEditing(true);

this.axMapControl1.ActiveView.Refresh();

}

///

5.在图层上添加点,feature类

///

///X坐标

///Y坐标

privatevoidAddPointOnLayer(doublex,doubley)

{

//得到要添加地物的图层

IFeatureLayeriFeatureL=this.axMapControl1.Map.get_Layer

(1)asIFeatureLayer;

//定义一个地物类,把要编辑的图层转化为定义的地物类

IFeatureClassiFeatureC=iFeatureL.FeatureClass;

//先定义一个编辑的工作空间,然后转化为数据集,最后转化为编辑工作空间

IWorkspaceEditw=(iFeatureCasIDataset).WorkspaceasIWorkspaceEdit;

IFeaturepFeature;

IPointpPoint;

//开始事务操作

w.StartEditing(true);

//开始编辑

w.StartEditOperation();

//创建一个地物

pFeature=iFeatureC.CreateFeature();

pPoint=newPointClass();

//设置点的坐标

pPoint.PutCoords(x,y);

//确定图形类型

pFeature.Shape=pPoint;

//保存地物

pFeature.Store();

pFeature.set_Value(pFeature.Fields.FindField("类别"),"Circle2");

pFeature.Store();

//结束编辑

w.StopEditOperation();

//结束事务操作

w.StopEditing(true);

this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,iFeatureL,null);

}

///

6.显示当前选中图元属性,feature类

///

privatevoidshowAttri()

{

stringstr="";

//获取图层

IQueryFilterpQueryFilter=newQueryFilterClass();

IFeatureLayerpFeatureLayer=this.axMapControl1.get_Layer

(1)asIFeatureLayer;

IFeatureClasspFeatureClass=pFeatureLayer.FeatureClass;

intindexOfName=pFeatureClass.FindField("类别");

IFeaturepFeature;

IMappMap=this.axMapControl1.Map;

ISelectionpSelection=pMap.FeatureSelection;

IEnumFeaturepEnumFeature=pSelectionasIEnumFeature;

pEnumFeature.Reset();

pFeature=pEnumFeature.Next();

if(pFeature==null)

{

MessageBox.Show("未选中图元,请重新选择");

}

else

{

while(pFeature!

=null)

{

pQueryFilter.WhereClause="FID="+pFeature.get_Value(0).ToString();

IFeatureCursorpFeatureCursor=pFeatureLayer.Search(pQueryFilter,true);

IFeaturexxfeature;

xxfeature=pFeatureCursor.NextFeature();

str=str+"类别:

"+xxfeature.get_Value(indexOfName).ToString()+"\n";

pFeature=pEnumFeature.Next();

}

MessageBox.Show(str);

}

}

///

7.删除当前选中图元,feature类

///

privatevoiddeleteFeature()

{

IFeaturepFeature;

IFeatureLayeriFeatureL=this.axMapControl1.get_Layer

(1)asIFeatureLayer;

IFeatureClassiFeatureC=iFeatureL.FeatureClass;

IWorkspaceEditiWorkspaceE=(iFeatureCasIDataset).WorkspaceasIWorkspaceEdit;

iWorkspaceE.StartEditing(true);

iWorkspaceE.StartEditOperation();

IMappMap=this.axMapControl1.Map;

IEnumFeaturepEnumFeature=pMap.FeatureSelectionasIEnumFeature;

pEnumFeature.Reset();

pFeature=pEnumFeature.Next();

try

{

if(pFeature!

=null)

{

while(pFeature!

=null)

{

DialogResultpDialogR=MessageBox.Show("确实要删除FID="+pFeature.get_Value(0).ToString()+"的图元吗?

","提示:

",MessageBoxButtons.YesNo,MessageBoxIcon.Information);

if(pDialogR==DialogResult.Yes)

{

pFeature.Delete();

MessageBox.Show("删除成功!

");

}

pFeature=pEnumFeature.Next();

}

}

}

catch(Exceptionerr)

{

MessageBox.Show(err.Message);

}

iWorkspaceE.StopEditOperation();

iWorkspaceE.StopEditing(true);

this.axMapControl1.ActiveView.Refresh();

}

///

8.查询图元并闪烁,feature类

///

///查询条件

privatevoidFindFeatureAndShape(stringsqlFilter)

{

this.axMapControl1.Map.ClearSelection();

this.axMapControl1.ActiveView.Refresh();

IQueryFilterpQueryFilter=newQueryFilterClass();

pQueryFilter.WhereClause=sqlFilter;

IFeatureLayerpFeatureLayer=this.axMapControl1.get_Layer

(1)asIFeatureLayer;

IFeatureCursorpFeatureCursor=pFeatureLayer.Search(pQueryFilter,true);

IFeaturepFeature;

pFeature=pFeatureCursor.NextFeature();

if(pFeature==null)

{

MessageBox.Show("未找到图元!

");

return;

}

ISimpleMarkerSymboliSimpleMarker=newSimpleMarkerSymbolClass();

iSimpleMarker.Style=esriSimpleMarkerStyle.esriSMSCircle;

iSimpleMarker.Size=12;

this.axMapControl1.Map.SelectFeature(pFeatureLayer,pFeature);

this.axMapControl1.FlashShape(pFeature.ShapeasIGeometry,5,300,iSimpleMarker);

this.axMapControl1.Map.ClearSelection();

//this.axMapControl1.ActiveView.Refresh();

}

///

9.得到符号

///

///符号路径

///符号类型

///符号名称

///返回指定符号

privateISymbolGetSymbol(stringsServerStylePath,stringsGalleryClassName,stringsymbolName)

{

try

{

IStyleGallerypStyleGaller=newServerStyleGalleryClass();

IStyleGalleryStoragepStyleGalleryStorage=pStyleGallerasIStyleGalleryStorage;

IEnumStyleGalleryItempEnumSyleGalleryItem=null;

IStyleGalleryItempStyleGallerItem=null;

IStyleGalleryClasspStyleGalleryClass=null;

pStyleGalleryStorage.AddFile(sServerStylePath);

for(inti=0;i

{

pStyleGalleryClass=pStyleGaller.get_Class(i);

if(pStyleGalleryClass.Name!

=sGalleryClassName)

continue;

pEnumSyleGalleryItem=pStyleGaller.get_Items(sGalleryClassName,sServerStylePath,"

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

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1