AE代码 积累

  1         /// <summary>
  2         /// 计算两点角度
  3         /// </summary>
  4         /// <param name="p1">original point</param>
  5         /// <param name="p2">end point</param>
  6         /// <returns></returns>
  7         private float Angle(IPoint p1, IPoint p2)
  8         {
  9             double tan = Math.Atan(Math.Abs((p2.Y - p1.Y) / (p2.X - p1.X))) * 180 / Math.PI;
 10             if (p2.X > p1.X && p2.Y > p1.Y) //第一象限
 11                 return -(float.Parse(tan.ToString()));
 12             else if (p2.X > p1.X && p2.Y > p1.Y) //第二象限
 13                 return float.Parse(tan.ToString());
 14             else if (p2.X < p1.X && p2.Y > p1.Y) //第三象限
 15                 return float.Parse(tan.ToString()) - 180;
 16             else //第四象限
 17                 return 180-float.Parse(tan.ToString());
 18         }
 19
 20         /// <summary>
 21         /// 获取面图层的质心<IPoint>
 22         /// </summary>
 23         /// <param name="pFeatureLayer">面图层</param>
 24         /// <returns>List<></returns>
 25         private List<pointofpolygon> Get_PointFromPolygon(IFeatureLayer pFeatureLayer)
 26         {
 27             ESRI.ArcGIS.Geodatabase.IQueryFilter pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
 28             pQueryFilter.WhereClause = "FID IS NOT null";
 29             IArea pArea;
 30             List<pointofpolygon> pts=new List<pointofpolygon>();
 31             //MessageBox.Show(pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter).ToString());
 32             for (int i = 0; i < pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter); i++)
 33             {
 34                 pArea = pFeatureLayer.FeatureClass.GetFeature(i).Shape as IArea;
 35                 pts.Insert(i, new pointofpolygon(pFeatureLayer.FeatureClass.GetFeature(i).OID, pArea.Centroid));
 36             }
 37             return pts;
 38         }
 39
 40         /// <summary>
 41         /// 计算p1点相对p2点的角度,整栋方向为0度
 42         /// </summary>
 43         /// <param name="p1">polyline上的点</param>
 44         /// <param name="p2">original point,面的重心</param>
 45         /// <returns></returns>
 46         private float Get_Angle(IPoint p1, IPoint p2)
 47         {
 48             if (p1.X == p2.X && p1.Y == p2.Y)
 49                 return -1;
 50             IPoint p3=new PointClass();
 51             p3.Y=p2.Y;
 52             p3.X=p2.X+10;
 53             float c = (float)Math.Sqrt(Math.Pow((p1.X - p2.X), 2) + Math.Pow(p1.Y - p2.Y, 2)) *
 54                 (float)Math.Sqrt(Math.Pow(p3.X - p2.X, 2) + Math.Pow(p3.Y - p2.Y, 2));
 55             if (c == 0) return -1;
 56             float angle = (float)Math.Acos(((p1.X - p2.X) * (p3.X - p2.X) + (p1.Y - p2.Y) * (p3.Y - p2.Y)) / c);
 57             return angle;
 58         }
 59
 60         /// <summary>
 61         /// 清空属性表中需要计算的字段的值
 62         /// </summary>
 63         /// <param name="pFLyr">输入图层</param>
 64         private void ClearAttributeTable(IFeatureLayer pFLyr)
 65         {
 66             IDataset dataset = (IDataset)pFLyr.FeatureClass;
 67             IWorkspace workspace = dataset.Workspace;
 68             IWorkspaceEdit workspaceedit = (IWorkspaceEdit)workspace;
 69             workspaceedit.StartEditing(true);
 70             workspaceedit.StartEditOperation();
 71             for (int i = 0; i < pFLyr.FeatureClass.FeatureCount(new QueryFilter()); i++)
 72             {
 73                 IFeature pFeature = FlyrtoF(pFLyr, i);
 74                 pFeature.set_Value(pFeature.Fields.FindField("inner"),null);
 75                 pFeature.set_Value(pFeature.Fields.FindField("near"), null);
 76                 pFeature.set_Value(pFeature.Fields.FindField("far"), null);
 77                 pFeature.set_Value(pFeature.Fields.FindField("direction"), null);
 78                 pFeature.set_Value(pFeature.Fields.FindField("sum"), null);
 79                 pFeature.Store();
 80             }
 81             workspaceedit.StopEditing(true);
 82             workspaceedit.StopEditOperation();
 83         }
 84
 85         /// <summary>
 86         /// 创建内存中的FeatureClass
 87         /// </summary>
 88         /// <param name="point"></param>
 89         public void CreateFeatureClassInMemory(IPoint point)
 90         {
 91             IWorkspaceFactory pWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
 92             IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("", "pWorkspace", null, 0);
 93             IName pName = (IName)pWorkspaceName;
 94             IWorkspace pWorkspace = (IWorkspace)pName.Open();
 95             IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
 96             IFields pFields = new FieldsClass();
 97             IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
 98             IField pField = new FieldClass();
 99             IFieldEdit pFieldEdit = pField as IFieldEdit;
100             pFieldEdit.Name_2 = "SHAPE";
101             pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
102             IGeometryDef pGeometryDef = new GeometryDefClass();
103             IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
104             pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
105             //为FeatureClass赋参考系,不写会出错***************************************
106             ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
107             ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
108             pGeometryDefEdit.SpatialReference_2 = pSpatialReference;
109             //************************************************************************
110             pFieldEdit.GeometryDef_2 = pGeometryDef;
111             pFieldsEdit.AddField(pField);
112             pField = new FieldClass();//不要省略写!容易出问题
113             //pFieldEdit = pField as IFieldEdit;
114             //pFieldEdit.AliasName_2 = "高程";
115             //pFieldEdit.Name_2 = "elevation";
116             //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
117             pFieldsEdit.AddField(pField);
118             IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass("1", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
119
120             //插入到新建的FeatureClass中
121             IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit;
122             pWorkspaceEdit.StartEditing(true);
123             pWorkspaceEdit.StartEditOperation();
124             IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
125             IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
126             pFeatureBuffer.Shape = point;
127             pFeatureCursor.InsertFeature(pFeatureBuffer);
128
129             pFeatureCursor.Flush();
130             pWorkspaceEdit.StopEditOperation();
131             pWorkspaceEdit.StopEditing(true);
132
133             pFCInMemory = pFeatureClass;
134         }
135
136         /// <summary>
137         /// 计算pt是否在point的可视范围中
138         /// </summary>
139         /// <param name="pRasterLayer">dem</param>
140         /// <param name="point">polyline转的点</param>
141         /// <param name="pt">polygon转的点</param>
142         /// <returns>返回值为1或者0,1为可视,0为不可视</returns>
143         private bool CalViewshed(IRasterLayer pRasterLayer, IPoint point, IPoint pt)
144         {
145             //获取两个点的高程
146             IRasterSurface pRasterSurface = new RasterSurfaceClass();
147             pRasterSurface.PutRaster(pRasterLayer.Raster, 0);
148             ISurface pSurface = pRasterSurface as ISurface;
149             double elv_point = pSurface.GetElevation(point);
150             point.Z = elv_point;
151             double elv_pt = pSurface.GetElevation(pt);
152             pt.Z = elv_pt;
153             //IPolyline pPolyline = AxMapC.TrackLine() as IPolyline;
154             IPoint pPoint = null;
155             Boolean pBool = true;
156             IPolyline pVPolyline = null;
157             IPolyline pInPolyline = null;
158             object pRef = 0.13;
159             pSurface.GetLineOfSight(point, pt, out pPoint, out pVPolyline, out pInPolyline, out pBool, false, false, ref pRef);
160             //如果pt在pVPolyline上,则可视;否则不可视
161             return pBool;
162         }
163
164         /// <summary>
165         /// 计算点所在栅格的值
166         /// </summary>
167         /// <param name="point"></param>
168         /// <param name="rasterlayer">栅格</param>
169         /// <returns>返回栅格值</returns>
170         private int GetPointInRasterValue(IPoint point, IRasterLayer rasterlayer)
171         {
172             //第一种方法
173             object obj=null;
174             IRasterProps rasterprops = (IRasterProps)rasterlayer.Raster;
175             long dHeight = rasterprops.Height;
176             long dWidth = rasterprops.Width;
177             double dx = rasterprops.MeanCellSize().X;
178             double dy = rasterprops.MeanCellSize().Y;
179             rstPixelType pixelType = rasterprops.PixelType;
180             IPnt pnt = new PntClass();
181             pnt.SetCoords(dx,dy);
182             IPixelBlock pixelBlock = rasterlayer.Raster.CreatePixelBlock(pnt);
183             IPnt pnt1 = new PntClass();
184             double xx = rasterprops.Extent.XMin;
185             double yy = rasterprops.Extent.YMax;
186             int row = (int)Math.Abs((yy - point.Y) / dx)+1;
187             int col = (int)Math.Abs((xx - point.X) / dy)+1;
188             pnt1.SetCoords(row,col);
189             rasterlayer.Raster.Read(pnt1, pixelBlock); ;
190             if (pixelBlock != null)
191             {
192                 obj = pixelBlock.GetVal(0, 0, 0);
193             }
194             if (obj != null)
195                 return (int)obj;
196             else return -1;
197             //第二种方法
198             IRasterSurface pRasterSurface=new RasterSurfaceClass();
199             pRasterSurface.PutRaster(rasterlayer.Raster,0);
200             ISurface pSurface=pRasterSurface as ISurface;
201             double elv = pSurface.GetElevation(point);
202         }
203
204         /// <summary>
205         /// IRasterLayer类型转换成IGeoDataset
206         /// </summary>
207         /// <param name="pRasterLyr">输入DEM图层</param>
208         /// <returns>pSurfaceOP.Visibility的第一个参数</returns>
209         private IGeoDataset GetGeoDatasetFromLayer(IRasterLayer pRasterLyr)
210         {
211             IRaster pRaster = pRasterLyr.Raster;
212             IRasterBandCollection pRasterBandCollection = pRaster as IRasterBandCollection;
213             IRasterBand pRasterBand = pRasterBandCollection.Item(0);
214             IRasterDataset pRasterDataset = pRasterBand as IRasterDataset;
215             return pRasterDataset as IGeoDataset;
216         }
217
218         /// <summary>
219         /// IgeoDataset转换成IRasterLayer
220         /// </summary>
221         /// <param name="geodataset"></param>
222         /// <returns></returns>
223         private IRasterLayer GetRasterLayerFromGeoDataset(IGeoDataset geodataset)
224         {
225             IRasterLayer pRasterLayer = new RasterLayerClass();
226             pRasterLayer.CreateFromDataset(geodataset as IRasterDataset);
227             return pRasterLayer;
228         }
229
230         /// <summary>
231         /// FeatureLayer To FeatureClass
232         /// </summary>
233         /// <param name="pFeatureLyr"></param>
234         /// <returns></returns>
235         private IFeatureClass FLyrToFC(IFeatureLayer pFeatureLyr)
236         {
237             return pFeatureLyr.FeatureClass;
238         }
239         /// <summary>
240         /// FeatureLayer To Feature
241         /// </summary>
242         /// <param name="pFeatureLyr"></param>
243         /// <param name="index"></param>
244         /// <returns></returns>
245         private IFeature FlyrtoF(IFeatureLayer pFeatureLyr,int index)
246         {
247             IFeatureClass pFeatureClass=FLyrToFC(pFeatureLyr);
248             return pFeatureClass.GetFeature(index);
249         }
250
251         /// <summary>
252         /// 编辑属性表
253         /// </summary>
254         /// <param name="pt_polyline">多条polyline上的节点</param>
255         /// <param name="pt_polygon">polygon的质心</param>
256         /// <param name="pFeatureLyr">polygo Layer</param>
257         private void Calulatation(List<List<IPoint>> pt_polyline,List<pointofpolygon> pt_polygon, IFeatureLayer pFeatureLyr)
258         {
259             //使图层处于编辑状态
260             IDataset dataset = (IDataset)pFeatureLyr.FeatureClass;
261             IWorkspace workspace = dataset.Workspace;
262             IWorkspaceEdit workspaceedit = (IWorkspaceEdit)workspace;
263             workspaceedit.StartEditing(true);
264             workspaceedit.StartEditOperation();
265             IFeature feature;
266             float dir = 0, buf = 0;
267             int direction=0;
268
269             //修改某一记录某一字段的
270             feature.set_Value(feature.Fields.FindField("direction"), (float)feature.get_Value(feature.Fields.FindField("far")) + 0);
271             feature.Store();
272             //关闭要素的编辑状态
273             workspaceedit.StopEditing(true);
274             workspaceedit.StopEditOperation();
275         }
时间: 2024-10-23 13:31:03

AE代码 积累的相关文章

R 代码积累

R 代码积累不定期更新 1.阶乘.递归.reduce.sprintf #NO.1 # 阶乘函数 fact <- function(n){ if(n==0) return(1) #基例在这 else return(n*fact(n-1)) } #1+2!+3!+...+20!的和 #测试 Reduce('+', lapply(1:3,fact)) 结果是9 Reduce('+', lapply(1:20,fact)) #NO.2 #判断101-200之间有多少个素数,并输出所有素数 is.prim

Android 开发有用代码积累

Android开发需求变化快,开发周期要求尽量短,接下来一系列文章从实际使用出发总结一些常用的代码片段,便于查找,也为后来人提供一份参考. 1.获取Manifest的基本信息(升级页面和软件关于页面一般会使用到) Context mContext = XXXApplication.getInstance().getApplicationContext(); //获取Application的Context ,当然也可以获取当前的Activity的Context, Application一般是单例

5、终于代码积累越来越多了……

python的学习,看了也写了一些代码,慢慢发现没一条语句的标准写法以及作用和效果 好吧!继续ing  慢慢充实知识库.

代码积累——生成验证码servlet

package web; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import javax.imageio.ImageIO; import javax.servlet.ServletException; impor

代码积累

一.如何按照自己定义的格式输出日期? //定义日期的格式 SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //把当前的日期转换为特定格式日期的字符串并输出 System.out.println(dateFormat.format(new Date())); //解析一个字符串格式,字符串的格式要按照你设定的格式,转为为一个Date的日期类型 System.out.println(dateF

部分代码积累

Linux 安装命令: init 0 : 关机 init 3 : 命令界面 init 5 : 图形界面 ifconfig -a:查询网卡 dhclient: 自动获取ip vi /etc/sysconfig/network-scripts/ifcfg-eth0:打开网卡编辑 ONBOOT: 网卡是否开机启动(yes/no) BOOTPROTO: 获取ip方式自动.静态(dhcp/static) IPADDR: 添加ip NETMASK: 子网掩码:255.255.255.0 GATEWAY :

代码积累(没有进行分类)

1.window.location.href//得到完整地址2."dajiang|you".split("|")//(2) ["dajiang", "you"]```stringObject.split(separator,howmany)separator 必需.字符串或正则表达式,从该参数指定的地方分割 stringObject.howmany 可选.该参数可指定返回的数组的最大长度.如果设置了该参数,返回的子串不会多于这

提高代码质量:如何编写函数

阅读目录 命名 函数参数 编写函数体 总结 函数是实现程序功能的最基本单位,每一个程序都是由一个个最基本的函数构成的.写好一个函数是提高程序代码质量最关键的一步.本文就函数的编写,从函数命名,代码分布,技巧等方面入手,谈谈如何写好一个可读性高.易维护,易测试的函数. 回到顶部 命名 首先从命名说起,命名是提高可读性的第一步.如何为变量和函数命名一直是开发者心中的痛点之一,对于母语非英语的我们来说,更是难上加难.下面我来说说如何为函数命名的一些想法和感受: 采用统一的命名规则 在谈及如何为函数取一

论“java程序员的进阶路途”如何做到少走弯路,多写正确有意义的代码。

首先说明一下我为什么会去思考这个问题.本人离开学校也有一段时间了,经过了几场面试几次临时抱佛脚还有遇到的种种问题之后,社会告诉了我,如何做到少走弯路?如何让自己在何时去写合适的代码.其实在我看来这是每一位程序员都会去思考的事情. one:"如何让自己少走弯路" 一个伟大的程序员或者架构师再或者一个cto,如果你想问他们怎样让自己快速的进步?他们如一的告诉你,"累代码":对,对,讲的对!一名合格的程序员就是从简单的代码积累进阶的. 可是如果一名程序员重复的代码永远就是