1.Intro
最近在忙一个政府的项目,所以一直没更新,地图操作库吸收了很多网上、书上的优秀代码,同时又自己进行了优化,这里先给出部分的代码。
2.Environment
Environment:Windows 7及以上
Language:C#
IDE:Visual Studio 2012
SDK:ArcGIS Engine 10.2
3.Source
[Guid("afb9174c-2fe5-4a86-acca-256c3e946162")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Libs_GIS.Map_Operate")]
public sealed class Map_Operate
{
/// <summary>
/// 选中图中想要的要素
/// </summary>
/// <param name="axMapControl">地图控件对象</param>
/// <param name="e">鼠标点击事件对象</param>
/// <returns>返回要素枚举集合</returns>
public static void SelectAreaFeature(AxMapControl axMapControl, IMapControlEvents2_OnMouseDownEvent e)
{
IMap pMap = axMapControl.Map;
// 获取控件激活的视图
IActiveView pActiveView = pMap as IActiveView;
IGeometry pGeometry = null;
IEnvelope pEnvlope;
// 获取空间当前方形区域
pEnvlope = axMapControl.TrackRectangle();
if (pEnvlope.IsEmpty) // 点选操作
{
tagRECT r;
r.bottom = e.y;
r.top = e.y;
r.left = e.x;
r.right = e.x;
//
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnvlope, ref r, 4);
// 获取当前激活视图的空间参考并赋值给方形区域的空间参考
pEnvlope.SpatialReference = pActiveView.FocusMap.SpatialReference;
}
pGeometry = pEnvlope as IGeometry;
// 选中区域的要素
axMapControl.Map.SelectByShape(pGeometry, null, false);
// 激活视图刷新
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
/// <summary>
/// 根据图形集合选择要素
/// </summary>
/// <param name="axMapControl">地图对象</param>
/// <param name="pGraphicsContainer">图形集合</param>
/// <param name="clearAll">是否清除已选择的要素</param>
public static void SelectFeatureByGraphicsContainer(AxMapControl axMapControl, IGraphicsContainer pGraphicsContainer, bool clearAll)
{
if (clearAll)
{
//清空地图选择集后进行后续的操作选择
axMapControl.Map.FeatureSelection.Clear();
}
//重置游标,访问第一个图形
pGraphicsContainer.Reset();
//获取第一个图形
IElement pElement = pGraphicsContainer.Next();
while (pElement != null)
{
//获取图形的几何信息
IGeometry pGeometry = pElement.Geometry;
//选择地图要素,根据第一个图形的几何形状所包含的要素
axMapControl.Map.SelectByShape(pGeometry, null, false);
pElement = pGraphicsContainer.Next();
}
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, axMapControl.ActiveView.Extent);
}
/// <summary>
/// 根据元组清除要素
/// </summary>
/// <param name="axMapControl">地图对象</param>
/// <param name="pElement">元素对象</param>
/// <param name="clearAll">是否清除已选择的要素</param>
public static void SelectFeatureByElement(AxMapControl axMapControl, IElement pElement, bool clearAll)
{
if (clearAll)
{
//清空地图选择集后进行后续的操作选择
axMapControl.Map.FeatureSelection.Clear();
}
//获取图形的几何信息
IGeometry pGeometry = pElement.Geometry;
//选择地图要素,根据第一个图形的几何形状所包含的要素
axMapControl.Map.SelectByShape(pGeometry, null, false);
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, axMapControl.ActiveView.Extent);
}
/// <summary>
/// 通过图层名称获取图层对象
/// </summary>
/// <param name="axMapControl">地图控件对象</param>
/// <param name="layerName">图层名称</param>
/// <returns>返回图层对象</returns>
public static ILayer GetLayerByName(AxMapControl axMapControl, string layerName)
{
IEnumLayer pEnumLayer = axMapControl.Map.Layers;
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
string layerName_LayerTmp = pLayer.Name;
string layerName_LayerTmp2 = "";
try
{
layerName_LayerTmp2 = (pLayer as IFeatureLayer).FeatureClass.AliasName.ToString();
}
catch
{
layerName_LayerTmp2 = pLayer.Name;
}
if (layerName == layerName_LayerTmp || layerName == layerName_LayerTmp2)
{
break;
}
pLayer = pEnumLayer.Next();
}
return pLayer;
}
/// <summary>
/// 检查地图中是否包含某图层
/// </summary>
/// <param name="axMapControl">地图空间</param>
/// <param name="layerName">图层名称</param>
/// <returns>返回检查结果</returns>
public static bool CheckLayerExsits(AxMapControl axMapControl, string layerName)
{
//遍历MapControl中所有图层,找到与layerName名称相同的图层
//遍历MapControl中所有图层,找到与layerName名称相同的图层
for (int i = 0; i < axMapControl.LayerCount; i++)
{
//如果该图层为图层组类型,则分别对所包含的每个图层进行操作
if (axMapControl.get_Layer(i) is GroupLayer)
{
//用ICompositeLayer接口进行遍历操作
ICompositeLayer pCompositeLayer = axMapControl.get_Layer(i) as ICompositeLayer;
for (int j = 0; j < pCompositeLayer.Count; j++)
{
//获取到每个图层的名称赋值给临时变量
string layerName_tmp = pCompositeLayer.get_Layer(j).Name;
if (layerName_tmp == layerName)
{
return true;
}
}
}
else
{
string layerName_tmp = axMapControl.get_Layer(i).Name.ToString();
if (layerName_tmp == layerName)
{
return true;
}
}
}
return false;
}
#region 闪烁并缩放
/// <summary>
/// 缩放至要素并闪烁
/// </summary>
/// <param name="axMapControl">地图控件对象</param>
/// <param name="pFeature">要素对象</param>
public static void Zoom_Flash_Feature(AxMapControl axMapControl, IFeature pFeature)
{
IMap pMap = axMapControl.Map;
IActiveView pActiveView = pMap as IActiveView;
IEnvelope pEnvelope = new EnvelopeClass();
string layerName = pFeature.Class.AliasName.ToString();
IFeatureLayer currentLayer = GetLayerByName(axMapControl, layerName) as IFeatureLayer;
if (currentLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
{
pEnvelope = pActiveView.Extent;
pEnvelope.Height = pEnvelope.Height / 2;
pEnvelope.Width = pEnvelope.Width / 2;
pEnvelope.CenterAt(pFeature.ShapeCopy as IPoint);
}
else
{
pEnvelope = SetZoomEnvelopeParam(pFeature.Extent.Envelope, 1.2);
}
pActiveView.Extent = pEnvelope;
// 闪烁要素
IGeometry geometry = pFeature.Shape;
IPoint pCenterPoint = new PointClass();
double x = (geometry.Envelope.LowerLeft.X + geometry.Envelope.UpperRight.X) / 2;
double y = (geometry.Envelope.LowerLeft.Y + geometry.Envelope.UpperRight.Y) / 2;
pCenterPoint.PutCoords(x, y);
IDisplayTransformation pDisplayTransform = pActiveView.ScreenDisplay.DisplayTransformation;
IEnvelope pEnvelope2 = pDisplayTransform.VisibleBounds;
pEnvelope2.CenterAt(pCenterPoint);
pDisplayTransform.VisibleBounds = pEnvelope2;
pActiveView.PartialRefresh((esriViewDrawPhase)6, null, pActiveView.Extent);
pActiveView.ScreenDisplay.UpdateWindow();
ISymbol symbol = CreateSimpleSsymbol(geometry.GeometryType);
if (symbol == null)
{ return; }
DrawSymbol(symbol, geometry, pActiveView);
}
/// <summary>
/// 缩放至要素并闪烁
/// </summary>
/// <param name="axMapControl">地图控件对象</param>
/// <param name="pFeatureClass">要素类对象</param>
/// <param name="pFeature">要素对象</param>
public static void Zoom_Flash_Feature(AxMapControl axMapControl, IFeatureClass pFeatureClass, IFeature pFeature)
{
IMap pMap = axMapControl.Map;
IActiveView pActiveView = pMap as IActiveView;
IEnvelope pEnvelope = new EnvelopeClass();
if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
{
pEnvelope = pActiveView.Extent;
pEnvelope.Height = pEnvelope.Height / 2;
pEnvelope.Width = pEnvelope.Width / 2;
pEnvelope.CenterAt(pFeature.ShapeCopy as IPoint);
}
else
{
pEnvelope = SetZoomEnvelopeParam(pFeature.Extent.Envelope, 0.6);
}
pActiveView.Extent = pEnvelope;
// 闪烁要素
IGeometry geometry = pFeature.Shape;
IPoint pCenterPoint = new PointClass();
double x = (geometry.Envelope.LowerLeft.X + geometry.Envelope.UpperRight.X) / 2;
double y = (geometry.Envelope.LowerLeft.Y + geometry.Envelope.UpperRight.Y) / 2;
pCenterPoint.PutCoords(x, y);
IDisplayTransformation pDisplayTransform = pActiveView.ScreenDisplay.DisplayTransformation;
IEnvelope pEnvelope2 = pDisplayTransform.VisibleBounds;
pEnvelope2.CenterAt(pCenterPoint);
pDisplayTransform.VisibleBounds = pEnvelope2;
pActiveView.PartialRefresh((esriViewDrawPhase)6, null, pActiveView.Extent);
pActiveView.ScreenDisplay.UpdateWindow();
ISymbol symbol = CreateSimpleSsymbol(geometry.GeometryType);
if (symbol == null)
{ return; }
DrawSymbol(symbol, geometry, pActiveView);
}
/// <summary>
/// 设置缩放比例参数
/// </summary>
/// <param name="pEnvelope">外接矩形对象</param>
/// <param name="size">缩放比例</param>
/// <returns>返回外接矩形对象</returns>
private static IEnvelope SetZoomEnvelopeParam(IEnvelope pEnvelope, double size = 0.6)
{
double xMin = pEnvelope.XMin;
double xMax = pEnvelope.XMax;
double yMin = pEnvelope.YMin;
double yMax = pEnvelope.YMax;
double xDec = xMax - xMin;
double yDec = yMax - yMin;
double xMin_Le = xMin - size * xDec;
double yMin_Le = yMin - size * yDec;
double xMax_Le = xMax + size * xDec;
double yMax_Le = yMax + size * yDec;
pEnvelope.XMin = xMin_Le;
pEnvelope.XMax = xMax_Le;
pEnvelope.YMin = yMin_Le;
pEnvelope.YMax = yMax_Le;
return pEnvelope;
}
/// <summary>
/// 创建简单样式
/// </summary>
/// <param name="geometryType">几何类型</param>
/// <returns>返回样式对象</returns>
private static ISymbol CreateSimpleSsymbol(esriGeometryType geometryType)
{
ISymbol symbol = null;
switch (geometryType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass();
markerSymbol.Color = getRGB(255, 0, 0);
markerSymbol.Size = 8;
symbol = markerSymbol as ISymbol;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Color = getRGB(255, 0, 0);
lineSymbol.Width = 4;
symbol = lineSymbol as ISymbol;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = getRGB(255, 0, 0);
symbol = fillSymbol as ISymbol;
break;
default:
break;
}
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
return symbol;
}
/// <summary>
/// 获取RGB对象
/// </summary>
/// <param name="yourRed">红色值</param>
/// <param name="yourGreen">绿色值</param>
/// <param name="yourBlue">蓝色值</param>
/// <returns>返回颜色对象</returns>
private static IColor getRGB(int yourRed, int yourGreen, int yourBlue)
{
IRgbColor pRGB;
pRGB = new RgbColorClass();
pRGB.Red = yourRed;
pRGB.Green = yourGreen;
pRGB.Blue = yourBlue;
pRGB.UseWindowsDithering = true;
return pRGB;
}
/// <summary>
/// 样式绘制
/// </summary>
/// <param name="symbol">样式对象</param>
/// <param name="geometry">几何类型对象</param>
/// <param name="pActiveView">激活视图对象</param>
private static void DrawSymbol(ISymbol symbol, IGeometry geometry, IActiveView pActiveView)
{
IScreenDisplay pDisplay = pActiveView.ScreenDisplay;
pDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
pDisplay.SetSymbol(symbol);
for (int i = 0; i < 10; i++)
{
switch (geometry.GeometryType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
pDisplay.DrawPoint(geometry);
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint:
pDisplay.DrawMultipoint(geometry);
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
pDisplay.DrawPolyline(geometry);
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
pDisplay.DrawPolygon(geometry);
break;
default:
break;
}
System.Threading.Thread.Sleep(100);
}
pDisplay.FinishDrawing();
}
#endregion
#region 地图导出
/// 导出视图
/// </summary>
/// <param name="view">激活视图对象</param>
/// <param name="pGeo">几何对象</param>
/// <param name="OutputResolution">输出分辨率</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <param name="ExpPath">导出路径</param>
/// <param name="bRegion">是否删除当前视图的所有元素(判断全域或局域导出)</param>
public static void ExportView(IActiveView view, IGeometry pGeo, int OutputResolution, int Width, int Height, string ExpPath, bool bRegion)
{
//实例化导出类
IExport pExport = null;
//实例化目标结构
tagRECT exportRect = new tagRECT();
//通过传入的几何对象实例化包络线对象
IEnvelope pEnvelope = pGeo.Envelope;
//通过文件路径名获取文件的类型并转换成字符串类型的
string sType = System.IO.Path.GetExtension(ExpPath);
//依据类型返回对应的类型对象
switch (sType)
{
case ".jpg":
pExport = new ExportJPEGClass();
break;
case ".bmp":
pExport = new ExportBMPClass();
break;
case ".tif":
pExport = new ExportTIFFClass();
break;
case ".png":
pExport = new ExportPNGClass();
break;
case ".pdf":
pExport = new ExportPDFClass();
break;
default:
MessageBox.Show("没有输出格式,默认到JPEG格式");
pExport = new ExportJPEGClass();
break;
}
//将保存的文件名复制给导出文件名
pExport.ExportFileName = ExpPath;
//导出的结构属性值分别为,左0,上0,右=宽,下=高,因为左上角坐标为0,0
exportRect.left = 0;
exportRect.top = 0;
exportRect.right = Width;
exportRect.bottom = Height;
//如果bRegion为true
if (bRegion)
{
//当前视图删除所有元素
view.GraphicsContainer.DeleteAllElements();
view.Refresh();
}
//实例化包络线对象
IEnvelope envelope = new EnvelopeClass();
//通过PutCoords方法传入参数,上下左右的坐标值,确定包络线范围
envelope.PutCoords((double)exportRect.left, (double)exportRect.top, (double)exportRect.right, (double)exportRect.bottom);
//将包络线对象赋值给导出对象的像元值
pExport.PixelBounds = envelope;
//视图输出方法,传入参数:导出对象的开始导出方法,导出分辨率,导出结构,包络线对象,
view.Output(pExport.StartExporting(), OutputResolution, ref exportRect, pEnvelope, null);
//完成导出
pExport.FinishExporting();
//清除
pExport.Cleanup();
}
/// <summary>
/// 地图全域导出
/// </summary>
/// <param name="axMapControl">地图控件</param>
/// <returns>返回几何对象</returns>
public static IGeometry DrawGeometry_ExportFullArea(AxMapControl axMapControl)
{
IGeometry pGeometry = axMapControl.ActiveView.Extent;
return pGeometry;
}
/// <summary>
/// 地图局域导出
/// </summary>
/// <param name="axMapControl">地图控件</param>
/// <returns>返回几何对象</returns>
public static IGeometry DrawGeometry_ExportLocalArea(AxMapControl axMapControl)
{
//删除视图中数据
axMapControl.ActiveView.GraphicsContainer.DeleteAllElements();
//刷新
axMapControl.ActiveView.Refresh();
//调用绘制多边形方法,传入当前视图参数,赋值给多边形对象完成实例化
IGeometry pGeometry = DrawPolygon(axMapControl);
if (pGeometry == null) return null;
//调用导出地图的添加要素方法,传入几何对象,当前视图的激活视图
AddElement(pGeometry, axMapControl.ActiveView);
//将多边形对象转化为几何对象赋值给几何对象Geometry
return pGeometry;
}
#region 局域导出设置
/// <summary>
/// 添加元素
/// </summary>
/// <param name="pGeometry">几何对象</param>
/// <param name="activeView">激活视图</param>
public static void AddElement(IGeometry pGeometry, IActiveView activeView)
{
//通过GetRgbColor方法传入三基色,实例化颜色对象
IRgbColor fillColor = GetRgbColor(255, 0, 0);
IRgbColor lineColor = GetRgbColor(255, 0, 0);
//通过CreateElement方法,传入几何对象,线颜色,填充颜色,实例化元素对象
IElement pEle = CreateElement(pGeometry, lineColor, fillColor);
//通过将当前激活的绘图包含者属性,实例化绘图包含者对象
IGraphicsContainer pGC = activeView.GraphicsContainer;
if (pGC != null)//如果绘图包含者对象为空
{
//添加元素
pGC.AddElement(pEle, 0);
//当前激活视图局部刷新
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pEle, null);
}
}
/// <summary>
/// 获取RGB颜色
/// </summary>
/// <param name="intR">R色值</param>
/// <param name="intG">G色值</param>
/// <param name="intB">B色值</param>
/// <returns>返回IRgbColor对象</returns>
public static IRgbColor GetRgbColor(int intR, int intG, int intB)
{
//实例化颜色对象
IRgbColor pRgbColor = null;
if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255)
{
return pRgbColor;
}
pRgbColor = new RgbColorClass();
pRgbColor.Red = intR;
pRgbColor.Green = intG;
pRgbColor.Blue = intB;
return pRgbColor;
}
/// <summary>
/// 创建元素
/// </summary>
/// <param name="pGeometry">几何对象</param>
/// <param name="lineColor">线颜色对象</param>
/// <param name="fillColor">填充颜色对象</param>
/// <returns>元素</returns>
public static IElement CreateElement(IGeometry pGeometry, IRgbColor lineColor, IRgbColor fillColor)
{
if (pGeometry == null || lineColor == null || fillColor == null)
{
return null;
}
//实例化元素对象
IElement pElem = null;
try
{
//如果几何对象是包络线类型
if (pGeometry is IEnvelope)
{
//实例化一个矩形元素对象
pElem = new RectangleElementClass();
}
//如果几何对象是多边形类型
else if (pGeometry is IPolygon)
{
//实例化一个多边形元素对象
pElem = new PolygonElementClass();
}
//如果几何对象是圆形类型
else if (pGeometry is ICircularArc)
{
//通过几何对象实例化一个部分对象
ISegment pSegCircle = pGeometry as ISegment;//QI
//通过多边形组件类,实例化一个部分收集对象
ISegmentCollection pSegColl = new PolygonClass();
object ojb = Type.Missing;
//调用部分对象的添加部分AddSegment方法,传入参数:部分圆
pSegColl.AddSegment(pSegCircle, ref ojb, ref ojb);
//通过部分收集对象,实例化一个多边形对象
IPolygon pPolygon = pSegColl as IPolygon;
//通过多边形对象实例化为几何对象
pGeometry = pPolygon as IGeometry;
//实例化一个圆形元素对象
pElem = new CircleElementClass();
}
//如果几何对象时是线类型
else if (pGeometry is IPolyline)
{
//实例化一个线元素对象
pElem = new LineElementClass();
}
//如果对象为空,返回一个空
if (pElem == null)
{ return null; }
//将几何对象复制给要素的几何属性
pElem.Geometry = pGeometry;
//将要素赋值给 填充Shape元素 对象完成实例化
if (pGeometry is IPolyline)
{
ILineElement pLineElem = pElem as ILineElement;
ILineFillSymbol pLineSymbol = new LineFillSymbolClass();
pLineSymbol.Color = fillColor;
pLineSymbol.Outline.Color = lineColor;
pLineSymbol.LineSymbol.Width = 2;
pLineSymbol.Separation = 0.5;
if (pLineSymbol == null)
{ return null; }
pLineElem.Symbol = pLineSymbol.LineSymbol;
}
else if (pGeometry is IPolygon)
{
IFillShapeElement pFElem = pElem as IFillShapeElement;
//直接实例化符号对象
ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass();
//将传入的填充颜色赋值给符号颜色属性
pSymbol.Color = fillColor;
//将传入的线段颜色赋值给符号的外边框颜色
// pSymbol.Outline.Color = lineColor;
pSymbol.Outline.Color.CMYK = lineColor.CMYK;
pSymbol.Outline.Color.RGB = lineColor.RGB;
//pSymbol.Outline.Width = 10;
//符号样式设置为简单的填充风格
pSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
//如果符号对象为空,则返回空
if (pSymbol == null)
{ return null; }
//将具有若干属性的符号对象赋值给 填充Shape元素对象的符号属性
pFElem.Symbol = pSymbol;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return pElem;
}
/// <summary>
/// 绘制多边形
/// </summary>
/// <param name="axMapControl">地图对象</param>
/// <returns>几何对象</returns>
public static IGeometry DrawPolygon(AxMapControl axMapControl)
{
//设置局部变量几何对象
IGeometry pGeometry = null;
//如果传入地图文档参数为空则返回空
if (axMapControl == null)
{ return null; }
//实例化一个RubberBand(橡皮圈)对象
IRubberBand rb = new RubberPolygonClass();
//通过调用橡皮圈对象的TrackNew方法,传入参数为当前地图的激活视图的屏幕显示,null,完成对几何对象的实例化
pGeometry = rb.TrackNew(axMapControl.ActiveView.ScreenDisplay, null);
//返回一个几何对象,并转为多边形对象
return pGeometry;
}
#endregion
#endregion
/// <summary>
/// 获取地图坐标单位
/// </summary>
/// <param name="axMapControl">地图控件</param>
/// <returns>返回单位</returns>
public static string GetMapUnit(AxMapControl axMapControl)
{
string sMapUnits = string.Empty;
esriUnits pEsriMapUnit = axMapControl.Map.MapUnits;
switch (pEsriMapUnit)
{
case esriUnits.esriCentimeters:
sMapUnits = "厘米";
break;
case esriUnits.esriDecimalDegrees:
sMapUnits = "十进制";
break;
case esriUnits.esriDecimeters:
sMapUnits = "分米";
break;
case esriUnits.esriFeet:
sMapUnits = "英寸";
break;
case esriUnits.esriInches:
sMapUnits = "英尺";
break;
case esriUnits.esriKilometers:
sMapUnits = "公里";
break;
case esriUnits.esriMeters:
sMapUnits = "米";
break;
case esriUnits.esriMiles:
sMapUnits = "英里";
break;
case esriUnits.esriMillimeters:
sMapUnits = "毫米";
break;
case esriUnits.esriNauticalMiles:
sMapUnits = "海里";
break;
case esriUnits.esriPoints:
sMapUnits = "点";
break;
case esriUnits.esriUnitsLast:
sMapUnits = "最后单位";
break;
case esriUnits.esriUnknownUnits:
sMapUnits = "未知单位";
break;
case esriUnits.esriYards:
sMapUnits = "码";
break;
}
return sMapUnits;
}
/// <summary>
/// 通过点集合生成几何对象
/// </summary>
/// <param name="pPointCollection">点集合</param>
/// <returns>返回几何对象</returns>
public static IGeometry GetGeometryFromPointCollection(IPointCollection pPointCollection)
{
Ring ring = new RingClass();
object missing = Type.Missing;
ring.AddPointCollection(pPointCollection);
IGeometryCollection pointPolygon = new PolygonClass();
pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing);
IPolygon polyGonGeo = pointPolygon as IPolygon;
polyGonGeo.SimplifyPreserveFromTo();
return polyGonGeo as IGeometry;
}
}
4.Conclusion
不多比比,直接上代码,都在注释里了兄弟。