Skyline学习资料以及实用代码汇总
基本知识点:
1.5.2 偏移,俯仰和翻滚角度
摄像机、飞机和对象的偏移(方向),俯仰(倾斜)和翻滚角的定义如下图所示。
代码:
1.测距离:
1 2 3 | sgworld.Command.Execute(1034,0); //水平距离量测 sgworld.Command.Execute(1035,0); //空间距离量测 sgworld.Command.Execute(1036,0); //垂直距离量测 |
1 2 3 4 5 6 7 8 9 | var newPoint = SGWorld.Creator.GeometryCreator.CreatePointGeometry([circle.Position.X,circle.Position.Y,0]); //对newPoint进行缓冲分析得到圆 //先得到缓冲分析后的Geometry。 var newCircleGeometry = newPoint.SpatialOperator.buffer(circle.Radius); //利用缓冲分析后得到的Geometry得到新的圆,之前可以删除掉。 var color = SGWorld.Creator.Color(255,0,0); var newCircle = SGWorld.Creator.CreatePolygon(newCircleGeometry,color,color,0, '' , 'newCircle' ); //开始空间查询,假如需要查询的图层为featureLayer var spatialQueryResult = featureLayer.ExecuteSpatialQuery(newCircleGeometry,1); |
3.sharpkml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | /* * RADO OSREDKAR * 10.03.2011 */ using System; using System.Collections.Generic; using System.Xml; using System.Collections; namespace Alpcheck2.razredi { public class KML { //kml tags found bool IS_POINT = false ; bool IS_LINESTRING = false ; bool IS_COORDINATE = false ; //kml geometry private enum kmlGeometryType { POINT, LINESTRING } //kml tags private enum kmlTagType { POINT, LINESTRING, COORDINATES } //return types List<Hashtable> PointsCollection = new List<Hashtable>(); //all parsed kml points List<Hashtable> LinesCollection = new List<Hashtable>(); //all parsed kml lines Hashtable Point; //single point (part of PointsCollection) Hashtable Line; //single line (part of LinesCollection) Hashtable Coordinates; //object coordinate Hashtable KMLCollection = new Hashtable(); //parsed KML private kmlGeometryType? currentGeometry = null ; //currently parsed geometry object private kmlTagType? currentKmlTag = null ; //currently parsed kml tag private string lastError; /// <summary> /// parse kml, fill Points and Lines collections /// </summary> /// <param name="fileName">Full ABSOLUTE path to file.</param> /// <returns>HashTable</returns> public Hashtable KMLDecode ( string fileName){ readKML(fileName); if (PointsCollection != null ) KMLCollection.Add( "POINTS" , PointsCollection); if (LinesCollection != null ) KMLCollection.Add( "LINES" , LinesCollection); return KMLCollection; } /// <summary> /// Open kml, loop it and check for tags. /// </summary> /// <param name="fileName">Full ABSOLUTE path to file.</param> private void readKML ( string fileName){ using (XmlReader kmlread = XmlReader.Create(fileName)) { while (kmlread.Read()) //read kml node by node { //select type of tag and object switch (kmlread.NodeType) { case XmlNodeType.Element: //in elements select kml type switch (kmlread.Name.ToUpper()) { case "POINT" : currentGeometry = kmlGeometryType.POINT; Point = new Hashtable(); break ; case "LINESTRING" : currentGeometry = kmlGeometryType.LINESTRING; Line = new Hashtable(); break ; case "COORDINATES" : currentKmlTag = kmlTagType.COORDINATES; break ; } break ; case XmlNodeType.EndElement: //check if any geometry is parsed in add it to collection switch (kmlread.Name.ToUpper()) { case "POINT" : if (Point != null ) PointsCollection.Add(Point); //Reinit vars Point = null ; currentGeometry = null ; currentKmlTag = null ; break ; case "LINESTRING" : if (Line != null ) LinesCollection.Add(Line); //Reinit vars Line = null ; currentGeometry = null ; currentKmlTag = null ; break ; } break ; case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.Comment: case XmlNodeType.XmlDeclaration: //Parse inner object data switch (currentKmlTag) { case kmlTagType.COORDINATES: parseGeometryVal(kmlread.Value); //try to parse coordinates break ; } break ; case XmlNodeType.DocumentType: break ; default : break ; } } } } /// <summary> /// Parse selected geometry based on type /// </summary> /// <param name="tag_value">Value of geometry element.</param> protected void parseGeometryVal( string tag_value) { object value = null ; switch (currentGeometry) { case kmlGeometryType.POINT: parsePoint(tag_value); break ; case kmlGeometryType.LINESTRING: parseLine(tag_value); break ; } } /// <summary> /// If geometry is point select element values: /// COORDINATES - add lat & lan to HashTable Point /// </summary> /// <param name="tag_value">Value of geometry element.</param> protected void parsePoint( string tag_value) { Hashtable value = null ; string [] coordinates; switch (currentKmlTag) { case kmlTagType.COORDINATES: //kml point coordinates format is [lat,lan] value = new Hashtable(); coordinates = tag_value.Split( ',' ); if (coordinates.Length < 2)lastError = "ERROR IN FORMAT OF POINT COORDINATES" ; value.Add( "LNG" , coordinates[0].Trim()); value.Add( "LAT" , coordinates[1].Trim()); Point.Add( "COORDINATES" , value); break ; } } /// <summary> /// If geometry is line select element values: /// COORDINATES - add lat & lan to List /// add list to HashTable Line /// </summary> /// <param name="tag_value">Value of geometry element.</param> protected void parseLine( string tag_value) { List<Hashtable> value = null ; Hashtable linePoint = null ; string [] vertex; string [] coordinates; int idx = 0; switch (currentKmlTag) { case kmlTagType.COORDINATES: //kml coordinates format is [lat,lan] value = new List<Hashtable>(); vertex = tag_value.Trim().Split( ' ' ); //Split linestring to vertexes foreach ( string point in vertex) { coordinates = point.Split( ',' ); if (coordinates.Length < 2) LastError = "ERROR IN FORMAT OF LINESTRING COORDINATES" ; foreach ( string coordinate in coordinates) { linePoint = new Hashtable(); linePoint.Add( "LNG" , coordinates[0]); linePoint.Add( "LAT" , coordinates[1]); idx++; //index of net point value.Add(linePoint); } } Line.Add( "COORDINATES" , value); //Add coordinates to line break ; } } /// <summary> /// Last returned error /// </summary> public string LastError { get { return lastError; } set { //remember error and promote it to caller lastError = value; throw new System.Exception(lastError); } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //load the xml file var document = XDocument.Load( @"C:\temp\bob.xml" ); var ns = document.Root.Name.Namespace; //get every placemark element in the document var placemarks = document.Descendants(ns + "Placemark" ); //loop through each placemark and separate it into coordinates and bearings var coordinates = new List< string >(); var coordinate = "" ; foreach ( var point in placemarks) { coordinate = point.Descendants(ns + "coordinates" ).First().Value; coordinates.Add(coordinate); } |
源代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #region 读取图片中GPS点 /// <summary> /// 获取图片中的GPS坐标点 /// </summary> /// <param name=”p_图片路径”>图片路径</param> /// <returns>返回坐标【纬度+经度】用”+”分割 取数组中第0和1个位置的值</returns> public String fnGPS坐标(String p_图片路径) { String s_GPS坐标 = “”; //载入图片 Image objImage = Image.FromFile(p_图片路径); //取得所有的属性(以PropertyId做排序) var propertyItems = objImage.PropertyItems.OrderBy(x => x.Id); //暂定纬度N(北纬) char chrGPSLatitudeRef = ‘N’; //暂定经度为E(东经) char chrGPSLongitudeRef = ‘E’; foreach (PropertyItem objItem in propertyItems) { //只取Id范围为0x0000到0x001e if (objItem.Id >= 0x0000 && objItem.Id <= 0x001e) { objItem.Id = 0x0002; switch (objItem.Id) { case 0x0000: var query = from tmpb in objItem.Value select tmpb.ToString(); string sreVersion = string .Join(“.”, query.ToArray()); break ; case 0x0001: chrGPSLatitudeRef = BitConverter.ToChar(objItem.Value, 0); break ; case 0x0002: if (objItem.Value.Length == 24) { //degrees(将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint) double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); //minutes(將byte[8]~byte[11]转成uint, 除以byte[12]~byte[15]转成的uint) double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12); //seconds(將byte[16]~byte[19]转成uint, 除以byte[20]~byte[23]转成的uint) double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20); //计算经纬度数值, 如果是南纬, 要乘上(-1) double dblGPSLatitude = (((s / 60 + m) / 60) + d) * (chrGPSLatitudeRef.Equals(‘N’) ? 1 : -1); string strLatitude = string .Format(“{0:#} deg {1:#}’ {2:#.00}\” {3}”, d , m, s, chrGPSLatitudeRef); //纬度+经度 s_GPS坐标 += dblGPSLatitude + “+”; } break ; case 0x0003: //透过BitConverter, 将Value转成Char(‘E’ / ‘W’) //此值在后续的Longitude计算上会用到 chrGPSLongitudeRef = BitConverter.ToChar(objItem.Value, 0); break ; case 0x0004: if (objItem.Value.Length == 24) { //degrees(将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint) double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); //minutes(将byte[8]~byte[11]转成uint, 除以byte[12]~byte[15]转成的uint) double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12); //seconds(将byte[16]~byte[19]转成uint, 除以byte[20]~byte[23]转成的uint) double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20); //计算精度的数值, 如果是西经, 要乘上(-1) double dblGPSLongitude = (((s / 60 + m) / 60) + d) * (chrGPSLongitudeRef.Equals(‘E’) ? 1 : -1); } break ; case 0x0005: string strAltitude = BitConverter.ToBoolean(objItem.Value, 0) ? “0” : “1”; break ; case 0x0006: if (objItem.Value.Length == 8) { //将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint double dblAltitude = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); } break ; } } } return s_GPS坐标; } #endregion |
改进后:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | public string GetGPS( string path) { string gpsValue = "" ; //载入图片 Image objImage = Image.FromFile(path); //取得所有的属性(以PropertyId做排序) var propertyItems = objImage.PropertyItems.OrderBy(x => x.Id); //暂定纬度N(北纬) char chrGPSLatitudeRef = 'N' ; //暂定经度为E(东经) char chrGPSLongitudeRef = 'E' ; foreach (PropertyItem objItem in propertyItems) { //只取Id范围为0x0000到0x001e if (objItem.Id >= 0x0000 && objItem.Id <= 0x001e) { objItem.Id = 0x0002; switch (objItem.Id) { case 0x0000: var query = from tmpb in objItem.Value select tmpb.ToString(); string sreVersion = string .Join( "." , query.ToArray()); break ; case 0x0001: chrGPSLatitudeRef = BitConverter.ToChar(objItem.Value, 0); break ; case 0x0002: var ss = objItem.Value; if (objItem.Value.Length == 24) { //degrees(将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint) double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); //minutes(將byte[8]~byte[11]转成uint, 除以byte[12]~byte[15]转成的uint) double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12); //seconds(將byte[16]~byte[19]转成uint, 除以byte[20]~byte[23]转成的uint) double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20); //计算经纬度数值, 如果是南纬, 要乘上(-1) double dblGPSLatitude = (((s / 60 + m) / 60) + d) * (chrGPSLatitudeRef.Equals( 'N' ) ? 1 : -1); string strLatitude = string .Format( "{0:#} deg {1:#}' {2:#.00}\" {3}" , d , m, s, chrGPSLatitudeRef); ; //纬度+经度 gpsValue += dblGPSLatitude + "," ; } break ; case 0x0003: //透过BitConverter, 将Value转成Char(‘E’ / ‘W’) //此值在后续的Longitude计算上会用到 chrGPSLongitudeRef = BitConverter.ToChar(objItem.Value, 0); break ; case 0x0004: if (objItem.Value.Length == 24) { //degrees(将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint) double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); //minutes(将byte[8]~byte[11]转成uint, 除以byte[12]~byte[15]转成的uint) double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12); //seconds(将byte[16]~byte[19]转成uint, 除以byte[20]~byte[23]转成的uint) double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20); //计算精度的数值, 如果是西经, 要乘上(-1) double dblGPSLongitude = (((s / 60 + m) / 60) + d) * (chrGPSLongitudeRef.Equals( 'E' ) ? 1 : -1); } break ; case 0x0005: string strAltitude = BitConverter.ToBoolean(objItem.Value, 0) ? "0" : "1" ; break ; case 0x0006: if (objItem.Value.Length == 8) { //将byte[0]~byte[3]转成uint, 除以byte[4]~byte[7]转成的uint double dblAltitude = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4); } break ; } } } objImage.Dispose(); return gpsValue; } |
7. C#如何遍历某个文件夹中的所有子文件和子文件夹(循环递归遍历多层)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public void Director( string dir,List< string > list) { DirectoryInfo d = new DirectoryInfo(dir); FileInfo[] files = d.GetFiles(); //文件 DirectoryInfo[] directs = d.GetDirectories(); //文件夹 foreach (FileInfo f in files) { list.Add(f.Name); //添加文件名到列表中 } //获取子文件夹内的文件列表,递归遍历 foreach (DirectoryInfo dd in directs) { Director(dd.FullName, list); } } |
8.求时间差,时分秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | DateTime dtone = Convert.ToDateTime( "2010-11-1 03:00:00" ); DateTime dttwo = Convert.ToDateTime( "2010-12-5 04:04:01" ); TimeSpan ts = dttwo - dtone; //这样就能得到天数、小时、分差 string str1=ts.Days + "天" + ts.Hours + "小时" + ts.Minutes + "分" +ts.Seconds+ "秒<br>" ; //所有时间换去 总计天数、小时、分钟 string str2=ts.TotalDays + "天<br>" + ts.TotalHours + "小时<br>" + ts.TotalMinutes + "分<br>" ; Response.Write(str1+str2); //运行以上代码,可以得到这样的结果: //34天1小时4分1秒 //34.0444560185185天 //817.066944444444小时 //49024.0166666667分 |

1 using System; 2 using System.Diagnostics; 3 using System.Threading; 4 class Program 5 { 6 static void Main(string[] args) 7 { 8 Stopwatch stopWatch = new Stopwatch(); 9 stopWatch.Start(); 10 Thread.Sleep(10000); 11 stopWatch.Stop(); 12 // Get the elapsed time as a TimeSpan value. 13 TimeSpan ts = stopWatch.Elapsed; 14 15 // Format and display the TimeSpan value. 16 string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", 17 ts.Hours, ts.Minutes, ts.Seconds, 18 ts.Milliseconds / 10); 19 Console.WriteLine("RunTime " + elapsedTime); 20 } 21 }
9.打开文件夹选择多个文件

1 using (OpenFileDialog fileDialog = new OpenFileDialog()) 2 { 3 fileDialog.Title = "请选择文件"; 4 fileDialog.Filter = "kml files (*.cpt)|*.cpt|All files (*.*)|*.*"; 5 fileDialog.FilterIndex = 1; 6 fileDialog.InitialDirectory = SamplesDirectory; 7 fileDialog.Multiselect = true; 8 9 if (fileDialog.ShowDialog() == DialogResult.OK) 10 { 11 foreach (string file in fileDialog.FileNames) 12 { 13 string fileName = System.IO.Path.GetFileName(file); 14 ISGWorld701 sgworld = new SGWorld701(); 15 IPosition701 tower2Position = sgworld.Creator.CreatePosition(120, 30, 0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, 0, 0); 16 sgworld.Creator.CreatePointCloudModel(file, tower2Position, null, fileName); 17 } 18 19 } 20 21 }
10.Skyline二次开发--(1)动态对象自定义路径漫游
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程