using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Analyst3D;
using System.Windows.Forms; using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SystemUI; namespace TestDrapeApplication
{
/// <summary>
/// Command that works in ArcGlobe or GlobeControl
/// </summary>
[Guid("2d4a8248-b8d1-459f-aa4d-c73fdd4cde3b")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("TestDrapeApplication.AddShapeFileMemory")]
public sealed class AddShapeFileMemory : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType); //
// TODO: Add any COM registration code here
//
} [ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType); //
// TODO: Add any COM unregistration code here
//
} #region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
GMxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
GMxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
} #endregion
#endregion private IGlobeHookHelper m_globeHookHelper = null; public AddShapeFileMemory()
{
//
// TODO: Define values for the public properties
//
base.m_category = "Add Shape File to map"; //localizable text
base.m_caption = "Add Shape File"; //localizable text
base.m_message = "Add shape File to Map"; //localizable text
base.m_toolTip = "Add Shape File to Map"; //localizable text
base.m_name = "AddShapeFileMemory"; //unique id, non-localizable (e.g. "MyCategory_MyCommand") try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
} #region Overriden Class Methods /// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return; try
{
m_globeHookHelper = new GlobeHookHelperClass();
m_globeHookHelper.Hook = hook;
if (m_globeHookHelper.ActiveViewer == null)
{
m_globeHookHelper = null;
}
}
catch
{
m_globeHookHelper = null;
} if (m_globeHookHelper == null)
base.m_enabled = false;
else
base.m_enabled = true; // TODO: Add other initialization code
} /// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
//This is run after adding document with elevation Raster layer
IGlobeDisplay globeDisplay = new GlobeDisplayClass(); globeDisplay = m_globeHookHelper.GlobeDisplay; double lon = -86.00;
double lat = 37.9166;
double alt = 100.0;
double azimuth = 175.0;
double range = 1000; //ConvertMetersToDatasetUnits((IGlobe2)globeDisplay.Globe, 1000.0);
double fov = 60.0; m_globeHookHelper.GlobeDisplay.RefreshViewers();
//Elevation present to here.
AddElement(ref globeDisplay, azimuth, fov, range, lat, lon, alt);
// still have elevation with polygon under elevated layer.
m_globeHookHelper.GlobeDisplay.RefreshViewers(); } #endregion private void AddElement(ref IGlobeDisplay globeDisplay, double azimuth, double fov, double range, double lat, double lon, double alt)
{
//Depending on the ASCII file type set a variable which will control the flow of the application
string shapeType = null;
string sensorID = "Sim.Trip1";
//shapeType = "points";
// shapeType = "polylines";
shapeType = "polygons"; string datasetType = "Shapefile";
IWorkspace workSpace = null;
workSpace = this.CreateWorkspace();
IFields fields = CreateFields(shapeType);
//Create the Feature Class
IFeatureClass featureClass = CreateFeatureClass(workSpace, null, shapeType, fields, null, null, ""); AddShape(ref featureClass, ref workSpace, azimuth, fov, range, lat, lon, alt, sensorID); //Create a Feature Layer to display the data in ArcMap
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
featureLayer.Name = featureClass.AliasName;
featureLayer.Visible = true;
IGeoFeatureLayer lyr = (IGeoFeatureLayer)featureLayer;
IRgbColor lyrColor = new RgbColorClass();
lyrColor.Red = 255;
lyrColor.Green = 0;
lyrColor.Blue = 0;
ISimpleFillSymbol sfSymbol = new SimpleFillSymbolClass();
sfSymbol.Color = lyrColor;
sfSymbol.Outline.Width = 0.4;
sfSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
ISimpleRenderer lyrSimRend = new SimpleRendererClass();
lyrSimRend.Symbol = (ISymbol)sfSymbol; lyr.Renderer = (IFeatureRenderer)lyrSimRend; ((IScene)globeDisplay.Globe).AddLayer(featureLayer, true);
ILayer lyrCreated = featureLayer; ((IActiveView)globeDisplay.Globe).Extent = lyrCreated.AreaOfInterest;
}
private IWorkspace CreateWorkspace()
{
try
{ IWorkspaceFactory workspaceFactory = null;
// Instantiate a Shapefile workspace factory
//workspaceFactory = new ShapefileWorkspaceFactoryClass();
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); //Create a directory hierarchy to seperate out datasets created for Points, Polylines, and Polygons IWorkspaceName workspaceName = workspaceFactory.Create(Application.StartupPath + @"\ShapeFile", "Shapefile", null, 0);
IName Name = (IName)workspaceName;
IWorkspace workspace = (IWorkspace)(Name.Open());
return workspace;
}
catch (Exception ex)
{
String mess = ex.Message;
MessageBox.Show(mess);
return null;
} } private IFields CreateFields(string shapeType)
{ // Create a new fields collection.
IFields fields = new FieldsClass(); // Cast to IFieldsEdit to modify the properties of the fields collection.
IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Set the number of fields the collection will contain.
fieldsEdit.FieldCount_2 = 5; // Create the ObjectID field.
IField oidField = new FieldClass();
IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
oidFieldEdit.Name_2 = "ObjectID";
oidFieldEdit.AliasName_2 = "FID";
oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
fieldsEdit.set_Field(0, oidField); // Create the myID field.
IField myIDField = new FieldClass();
IFieldEdit myIDFieldEdit = (IFieldEdit)myIDField;
myIDFieldEdit.Name_2 = "SensorID";
myIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
fieldsEdit.set_Field(1, myIDField); // Create the text field.
IField textField = new FieldClass();
IFieldEdit textFieldEdit = (IFieldEdit)textField;
textFieldEdit.Length_2 = 30; // Only string fields require that you set the length.
textFieldEdit.Name_2 = "Str_Att1";
textFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
fieldsEdit.set_Field(2, textField); // Create the numeric field.
IField numericField = new FieldClass();
IFieldEdit numericFieldEdit = (IFieldEdit)numericField;
numericFieldEdit.Name_2 = "Num_Att1";
numericFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldsEdit.set_Field(3, numericField); //Create the SHAPE field.
IField shapeField = new FieldClass();
IFieldEdit shapeFieldEdit = (IFieldEdit)shapeField;
shapeFieldEdit.Name_2 = "SHAPE";
shapeFieldEdit.IsNullable_2 = true;
shapeFieldEdit.Required_2 = true; IGeometryDef geometryDef = new GeometryDefClass();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.AvgNumPoints_2 = 1;
geometryDefEdit.GridCount_2 = 0;
geometryDefEdit.HasM_2 = false;
geometryDefEdit.HasZ_2 = false; //Depending on the feature type (ie. Point, Polyline, or Polygon)
//set the appropriate .Type_2 and .GeometryType_2 Properties.
if (shapeType == "points")
{
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
}
else if (shapeType == "polylines")
{
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
}
else if (shapeType == "polygons")
{
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
} //Generate a default Spatial Reference
ISpatialReference spatialReference = MakeSpatialReference(esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant);
geometryDefEdit.SpatialReference_2 = spatialReference; shapeFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;
fieldsEdit.set_Field(4, shapeFieldEdit); return fields; } ///<summary>Helper to create a Feature Class.</summary>
public IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, System.String featureClassName, IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, System.String strConfigKeyword)
{ if (featureClassName == "")
{
return null; // name was not passed in
}
featureClassName = "newShapeFile";
IFeatureClass featureClass = null;
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast // assign the class id value if not assigned
if (CLSID == null)
{
CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
CLSID.Value = "esriGeoDatabase.Feature";
} System.String strShapeField = ""; // locate the shape field
//for (Int32 j = 0; j < fields.FieldCount; j++)
//{
// if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
// {
// strShapeField = fields.get_Field(j).Name;
// }
//}
strShapeField = "SHAPE";
// finally create and return the feature class // no feature dataset passed in, create at the workspace level
try
{
featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
}
catch (Exception ex)
{
String mess = ex.Message;
MessageBox.Show(mess);
}
return featureClass; } public ISpatialReference MakeSpatialReference(esriSRProjCSType coordinateSystem)
{ ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ISpatialReferenceResolution;
spatialReferenceResolution.ConstructFromHorizon();
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference; return spatialReference; } private void AddShape(ref IFeatureClass FeatureClass, ref IWorkspace workspace, double azimuth, double fov, double range, double lat, double lon, double alt, String sensorID)
{
// Start an edit session and edit operation.
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation(); int IDAttributeFieldIndex = FeatureClass.FindField("SensorID");
int StringAttributeFieldIndex = FeatureClass.FindField("Str_Att1");
int NumericAttributeFieldIndex = FeatureClass.FindField("Num_Att1"); ComReleaser comReleaser = new ComReleaser();
// Create a new insert cursor with buffering.
IFeatureCursor featureCursor = FeatureClass.Insert(true);
comReleaser.ManageLifetime(featureCursor); // Create a feature buffer. This will store the values common to every
// feature to be installed.
IFeatureBuffer featureBuffer = FeatureClass.CreateFeatureBuffer();
comReleaser.ManageLifetime(featureBuffer); IPolygon polygon = makePolygon(azimuth, fov, range, lat, lon, alt);
featureBuffer.Shape = (IGeometry)polygon;
featureBuffer.set_Value(IDAttributeFieldIndex, sensorID);
featureBuffer.set_Value(StringAttributeFieldIndex, "Try this");
featureBuffer.set_Value(IDAttributeFieldIndex, 2);
featureCursor.InsertFeature(featureBuffer); // Flush the cursor.
featureCursor.Flush(); // All of the features were successfully inserted; stop the edit operation
// and stop the edit session, saving the changes made in edit operations.
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
}
#region "Build Polygon" /// <summary>
/// Takes input of azimuth field of view and range with position and altitude
/// to make a circular arc polygon to add as a symbol for element in layer.
/// </summary>
/// <param name="azimuth"></param>
/// <param name="fov"></param>
/// <param name="range"></param>
/// <param name="lat"></param>
/// <param name="lon"></param>
/// <param name="alt"></param>
/// <returns>IPolygon polygon</returns>
private IPolygon makePolygon(double azimuth, double fov, double range, double lat, double lon, double alt)
{
object missing = System.Reflection.Missing.Value;
//IZAware zAware;
IPolygon polygon = new PolygonClass(); IPoint centerPoint = new PointClass();
IPoint startPoint = new PointClass();
IPoint endPoint = new PointClass();
Boolean isCCW = true;
Boolean isMinor = false;
centerPoint.SpatialReference = MakeSpatialReference(esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant);
startPoint.SpatialReference = centerPoint.SpatialReference;
endPoint.SpatialReference = centerPoint.SpatialReference;
//zAware = centerPoint as IZAware;
////zAware.ZAware = true; //zAware = startPoint as IZAware;
////zAware.ZAware = true; //zAware = endPoint as IZAware;
////zAware.ZAware = true; centerPoint.PutCoords(lon, lat);
////centerPoint.Z = alt;
double Xray = centerPoint.X;
double Yankee = centerPoint.Y; ICircularArc circularArc = new CircularArcClass(); ISegmentCollection ring1 = new RingClass();
ring1.AddSegment(circularArc as ISegment, ref missing, ref missing);
double fovRadian = 0.0;
fovRadian = (fov * 2 * Math.PI) / 360;
circularArc.PutCoordsByAngle(centerPoint, GetFromAngle(azimuth, fov), fovRadian, range); circularArc.QueryCoords(centerPoint, startPoint, endPoint, ref isCCW, ref isMinor); ILine lineOut = new LineClass();
ILine lineIn = new LineClass();
lineOut.PutCoords(centerPoint, startPoint);
lineIn.PutCoords(endPoint, centerPoint); ISegmentCollection segColl = new PolygonClass();
segColl.AddSegment((ISegment)lineOut, ref missing, ref missing);
segColl.AddSegment((ISegment)circularArc, ref missing, ref missing);
segColl.AddSegment((ISegment)lineIn, ref missing, ref missing);
polygon = segColl as IPolygon;
//IGeometryCollection geometryCollection = polygon as IGeometryCollection;
//geometryCollection.AddGeometry(segColl as IGeometry, ref missing, ref missing); //geometryCollection.GeometriesChanged();
return polygon; } /// <summary>
/// Converts Azimuth and Field of View width to geometric
/// start angle of circular arc.
/// </summary>
/// <param name="azimuth"></param>
/// <param name="FOV"></param>
/// <returns>Double startAngle</returns>
private double GetFromAngle(double azimuth, double FOV)
{
double startAngle = 0.0;
double fovRadian = 0.0;
fovRadian = (FOV * 2 * Math.PI) / 360;
startAngle = AzimuthToAngle(azimuth) - (.5 * fovRadian);
return startAngle;
}
/// <summary>
/// Converts Azimuth to geometric angle of arc.
/// </summary>
/// <param name="azimuth"></param>
/// <returns>double angle</returns>
private double AzimuthToAngle(double azimuth)
{
double angle = 0.0;
double angleRadian = 0.0; angleRadian = (azimuth * 2 * Math.PI) / 360;
angle = (2 * Math.PI) - (angleRadian - Math.PI / 2);
if (angle >= 2 * Math.PI)
{
angle -= 2 * Math.PI;
}
return angle;
} private double ConvertMetersToDatasetUnits(IGlobe2 globe, double meters)
{
try
{
esriUnits units = globe.GlobeUnits;
IUnitConverter cvtr = new UnitConverter();
double mapUnits = cvtr.ConvertUnits(meters, esriUnits.esriMeters, units);
return mapUnits;
}
catch (Exception ex)
{
String mess = ex.Message;
return -1.0;
} } #endregion }
}

  

AE 创建的更多相关文章

  1. AE创建拓扑

    转自原文 AE创建拓扑 /// <summary> /// 创建拓朴 /// </summary> /// <param name="featureWorksp ...

  2. AE创建组件失败,项目中已存在对esri.arcgis.***的引用

    AE创建组件失败,项目中已存在对esri.arcgis.***的引用 解决办法:在解决方案资源管理器的引用中把错误提示中的引用删掉,再创建组件就没问题了.

  3. AE创建一个空白的Shapefile

    1.IField和IFieldEdit区别: IFieldEdit是继承IField的,因为IField的属性大部分是只读的(read-only),所以IFieldEdit就在IField的基础上多了 ...

  4. AE开发概念辨析

    樱木 原文 AE开发之概念辨析2,AE开发涉及相关概念,AE开发相关概念 1 AE中的类库 AE总共包括了21个子库,分别是SYSTEM,SYSTEMUI,GEOMETRY,DISPLAY,SERVE ...

  5. PR视屏剪切

    一款常用的视频编辑软件,由Adobe公司推出.现在常用的有CS4.CS5.CS6.CC.CC 2014及CC 2015版本.是一款编辑画面质量比较好的软件,有较好的兼容性,且可以与Adobe公司推出的 ...

  6. ArcGIS 开发的一些知识学习点

    由于文章太多,不便转载,现主要列举如下: ArcGIS Runtime支持的GP工具列表 ArcGIS Runtime支持的GP工具列表 目录(?)[-] Standard版本Standard 空间分 ...

  7. 命令生成和运行android项目

    转自:http://wiki.dourok.info/doku.php/%E7%BC%96%E7%A0%81/android/%E5%91%BD%E4%BB%A4%E8%A1%8C%E7%94%9F% ...

  8. redis 文件事件模型

    参考文献: 深入剖析 redis 事件驱动 Redis 中的事件循环 深入了解epoll (转) Redis自己的事件模型 ae EPOLL(7) Linux IO模式及 select.poll.ep ...

  9. 【GIS数据格式】ArcInfo Binary Grid Format

    最近在修改项目时发现有些提取的坡度数据在参与了下一步计算后会出错,仔细跟了代码之后发现AE生成的坡度数据和其他一些分析后的栅格都被存储为.adf文件.说起惭愧,并不了解这是什么数据,由于下层算法使用G ...

随机推荐

  1. MacOS 下安装 MySQL8.0 登陆 MySQL

    按照 官方教程 ,下载安装包,点击安装后,如需在命令行启动,还需设置命令路径: 在命令行中,打开配置文件 .bash_profile: vim ~/.bash_profile 在最后一行加上: PAT ...

  2. ftp获取mysql数据库方法

    我说的这种情况是针对mysql数据库的,首先下载一个mysql通过ftp放到站点里面,然后通过配置文件找到数据库的名字和密码,然后通过浏览器访问数据库,直接在域名后面加上下载的mysql文件的名字就可 ...

  3. 创建对象——单例(Singleton)模式

      单例(Singleton)模式:   保证一个类在系统里只能有一个对象被实例化.   如:缓存池.数据库连接池.线程池.一些应用服务实例等.   难点:在多线程环境中,保证实例的唯一性.     ...

  4. ubuntu系统nginx+Redis+PHP

    一.安装ngnix apt-get update sudo apt-get install nginx /etc/init.d/nginx start 二.安装php sudo apt-get ins ...

  5. Masonry基础API

    Masonry基础API mas_makeConstraints()    添加约束 mas_remakeConstraints()  移除之前的约束,重新添加新的约束 mas_updateConst ...

  6. Linux命令运行监测和软件安装

    监测命令的运行时间 time command $ time sleep 5 real 0m5.003s # 程序开始至结束的时间,包括其它进程占用的时间片和IO时间 user 0m0.001s # 进 ...

  7. 扩增子分析解读2提取barcode 质控及样品拆分 切除扩增引物

    本节课程,需要完成扩增子分析解读1质控 实验设计 双端序列合并 先看一下扩增子分析的整体流程,从下向上逐层分析 分析前准备 # 进入工作目录 cd example_PE250 上一节回顾:我们拿到了双 ...

  8. UVA - 10410 Tree Reconstruction(栈处理递归)

    题目: 给出一棵树的BFS和DFS序列,输出这棵树中每个结点的子结点列表.BFS和DFS序列在生成的时候,当一个结点被扩展时,其所有子结点应该按照编号从小 到大的顺序访问. 思路: 一开始是想根据BF ...

  9. 魂酥的NOIP2018(真实)游记

    NOIP之后才开博客 作为一个高一零基础蒟蒻 想说什么似乎也没什么可说的 才学几个月似乎也没什么发言权就是了 Day -1 期中考爆0,似乎是班里学OI的考得最惨的一个 岂不美哉 要么我也没想考好 也 ...

  10. Linux学习笔记记录(九)