ArcEngine代码集锦
arcgis吧
全部回复
仅看楼主
level 9
有途地理 楼主
开发工作是一个不断积累经验的过程,尤其是ArcGIS Engine开发。对象、接口、类和方法众多,要做好AE开发须具体三个条件:一是有基本的开发功底和程序思维; 二是擅长学习和使用API帮助; 三是有越来越多的开发经验积累。前两者是一个可以即时学习的过程,但开发经验需要不断的积累。
下面是代码所涉及的功能:
许可控件 属性表
地图控件 数据库
目录控件 地图投影
工具控件 数据转换
符号控件 地图编辑
文件管理 影像有关
图层操作 矢量拓扑
导航操作 GP处理
查询操作 三维分析
专题图 打印出图
产品详情功能代码示例
缩放地图
缩放地图一般可分为以下几种情况:
1.缩放地图:与放大地图相对,一般是手动绘制区域或固定比例缩放,可调用命令或Expand函数来;
函数方法:
ipEnv =axMapControl1.TrackRectangle();
ipEnv =axMapControl1.Extent;
ipEnv.Expand(2, 2, true);
axMapControl1.Extent =ipEnv;
命令方法:
this._cmd = newESRI.ArcGIS.Controls.ControlsZoomToSelectedCommandClass();
this._cmd.OnCreate(this.MapControl);
this._cmd.OnClick();
2.缩放到图层:这一种用得比较多,通常是将图层转为GeoDataset,利用其他Extent属性来缩放到图层;
IGeoDataset pGeoDataset =pLayer as IGeoDataset;
IEnvelope pEnvelope =pGeoDataset.Extent;
axMapControl1.Extent =pEnvelope;
3.缩放到选中:选中一个或多个要素,根据选择的要素,创建Geometry,获取Envelope。如果数据量太大,会比较耗时;
IFeatureLayer pFeatureLayer = GetLayrByName(pMap,cbxLayer.SelectedItem.ToString());
IFeatureSelection pFeatSel = pFeatureLayer asIFeatureSelection;
IEnumGeometryBind tEnumGeometryBind = newEnumFeatureGeometryClass();
tEnumGeometryBind.BindGeometrySource(null,pFeatSel.SelectionSet);
IEnumGeometry tEnumGeometry = (IEnumGeometry)tEnumGeometryBind;
IGeometryFactory tGeometryFactory = newGeometryEnvironmentClass();
IGeometry tGeometryAllSelect =tGeometryFactory.CreateGeometryFromEnumerator(tEnumGeometry);
axMap.Extent = tGeometryAllSelect.Envelope;
4.缩放到单个要素:有时,为了截取,需要分别缩放到单个要素,这个非常简单;
axMap.Extent=mFeature.Extent;
axMap.Refresh();
5.缩放到单个要素(需要准确显示周围信息):往往在缩放到单个要素时,由于图斑形状不同,可能不能准确显示周围信息,这时需要将地图适当的再缩小一点,换言之,缩放扩大的单个要素(可用缓冲实现);
/// <summary>
/// 缩放到单个要素
/// </summary>
/// <paramname="mFeature">缩放要素:需要进行缩放的单个要素</param>
/// <param name="dblExpand">扩大显示倍率(缓冲区半径):如果填写0,则不扩大显示</param>
private void ZoomToFeature(IFeaturemFeature, double dblExpand)
{
if (dblExpand==0.0)
{
axMap.Extent =mFeature.Extent;
axMap.Refresh();
}
else
{
ITopologicalOperator mTopologicalOperator =(ITopologicalOperator2)((IPolygon)mFeature.ShapeCopy);
//简化几何
if (mTopologicalOperator.IsSimple ==false)
{
mTopologicalOperator.Simplify();
}
//缓冲
IPolygon mPolygonBuffer =mTopologicalOperator.Buffer(dblExpand) as IPolygon;
axMap.Extent = mPolygonBuffer.Envelope;
axMap.Refresh();
}
}
6.缩放到选择图层:这一种情况比较特殊,需要重点说明。我们在要素类中选择部分要素后,可创建选择图层(pFeatureLayerDefinition的CreateSelectionLayer方法),如果我们直接获取选择图层的Envelope来作为显示范围,则不是我们想要的结果,选择图层的Envelope与源图层的Envelope相同,不管选择多少个要素。无奈,我使用了Envelope的Union方法,重新生成了准确的范围。
IEnvelope envelope = newEnvelopeClass();
IQueryFilter queryFilter =new QueryFilterClass();
queryFilter.WhereClause =whereClause;
IFeatureCursor featureCursor= pNewFeat.FeatureClass.Search(queryFilter, true);
IFeature feature =featureCursor.NextFeature();
while (feature != null)
{
IGeometry geometry = feature.Shape;
IEnvelope featureExtent =geometry.Envelope;
envelope.Union(featureExtent);
System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
feature = featureCursor.NextFeature();
}
axMap.Extent = envelope;
代码目录示例
下面是具体的功能列表,每一个功能都对应一段代码文件。
一、目录树控件
序号 功能项 描述
1 获取当前图层
2 右键菜单
3 隐藏图层
4 显示图层
5 刷新图层
6 选中图层
7 图层拖动
8 自定义
二、地图控件
9 打开地图文件
10 保存地图文件
11 另存地图文件
13 获取地图文件缩略图
14 获取地图坐标
15 获取经纬度坐标
16 获取比例尺
17 缩放地图
…………
由于目录较长,不一一列举。
2017年09月26日 09点09分 1
level 2
请问楼主这个是书籍还是什么?
2018年01月21日 06点01分 2
level 5
好东西,求分享
2018年01月21日 11点01分 3
1