c#+AE开发一些常用到的方法
来源:互联网 发布:tc软件 编辑:程序博客网 时间:2024/05/24 02:15
{
//将距离转换函数
public static double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
int x1, x2, y1, y2;
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
double pixelExtent = x2 - x1;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
/// 将距离转换函数
public static double ConvertPixelToMapUnit(IActiveView pActiveView, double pixelUnits)
{
double realWorldDisplayExtent;
int pixelExtent;
double sizeOfOnePixel;
pixelExtent = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().right
- pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().left;
realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
/// <summary>
/// 获取一个图层中所有的地物
/// </summary>
/// <param name="featureClass"></param>
/// <returns></returns>
public static List<IFeature> GetLayerFeatures(IFeatureClass featureClass)
{
List<IFeature> result = new List<IFeature>();
if (featureClass == null)
return result;
IFeatureCursor featureCursor = featureClass.Search(null, false);
IFeature feature = featureCursor.NextFeature();
while (feature != null)
{
result.Add(feature);
feature = featureCursor.NextFeature();
}
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);
return result;
}
/// <summary>
/// 根据字段名获取地物的值
/// </summary>
/// <param name="feature"></param>
/// <param name="fieldName"></param>
/// <returns></returns>
public static string GetFieldValue(IFeature feature, string fieldName)
{
//根据字段名,获取字段的索引位置
int indexField = feature.Fields.FindField(fieldName);
if (indexField == -1)
return "";
return feature.get_Value(indexField).ToString();
}
/// <summary>
/// 获取线性地物的长度
/// </summary>
/// <param name="feature"></param>
/// <returns></returns>
public static double GetLineFeatureLength(IFeature feature)
{
if (feature.Shape.GeometryType != esriGeometryType.esriGeometryPolyline)
return 0;
else
{
IPolyline polyline = feature.Shape as IPolyline;
return polyline.Length;
}
}
public static IRgbColor GetRGB(int red, int green, int blue)
{
IRgbColor rGBColor = new RgbColorClass();
rGBColor.Red = red;
rGBColor.Green = green;
rGBColor.Blue = blue;
return rGBColor;
}
#region 闪烁地物
/// <summary>
/// 闪烁地物
/// </summary>
/// <param name="mapControl"></param>
/// <param name="iFeature"></param>
/// <param name="iMap"></param>
public static void FlashFeature(AxMapControl mapControl, IFeature iFeature)
{
IActiveView iActiveView = mapControl.ActiveView;
if (iActiveView != null)
{
iActiveView.ScreenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
//根据几何类型调用不同的过程
switch (iFeature.Shape.GeometryType)
{
case esriGeometryType.esriGeometryPolyline:
FlashLine(mapControl, iActiveView.ScreenDisplay, iFeature.Shape);
break;
case esriGeometryType.esriGeometryPolygon:
FlashPolygon(mapControl, iActiveView.ScreenDisplay, iFeature.Shape);
break;
case esriGeometryType.esriGeometryPoint:
FlashPoint(mapControl, iActiveView.ScreenDisplay, iFeature.Shape);
break;
default:
break;
}
iActiveView.ScreenDisplay.FinishDrawing();
}
}
//闪烁线
public static void FlashLine(AxMapControl mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry)
{
ISimpleLineSymbol iLineSymbol;
ISymbol iSymbol;
IRgbColor iRgbColor;
iLineSymbol = new SimpleLineSymbol();
iLineSymbol.Width = 4;
iRgbColor = new RgbColor();
iRgbColor.Red = 255;
iLineSymbol.Color = iRgbColor;
iSymbol = (ISymbol)iLineSymbol;
iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
mapControl.FlashShape(iGeometry, 3, 200, iSymbol);
}
//闪烁面
public static void FlashPolygon(AxMapControl mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry)
{
ISimpleFillSymbol iFillSymbol;
ISymbol iSymbol;
IRgbColor iRgbColor;
iFillSymbol = new SimpleFillSymbol();
iFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
iFillSymbol.Outline.Width = 12;
iRgbColor = new RgbColor();
iRgbColor.RGB = System.Drawing.Color.FromArgb(100, 180, 180).ToArgb();
iFillSymbol.Color = iRgbColor;
iSymbol = (ISymbol)iFillSymbol;
iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
iScreenDisplay.SetSymbol(iSymbol);
mapControl.FlashShape(iGeometry, 3, 200, iSymbol);
}
//闪烁点
public static void FlashPoint(AxMapControl mapControl, IScreenDisplay iScreenDisplay, IGeometry iGeometry)
{
ISimpleMarkerSymbol iMarkerSymbol;
ISymbol iSymbol;
IRgbColor iRgbColor;
iMarkerSymbol = new SimpleMarkerSymbol();
iMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
iRgbColor = new RgbColor();
iRgbColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
iMarkerSymbol.Color = iRgbColor;
iSymbol = (ISymbol)iMarkerSymbol;
iSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
mapControl.FlashShape(iGeometry, 3, 200, iSymbol);
}
#endregion
/// <summary>
/// 闪烁地物
/// </summary>
/// <param name="mapCtrl"></param>
/// <param name="flashGeometry"></param>
public static void FlashGeometry(AxMapControl mapCtrl, IGeometry flashGeometry)
{
//通过IHookActions闪烁要素集合
HookHelperClass m_pHookHelper = new HookHelperClass();
m_pHookHelper.Hook = mapCtrl.Object;
IHookActions hookActions = (IHookActions)m_pHookHelper;
hookActions.DoAction(flashGeometry, esriHookActions.esriHookActionsFlash);
Application.DoEvents();
m_pHookHelper.ActiveView.ScreenDisplay.UpdateWindow();
}
/// <summary>
/// 定位
/// </summary>
/// <param name="geometry">要定位的地物</param>
public static void LocateFeature(IGeometry geometry,AxMapControl Axmap)
{
if (geometry == null) return;
if (geometry.GeometryType == esriGeometryType.esriGeometryPoint)
{
Axmap.CenterAt(geometry as IPoint);
}
else
{
Axmap.Extent = geometry.Envelope;
}
}
/// <summary>
/// 获取两个地物相交的部分
/// </summary>
/// <param name="geo1">相交的第一个地物</param>
/// <param name="geo2">相交的第二个地物</param>
/// <returns></returns>
public static IGeometry GetDifferenceGeo(IGeometry geo1, IGeometry geo2)
{
ITopologicalOperator topo = geo2 as ITopologicalOperator;
return topo.Difference(geo1);
}
public static List<IFeature> GetCurrentLyrSelectedFeatures(IMap map,esriGeometryType geoType)
{
IFeature pFeature = null;
List<IFeature> features = new List<IFeature>();
ISelection selection = map.FeatureSelection;
IEnumFeature pEnumFeature = selection as IEnumFeature;
pFeature = pEnumFeature.Next();
while (pFeature != null)
{
if (pFeature.Shape.GeometryType == geoType)
{
features.Add(pFeature);
}
pFeature= pEnumFeature.Next();
}
return features;
}
}
- c#+AE开发一些常用到的方法
- iOS 开发中一些常用到的代码/方法总结
- AE开发时遇到的一些问题
- javascript常用到的一些方法
- javascript常用到的一些方法
- javascript常用到的一些方法
- Maven常用到的一些方法
- AE的一些基本知识
- 项目里用到的一些基本的AE开发功能:
- iOS开发中一些常用的方法
- iOS 开发 一些常用的公共方法
- iOS开发 GCD一些常用的方法
- C#.net VSTO Excel开发中一些常用方法
- android开发的一些常用不常用的公共方法
- 加载地图数据的几种方法(AE + C#)
- 加载地图数据的几种方法(AE + C#)
- 加载地图数据的几种方法(AE + C#)
- AE +C# 生成环状面要素的方法
- SQL语句
- MySQL基本使用
- 剑指offer - 二维数组的查找
- 定时旋转图片
- UI控件——UISlider:滑动条
- c#+AE开发一些常用到的方法
- 相机App简介
- 利用siezof运算现实存储各种数据类型使用内存空间的字节数
- VS2013 VC MFC 如何调用 COM
- sp<> 强指针类的用法
- hiho1087 Hamiltonian Cycle 位运算+记忆化搜索 求哈密顿回路数量
- HDU 5455
- iOS 应用开发,用户密码存储技术--KeyChain
- 函数指针和指针函数