ControlCoodinateLocal2.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using Tofly.Core.Context;
  5. using Tofly.Core.Context.Support;
  6. using Tofly.GIS;
  7. using Tofly.GIS.Carto;
  8. using Tofly.GIS.Display;
  9. using Tofly.GIS.Geometry;
  10. using Tofly.GIS.SpatialReference;
  11. using Tofly.SearchUI.Common;
  12. using System.Collections.Generic;
  13. using Tofly.GIS.Util;
  14. using Tofly.GISUI.Utils;
  15. namespace Tofly.SearchUI.Win
  16. {
  17. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "IControlCoodinateLocal2")]
  18. public partial class ControlCoodinateLocal2 : Tofly.CoreUI.Win.Control.UserControlClass, IlocalControl
  19. {
  20. //当前作业的视图
  21. private IActiveView curView;
  22. public double X;
  23. public double Y;
  24. public double NormalScale;
  25. public bool IsClear1 = false;
  26. private const double c_LONGMAXLIMIT = 180.0; //经度最大值
  27. private const double c_LONGMINLIMIT = -180.0; //经度最小值
  28. private const double c_LATITUDEMAXLIMIT = 90.0; //纬度最大值
  29. private const double c_LATITUDEMINLIMIT = -90.0; //纬度最小值
  30. private List<IElement> LstElements = new List<IElement>();
  31. private bool BoolGeoXInit = true;
  32. private bool BoolGeoYInit = true;
  33. private bool BoolProXInit = true;
  34. private bool BoolProYInit = true;
  35. private double CentralMeridian = 0;
  36. private int ChangeExtent = 3;
  37. private double ProXMax = 0;
  38. private double ProXMin = 0;
  39. private double GeoXMax = 0;
  40. private double GeoXMin = 0;
  41. //private bool m_bChange;
  42. private bool showFalseButton = true;
  43. private CoordinateCreateParams selectCoordinateParams = null;
  44. private Dictionary<int,ICoordinateSystem> coordinationsystem = new Dictionary<int, ICoordinateSystem>();
  45. //private const double c_MINUTESANDSECONDS = 60.0; //分和秒的单位最
  46. public ControlCoodinateLocal2(IActiveView view, double scacle, bool showFalseButton, CoordinateCreateParams SelectCoordinateParams)
  47. {
  48. curView = view;
  49. NormalScale = scacle;
  50. this.selectCoordinateParams = SelectCoordinateParams;
  51. if(selectCoordinateParams!=null)
  52. this.selectCoordinateParams.AddDiaHao = true;
  53. InitializeComponent();
  54. InitSpatialReference();
  55. if (!showFalseButton)
  56. this.btnAddLablePoint.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  57. }
  58. public bool IsClear
  59. {
  60. get
  61. {
  62. return IsClear1;
  63. }
  64. set
  65. {
  66. IsClear1=value;
  67. }
  68. }
  69. private enum EnumBtnEvent
  70. {
  71. enumbtnPan, //平移
  72. enumbtnZoomIn, //放大到
  73. enumbtnFlash, //闪烁
  74. enumbtnAddPoint, //添加点
  75. enumbtnAddLablePoint, //添加标签
  76. enumbtnAddCallout, //添加标注
  77. enumbtnQuery //查询
  78. }
  79. private void Button_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  80. {
  81. try
  82. {
  83. switch (e.Item.Name)
  84. {
  85. case "btnClear"://清除
  86. //for (int i = 0; i < LstElements.Count; i++)
  87. //{
  88. // curView.FocusMap.DeleteElement(LstElements[i]);
  89. //}
  90. curView.FocusMap.DeleteAllElements();
  91. curView.Refresh();
  92. LstElements.Clear();
  93. break;
  94. case "local": //查询
  95. OrientationLocal(EnumBtnEvent.enumbtnQuery);
  96. OrientationLocal(EnumBtnEvent.enumbtnAddLablePoint);
  97. break;
  98. case "btnFlash": //闪烁
  99. OrientationLocal(EnumBtnEvent.enumbtnFlash);
  100. break;
  101. case "btnAddPoint": //添加点
  102. OrientationLocal(EnumBtnEvent.enumbtnAddPoint);
  103. break;
  104. case "btnAddLablePoint": //添加标注点
  105. OrientationLocal(EnumBtnEvent.enumbtnAddLablePoint);
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. catch (Exception ex)
  112. {
  113. }
  114. }
  115. private void OrientationLocal(EnumBtnEvent pEnumBtnEvent)
  116. {
  117. try
  118. {
  119. ICoordinateSystem pSpatialReference;
  120. pSpatialReference = curView.FocusMap.SpatialReference;
  121. if (pSpatialReference is IUnknownCoordSystem || pSpatialReference == null)//当当前地图对象的坐标系统未知或为空时
  122. {
  123. LocationByXY(pEnumBtnEvent, Convert.ToDouble(X), Convert.ToDouble(Y));
  124. string strText = X + "," + Y;
  125. }
  126. else if (pSpatialReference is IGeoCoordinateSystem)//当当前地图对象的坐标系统为经纬度坐标时
  127. {
  128. GeographicLocation(pEnumBtnEvent);
  129. }
  130. else if (pSpatialReference is IProjectionCoordSystem) //当当前地图对象的坐标系统为XY坐标时
  131. {
  132. //按单位米定位
  133. LocationByXY(pEnumBtnEvent, Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  134. string strText = Project_x + "," + Project_y;
  135. }
  136. }
  137. catch (Exception ex)
  138. {
  139. }
  140. }
  141. private static void GetDMS(double dValue, bool bLatitude, out int iDegrees, out int iMinutes, out double DSecondes)
  142. {
  143. try
  144. {
  145. //ILatLonFormat pLatLonFormat = ContextRegistry.GetContext().GetObject("GIS_LatLonFormat") as ILatLonFormat;
  146. //pLatLonFormat.IsLatitude = bLatitude;
  147. //pLatLonFormat.ShowZeroMinutes = true;
  148. //pLatLonFormat.ShowZeroSeconds = true;
  149. //pLatLonFormat.GetDMS(dValue, out iDegrees, out iMinutes, out DSecondes);
  150. iDegrees = -1;
  151. iMinutes = -1;
  152. DSecondes = -1;
  153. if (bLatitude &&( dValue <= 0 || dValue > 180))
  154. return;
  155. //if (!bLatitude && (dValue <= 0 || dValue > 90))
  156. // return;
  157. iDegrees = Convert.ToInt16(Math.Truncate(dValue));//度
  158. dValue = dValue - iDegrees;
  159. iMinutes = Convert.ToInt16(Math.Truncate((dValue) * 60));//分
  160. DSecondes = Convert.ToInt16(Math.Round((dValue * 60 - iMinutes) * 60));
  161. //如果秒为60则分+1
  162. if (DSecondes == 60)
  163. {
  164. iMinutes = iMinutes + 1;
  165. DSecondes = 0;
  166. }
  167. //如果分为60则度+1
  168. if (iMinutes == 60)
  169. {
  170. iMinutes = 0;
  171. iDegrees = iDegrees + 1;
  172. }
  173. }
  174. catch (Exception ex)
  175. {
  176. iDegrees = 0;
  177. iMinutes = 0;
  178. DSecondes = 0;
  179. }
  180. }
  181. private void LocationByXY(EnumBtnEvent pEnumBtnEvent, double dx, double dy)
  182. {
  183. try
  184. {
  185. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  186. pPoint.PutCoords(dx, dy);
  187. switch (pEnumBtnEvent)
  188. {
  189. case EnumBtnEvent.enumbtnFlash:
  190. //闪烁
  191. curView.FocusMap.FlashGeometry(pPoint);
  192. break;
  193. case EnumBtnEvent.enumbtnAddPoint:
  194. AddPointElement(dx,dy, false, string.Format("{0},{1}", dx.ToString(),dy.ToString()));
  195. break;
  196. case EnumBtnEvent.enumbtnAddLablePoint:
  197. if (xtraTabControl1.SelectedTabPage==xtraTabPage1)
  198. {
  199. AddPointElement(dx, dy, true, string.Format("{0}°{1}′{2}″,{3}°{4}′{5}″", xd.Text, xf.Text, xm.Text, yd.Text, yf.Text, ym.Text));
  200. }
  201. else if (xtraTabControl1.SelectedTabPage == xtraTabPage3)
  202. {
  203. AddPointElement(dx, dy, true, string.Format("{0}°,{1}°", xod.Text, yod.Text));
  204. }
  205. else
  206. {
  207. AddPointElement(dx, dy, true, string.Format("{0},{1}", Project_x.Text.ToString(), Project_y.Text.ToString()));
  208. }
  209. break;
  210. case EnumBtnEvent.enumbtnQuery:
  211. LocalOprate(dx, dy, curView);
  212. break;
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. }
  218. }
  219. #region 按钮事件
  220. private void repositoryItemCheckEdit1_CheckStateChanged(object sender, EventArgs e)
  221. {
  222. if (((DevExpress.XtraEditors.CheckEdit)(sender)).CheckState == CheckState.Checked)
  223. IsClear = true;
  224. else
  225. IsClear = false;
  226. }
  227. private void GeographicLocation(EnumBtnEvent pEnumBtnEvent)
  228. {
  229. try
  230. {
  231. double dLongitude = 0;//经度
  232. double dLatitude = 0;//纬度
  233. if (this.xtraTabControl1.SelectedTabPageIndex == 0)
  234. {
  235. dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
  236. Convert.ToDouble(xm.Text) /3600;
  237. dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
  238. Convert.ToDouble(ym.Text) /3600;
  239. }
  240. else if (this.xtraTabControl1.SelectedTabPageIndex == 1)
  241. {
  242. dLongitude = Convert.ToDouble(xod.Text);
  243. dLatitude = Convert.ToDouble(yod.Text);
  244. }
  245. else if (this.xtraTabControl1.SelectedTabPageIndex == 2)
  246. {
  247. int diahao = int.Parse(Project_x.Text.Substring(0, 2));
  248. selectCoordinateParams.DaiHao = diahao;
  249. if (!coordinationsystem.ContainsKey(diahao))
  250. {
  251. ICoordinateSystem coordiante =
  252. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  253. selectCoordinateParams);
  254. coordinationsystem.Add(diahao, coordiante);
  255. }
  256. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  257. point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  258. point.CoordinateSystem = coordinationsystem[diahao];
  259. point.Project(curView.FocusMap.SpatialReference);
  260. dLongitude = point.X;
  261. dLatitude = point.Y;
  262. }
  263. //确保经度值在-180°到180°之间并且纬度值在-90°到90°之间
  264. if (dLongitude >= c_LONGMINLIMIT && dLongitude <= c_LONGMAXLIMIT && dLatitude >= c_LATITUDEMINLIMIT && dLatitude <= c_LATITUDEMAXLIMIT)
  265. {
  266. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  267. {
  268. LocationByXY(pEnumBtnEvent, GeoCoordinateConvertProjection(dLongitude, dLatitude).X, GeoCoordinateConvertProjection(dLongitude, dLatitude).Y);
  269. }
  270. else
  271. {
  272. LocationByXY(pEnumBtnEvent, dLongitude, dLatitude);
  273. }
  274. string strText = dLongitude.ToString("0.00") + "," + dLatitude.ToString("0.00");
  275. //if (!this.RepositoryItemComboBoxRecent.Items.Contains(strText))
  276. //{
  277. // this.RepositoryItemComboBoxRecent.Items.Add(strText);
  278. //}
  279. }
  280. else
  281. {
  282. //CoreUI.Message.MessageManager.Show(MessageType.Information, "输入不合法!", "提示信息", message);
  283. }
  284. }
  285. catch (Exception ex)
  286. {
  287. }
  288. }
  289. public void LocalOprate(double dx, double dy, IActiveView pAv)
  290. {
  291. try
  292. {
  293. IEnvelope pEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
  294. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  295. pPoint.PutCoords(dx, dy);
  296. pEnv = pAv.Extent;
  297. pEnv.CenterAt(pPoint);
  298. pAv.Extent = pEnv;
  299. pAv.FocusMap.SetMapScale(NormalScale, true);
  300. pAv.Refresh();
  301. //FlashPoint(pAv.ScreenDisplay, pPoint as IGeometry, 6, 200);//闪烁
  302. pAv.FocusMap.FlashGeometry(pPoint);
  303. }
  304. catch (Exception ex)
  305. {
  306. }
  307. }
  308. public void AddPointElement(double x, double y, bool bIsAddLablePoint, string strLableText)
  309. {
  310. IGraphicsContainer pGraphicsContainer;
  311. pGraphicsContainer = curView as IGraphicsContainer;
  312. //创建点
  313. IPoint pPoint;
  314. pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  315. pPoint.Project(curView.FocusMap.SpatialReference);
  316. pPoint.PutCoords(x, y);
  317. //初始化color(ISimpleMarkerSymbol封装的Color用的是microsoft)
  318. //Color pColor = Color.FromArgb(255, 0, 0);
  319. //ISimpleMarkerSymbol pSymlbol = ContextRegistry.GetContext().GetObject("GIS_SimpleMarkerSymbolClass") as ISimpleMarkerSymbol;
  320. //pSymlbol.Color = pColor;
  321. //pSymlbol.Size = 10;
  322. //pSymlbol.Style = SimpleMarkerStyle.Circle;
  323. IPictureMarkerSymbol pSymlbol = ContextRegistry.GetContext().GetObject("GIS_PictureMarkerSymbolClass") as IPictureMarkerSymbol;
  324. pSymlbol.CreateMarkerSymbolFromFile(Application.StartupPath + @"\Icon\Flag.png");
  325. pSymlbol.Size = 60;
  326. IMarkerElement pMarket = ContextRegistry.GetContext().GetObject("GIS_MarkerElement") as IMarkerElement;
  327. pMarket.Symbol = pSymlbol;
  328. IElement pElemt = (IElement)pMarket;
  329. pElemt.Geometry = pPoint;
  330. pGraphicsContainer.AddElement(pElemt, 0);
  331. if (!LstElements.Contains(pElemt))
  332. LstElements.Add(pElemt);
  333. if (bIsAddLablePoint)//是否添加标注
  334. {
  335. IElement element;
  336. ITextElement textelement = ContextRegistry.GetContext().GetObject("GIS_TextElementClass") as ITextElement;
  337. textelement.Text = strLableText;
  338. element = textelement as IElement;
  339. IPoint pTextPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  340. pTextPoint.X = pPoint.X;
  341. double YChange = ConvertPixelsToAVUnits(curView, 1);
  342. pTextPoint.Y = pPoint.Y + YChange;//坐标信息点位置
  343. pTextPoint.Project(curView.FocusMap.SpatialReference);
  344. element.Geometry = pTextPoint;
  345. pGraphicsContainer.AddElement(element, 0);
  346. if (!LstElements.Contains(element))
  347. LstElements.Add(element);
  348. }
  349. curView.PartialRefresh(ViewDrawPhase.ViewGraphics, null, null);
  350. }
  351. #endregion
  352. #region 初始化坐标
  353. /// <summary>
  354. /// 将地理坐标转为投影坐标,返回具有投影坐标的点Point
  355. /// </summary>
  356. /// <param name="dlongitude">点的经度</param>
  357. /// <param name="dlatitude">点的纬度</param>
  358. /// <returns>返回具有投影坐标的点Point</returns>
  359. private IPoint GeoCoordinateConvertProjection(double dlongitude, double dlatitude)
  360. {
  361. try
  362. {
  363. if (curView.FocusMap.SpatialReference == null) return null;
  364. if (curView.FocusMap.SpatialReference is IUnknownCoordSystem) return null;
  365. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  366. pPoint.Project(curView.FocusMap.SpatialReference);
  367. ICoordinateSystem pSpatialReference;
  368. IGeoCoordinateSystem pGeographicCoordinateSystem;
  369. IProjectionCoordSystem pProjectedCoordinateSystem;
  370. pSpatialReference = curView.FocusMap.SpatialReference;
  371. pProjectedCoordinateSystem = (IProjectionCoordSystem)pSpatialReference;
  372. pGeographicCoordinateSystem = pProjectedCoordinateSystem.GeographicCoordinateSystem;
  373. pPoint.Project((ICoordinateSystem)pGeographicCoordinateSystem);
  374. pPoint.PutCoords(dlongitude, dlatitude);
  375. pPoint.Project(curView.FocusMap.SpatialReference);
  376. return pPoint;
  377. }
  378. catch (Exception ex)
  379. {
  380. return null;
  381. }
  382. }
  383. /// <summary>
  384. /// 所加载数据的空间索引
  385. /// </summary>
  386. private void InitSpatialReference()
  387. {
  388. try
  389. {
  390. BoolGeoXInit = true;
  391. ICoordinateSystem pSpatialReference = curView.FocusMap.SpatialReference;
  392. if (pSpatialReference is IGeoCoordinateSystem) //只有经纬度坐标
  393. {
  394. BoolProXInit = false;
  395. BoolProYInit = false;
  396. InitGeographicCoordinate();
  397. }
  398. else if (pSpatialReference is IUnknownCoordSystem || pSpatialReference == null) //未知坐标
  399. {
  400. InitUnknowCoordinate();
  401. //this.tabControlQuery.SelectedIndex = 1;
  402. this.PanelGeo.Visible = false;
  403. this.panelGeoD.Visible = false;
  404. this.xtraTabPage2.PageVisible = false;
  405. this.panelPro.Dock = System.Windows.Forms.DockStyle.Fill;
  406. }
  407. else if(pSpatialReference is IProjectionCoordSystem)//平面坐标
  408. {
  409. BoolGeoXInit = false;
  410. BoolGeoYInit = false;
  411. InitProjectedCoordinate(pSpatialReference as IProjectionCoordSystem);
  412. this.panelPro.Visible = true;
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. }
  418. }
  419. /// <summary>
  420. ///初始化 平面坐标
  421. /// </summary>
  422. private void InitProjectedCoordinate(IProjectionCoordSystem projectionCoordSystem)
  423. {
  424. try
  425. {
  426. IEnvelope pEnvelope;
  427. pEnvelope = curView.Extent;
  428. X = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 2);
  429. Y = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 2);
  430. this.Project_x.Text = X.ToString();
  431. this.Project_y.Text = Y.ToString();
  432. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  433. pPoint.PutCoords(X, Y);
  434. pPoint.CoordinateSystem = projectionCoordSystem;
  435. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  436. pPoint.Project(pGeoCoordinateSystem);
  437. double dx = pPoint.X;
  438. double dy = pPoint.Y;
  439. xod.Text = Math.Round(dx, 5).ToString();
  440. yod.Text = Math.Round(dy, 5).ToString();
  441. int iLongtitudeD, iLongtitudeM;
  442. double dLongtitudeS;
  443. int iLatitudeD, iLatitudeM;
  444. double dLatitudeS;
  445. GetDMS(dx, true , out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  446. if (dLongtitudeS >= 60)
  447. {
  448. dLongtitudeS = dLongtitudeS - 60;
  449. iLongtitudeM = iLongtitudeM + 1;
  450. }
  451. if (iLongtitudeM >= 60)
  452. {
  453. iLongtitudeM = iLongtitudeM - 60;
  454. iLongtitudeD = iLongtitudeD + 1;
  455. }
  456. xd.Text = iLongtitudeD.ToString(); //度
  457. xf.Text = iLongtitudeM.ToString(); //分
  458. xm.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  459. GetDMS(dy,false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  460. if (dLatitudeS >= 60)
  461. {
  462. dLatitudeS = dLatitudeS - 60;
  463. iLatitudeM = iLatitudeM + 1;
  464. }
  465. if (iLatitudeM >= 60)
  466. {
  467. iLatitudeM = iLatitudeM - 60;
  468. iLatitudeD = iLatitudeD + 1;
  469. }
  470. yd.Text = iLatitudeD.ToString(); //度
  471. yf.Text = iLatitudeM.ToString(); //分
  472. ym.Text = Math.Round(dLatitudeS, 1).ToString(); //秒
  473. #region 计算投影坐标的经纬度范围用
  474. CentralMeridian = projectionCoordSystem.GetCentralMeridian(true);
  475. int TempInt = Convert.ToInt32(Math.Round(CentralMeridian, 0) + 3) % 6;
  476. if (TempInt != 0)
  477. {
  478. ChangeExtent = 3;
  479. }
  480. else
  481. {
  482. TempInt = Convert.ToInt32(Math.Round(CentralMeridian, 0) + 3) / 6;
  483. if (TempInt > 23 || TempInt < 13)
  484. {
  485. ChangeExtent = 3;
  486. }
  487. else
  488. {
  489. ChangeExtent = 6;
  490. }
  491. }
  492. GeoXMax = Math.Round(CentralMeridian, 0) + ChangeExtent * 0.5;
  493. double TempYA = dy;
  494. IPoint TempPointA = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  495. TempPointA.PutCoords(GeoXMax, TempYA);
  496. TempPointA.CoordinateSystem = pGeoCoordinateSystem;
  497. TempPointA.Project(projectionCoordSystem);
  498. ProXMax = TempPointA.X;
  499. GeoXMin = Math.Round(CentralMeridian, 0) - ChangeExtent * 0.5;
  500. double TempYB = dy;
  501. IPoint TempPointB = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  502. TempPointB.PutCoords(GeoXMin, TempYB);
  503. TempPointB.CoordinateSystem = pGeoCoordinateSystem;
  504. TempPointB.Project(projectionCoordSystem);
  505. ProXMin = TempPointB.X;
  506. #endregion
  507. }
  508. catch (Exception ex)
  509. {
  510. }
  511. }
  512. /// <summary>
  513. /// 未知坐标系统
  514. /// </summary>
  515. private void InitUnknowCoordinate()
  516. {
  517. IEnvelope pEnvelope;
  518. pEnvelope = curView.Extent;
  519. X = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 2);
  520. Y = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 2);
  521. this.Project_x.Text = X.ToString();
  522. this.Project_y.Text = Y.ToString();
  523. }
  524. /// <summary>
  525. ///初始化
  526. /// </summary>
  527. private void InitGeographicCoordinate()
  528. {
  529. try
  530. {
  531. IEnvelope pEnvelope;
  532. pEnvelope = curView.Extent;
  533. double dx = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 12);
  534. double dy = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 12);
  535. int iLongtitudeD, iLongtitudeM;
  536. double dLongtitudeS;
  537. int iLatitudeD, iLatitudeM;
  538. double dLatitudeS;
  539. GetDMS(dx, true , out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  540. xd.Text = iLongtitudeD.ToString(); //度
  541. xf.Text = iLongtitudeM.ToString(); //分
  542. xm.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  543. xod.Text = Math.Round(dx, 5).ToString();
  544. GetDMS(dy, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  545. yd.Text = iLatitudeD.ToString(); //度
  546. yf.Text = iLatitudeM.ToString(); //分
  547. ym.Text = Math.Round(dLatitudeS, 1).ToString(); //秒
  548. yod.Text = Math.Round(dy, 5).ToString();
  549. if (coordinationsystem != null && selectCoordinateParams != null)
  550. {
  551. int diahao = MapSpatialReferenceUtils.GetDaihao(dx,
  552. selectCoordinateParams
  553. .DaiHaoType ==
  554. DaiHaoType.Degree3);
  555. selectCoordinateParams.DaiHao = diahao;
  556. if (!coordinationsystem.ContainsKey(diahao))
  557. {
  558. ICoordinateSystem coordiante =
  559. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  560. selectCoordinateParams);
  561. coordinationsystem.Add(diahao, coordiante);
  562. }
  563. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  564. point.X = dx;
  565. point.Y = dy;
  566. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  567. point.Project(coordinationsystem[diahao]);
  568. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  569. Project_x.Text = Math.Round(point.X, 2).ToString();
  570. Project_y.Text = Math.Round(point.Y, 2).ToString();
  571. }
  572. }
  573. catch (Exception ex)
  574. {
  575. }
  576. }
  577. #endregion
  578. public CoreUI.Control.IUserControl curControl
  579. {
  580. get { return null; }
  581. }
  582. public List<IElement> Elements { get { return LstElements; } }
  583. private void barEditItem1_EditValueChanged(object sender, EventArgs e)
  584. {
  585. //if (Convert.ToBoolean(barEditItem1.EditValue))
  586. //{
  587. // IsClear1 = true;
  588. //}
  589. //else
  590. //{
  591. // IsClear1 = false;
  592. //}
  593. }
  594. private double ConvertPixelsToAVUnits(IActiveView pAv, long lTolerance)
  595. {
  596. if (pAv == null) return 5;
  597. IDisplayTransformation pTransformation;
  598. IScreenDisplay pScreenDisplay = pAv.ScreenDisplay;
  599. pTransformation = pScreenDisplay.DisplayTransformation;
  600. WKSPoint pOutPoint;
  601. TagPOINT pInPoint;
  602. pOutPoint.X = 0;
  603. pOutPoint.Y = 0;
  604. pInPoint.x = (int)lTolerance;
  605. pInPoint.y = (int)lTolerance;
  606. pTransformation.TransformCoords(ref pOutPoint, ref pInPoint, 1, 6);
  607. return pOutPoint.X;
  608. }
  609. #region 同步更新
  610. private void Project_x_EditValueChanged(object sender, EventArgs e)
  611. {
  612. try
  613. {
  614. if (!BoolProXInit)
  615. return;
  616. BoolProXInit = false;
  617. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  618. {
  619. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  620. pPoint.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  621. IProjectionCoordSystem projectionCoordSystem =
  622. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  623. pPoint.CoordinateSystem = projectionCoordSystem;
  624. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  625. pPoint.Project(pGeoCoordinateSystem);
  626. double dx = pPoint.X;
  627. xod.EditValue = Math.Round(dx,5);
  628. int iLongtitudeD, iLongtitudeM;
  629. double dLongtitudeS;
  630. GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  631. if (dLongtitudeS >= 60)
  632. {
  633. dLongtitudeS = dLongtitudeS - 60;
  634. iLongtitudeM = iLongtitudeM + 1;
  635. }
  636. if (iLongtitudeM >= 60)
  637. {
  638. iLongtitudeM = iLongtitudeM - 60;
  639. iLongtitudeD = iLongtitudeD + 1;
  640. }
  641. int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
  642. if (Convert.ToInt32(yd.Text) != iLongtitudeD)
  643. xd.Text = iLongtitudeD.ToString(); //度
  644. if (Convert.ToInt32(yf.Text) != iLongtitudeM)
  645. xf.Text = iLongtitudeM.ToString(); //分
  646. if (Convert.ToInt32(ym.Text) != iLongtitudeS)
  647. xm.Text = iLongtitudeS.ToString();
  648. }
  649. else
  650. {
  651. if (selectCoordinateParams == null)
  652. return;
  653. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  654. {
  655. int diahao = int.Parse(Project_x.Text.Substring(0, 2));
  656. selectCoordinateParams.DaiHao = diahao;
  657. if (!coordinationsystem.ContainsKey(diahao))
  658. {
  659. ICoordinateSystem coordiante =
  660. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  661. selectCoordinateParams);
  662. coordinationsystem.Add(diahao, coordiante);
  663. }
  664. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  665. point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  666. point.CoordinateSystem = coordinationsystem[diahao];
  667. point.Project(curView.FocusMap.SpatialReference);
  668. double dx = point.X;
  669. int iLongtitudeD, iLongtitudeM;
  670. double dLongtitudeS;
  671. GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  672. if (dLongtitudeS >= 60)
  673. {
  674. dLongtitudeS = dLongtitudeS - 60;
  675. iLongtitudeM = iLongtitudeM + 1;
  676. }
  677. if (iLongtitudeM >= 60)
  678. {
  679. iLongtitudeM = iLongtitudeM - 60;
  680. iLongtitudeD = iLongtitudeD + 1;
  681. }
  682. int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
  683. if (Convert.ToInt32(yd.Text) != iLongtitudeD)
  684. xd.Text = iLongtitudeD.ToString(); //度
  685. if (Convert.ToInt32(yf.Text) != iLongtitudeM)
  686. xf.Text = iLongtitudeM.ToString(); //分
  687. if (Convert.ToInt32(ym.Text) != iLongtitudeS)
  688. xm.Text = iLongtitudeS.ToString();
  689. }
  690. }
  691. }
  692. catch (Exception ex)
  693. {
  694. }
  695. }
  696. private void xd_EditValueChanged(object sender, EventArgs e)
  697. {
  698. try
  699. {
  700. if (!BoolGeoXInit)
  701. return;
  702. BoolGeoXInit = false;
  703. if (Convert.ToDouble(xm.Text) >= 60)
  704. {
  705. xm.Text = (Convert.ToDouble(xm.Text) - 60).ToString();
  706. xf.Text = (Convert.ToDouble(xf.Text) + 1).ToString();
  707. }
  708. if (Convert.ToDouble(xf.Text) >= 60)
  709. {
  710. xf.Text = (Convert.ToDouble(xf.Text) - 60).ToString();
  711. xd.Text = (Convert.ToDouble(xd.Text) + 1).ToString();
  712. }
  713. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  714. {
  715. double oldx = Convert.ToDouble(xm.Text);
  716. if (oldx >= 60)
  717. {
  718. xm.Text = (oldx%60).ToString();
  719. oldx = oldx - oldx%60;
  720. double addf = oldx/60;
  721. xf.Text = (Convert.ToDouble(xf.Text) + addf).ToString();
  722. }
  723. oldx = Convert.ToDouble(xf.Text);
  724. if (oldx >= 60)
  725. {
  726. xf.Text = (oldx%60).ToString();
  727. oldx = oldx - oldx%60;
  728. double addd = oldx/60;
  729. xd.Text = (Convert.ToDouble(xd.Text) + addd).ToString();
  730. }
  731. double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
  732. Convert.ToDouble(xm.Text) /3600;
  733. double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
  734. Convert.ToDouble(ym.Text) /3600;
  735. xod.Text = Math.Round(dLongitude, 5).ToString();
  736. yod.Text = Math.Round(dLatitude, 5).ToString();
  737. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  738. pPoint.PutCoords(dLongitude, dLatitude);
  739. IProjectionCoordSystem projectionCoordSystem =
  740. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  741. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  742. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  743. pPoint.Project(projectionCoordSystem);
  744. double dx = pPoint.X;
  745. if (dx != dLongitude)
  746. Project_x.Text = Math.Round(dx, 2).ToString();
  747. }
  748. else
  749. {
  750. if (selectCoordinateParams == null)
  751. return;
  752. double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
  753. Convert.ToDouble(xm.Text) /3600;
  754. double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
  755. Convert.ToDouble(ym.Text) /3600;
  756. xod.Text = Math.Round(dLongitude, 5).ToString();
  757. yod.Text = Math.Round(dLatitude, 5).ToString();
  758. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  759. pPoint.PutCoords(dLongitude, dLatitude);
  760. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
  761. selectCoordinateParams != null)
  762. {
  763. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  764. selectCoordinateParams
  765. .DaiHaoType ==
  766. DaiHaoType.Degree3);
  767. selectCoordinateParams.DaiHao = diahao;
  768. if (!coordinationsystem.ContainsKey(diahao))
  769. {
  770. ICoordinateSystem coordiante =
  771. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  772. selectCoordinateParams);
  773. coordinationsystem.Add(diahao, coordiante);
  774. }
  775. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  776. point.X = dLongitude;
  777. point.Y = dLatitude;
  778. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  779. point.Project(coordinationsystem[diahao]);
  780. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  781. Project_x.Text = Math.Round(point.X, 2).ToString();
  782. Project_y.Text = Math.Round(point.Y, 2).ToString();
  783. }
  784. }
  785. }
  786. catch (Exception ex)
  787. {
  788. }
  789. }
  790. private void Project_y_EditValueChanged(object sender, EventArgs e)
  791. {
  792. try{
  793. if (!BoolProYInit)
  794. return;
  795. BoolProYInit = false;
  796. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem )
  797. {
  798. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  799. pPoint.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  800. IProjectionCoordSystem projectionCoordSystem =
  801. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  802. pPoint.CoordinateSystem = projectionCoordSystem;
  803. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  804. pPoint.Project(pGeoCoordinateSystem);
  805. double dy = pPoint.Y;
  806. yod.Text = Math.Round(dy, 5).ToString();
  807. int iLongtitudeD, iLongtitudeM;
  808. double dLongtitudeS;
  809. GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  810. if (dLongtitudeS >= 60)
  811. {
  812. dLongtitudeS = dLongtitudeS - 60;
  813. iLongtitudeM = iLongtitudeM + 1;
  814. }
  815. if (iLongtitudeM >= 60)
  816. {
  817. iLongtitudeM = iLongtitudeM - 60;
  818. iLongtitudeD = iLongtitudeD + 1;
  819. }
  820. if (Convert.ToInt32(yd.Text) != iLongtitudeD)
  821. yd.Text = iLongtitudeD.ToString(); //度
  822. if (Convert.ToInt32(yf.Text) != iLongtitudeM)
  823. yf.Text = iLongtitudeM.ToString(); //分
  824. if (Convert.ToDouble(ym.Text) != Math.Round(dLongtitudeS, 1))
  825. ym.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  826. }
  827. else
  828. {
  829. if (selectCoordinateParams == null)
  830. return;
  831. double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) / 60 + Convert.ToDouble(xm.Text) / 3600;
  832. double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) / 60 + Convert.ToDouble(ym.Text) / 3600;
  833. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  834. {
  835. int diahao = int.Parse(Project_x.Text.Substring(0, 2));
  836. selectCoordinateParams.DaiHao = diahao;
  837. if (!coordinationsystem.ContainsKey(diahao))
  838. {
  839. ICoordinateSystem coordiante =
  840. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  841. selectCoordinateParams);
  842. coordinationsystem.Add(diahao, coordiante);
  843. }
  844. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  845. point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
  846. point.CoordinateSystem = coordinationsystem[diahao];
  847. point.Project(curView.FocusMap.SpatialReference);
  848. double dy = point.Y;
  849. int iLongtitudeD, iLongtitudeM;
  850. double dLongtitudeS;
  851. GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  852. if (dLongtitudeS >= 60)
  853. {
  854. dLongtitudeS = dLongtitudeS - 60;
  855. iLongtitudeM = iLongtitudeM + 1;
  856. }
  857. if (iLongtitudeM >= 60)
  858. {
  859. iLongtitudeM = iLongtitudeM - 60;
  860. iLongtitudeD = iLongtitudeD + 1;
  861. }
  862. if (Convert.ToInt32(yd.Text) != iLongtitudeD)
  863. yd.Text = iLongtitudeD.ToString(); //度
  864. if (Convert.ToInt32(yf.Text) != iLongtitudeM)
  865. yf.Text = iLongtitudeM.ToString(); //分
  866. if (Convert.ToDouble(ym.Text) != Math.Round(dLongtitudeS, 1))
  867. ym.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  868. }
  869. }
  870. }
  871. catch (Exception ex)
  872. {
  873. }
  874. }
  875. private void yd_EditValueChanged(object sender, EventArgs e)
  876. {
  877. try
  878. {
  879. if (!BoolGeoYInit)
  880. return;
  881. BoolGeoYInit = false;
  882. if (Convert.ToDouble(ym.Text) >= 60)
  883. {
  884. ym.Text = (Convert.ToDouble(ym.Text) - 60).ToString();
  885. yf.Text = (Convert.ToDouble(yf.Text) + 1).ToString();
  886. }
  887. if (Convert.ToDouble(yf.Text) >= 60)
  888. {
  889. yf.Text = (Convert.ToDouble(yf.Text) - 60).ToString();
  890. yd.Text = (Convert.ToDouble(yd.Text) + 1).ToString();
  891. }
  892. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  893. {
  894. double oldy = Convert.ToDouble(ym.Text);
  895. if (oldy >= 60)
  896. {
  897. ym.Text = (oldy%60).ToString();
  898. oldy = oldy - oldy%60;
  899. double addf = oldy/60;
  900. yf.Text = (Convert.ToDouble(yf.Text) + addf).ToString();
  901. }
  902. oldy = Convert.ToDouble(yf.Text);
  903. if (oldy >= 60)
  904. {
  905. yf.Text = (oldy%60).ToString();
  906. oldy = oldy - oldy%60;
  907. double addd = oldy/60;
  908. yd.Text = (Convert.ToDouble(yd.Text) + addd).ToString();
  909. }
  910. double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
  911. Convert.ToDouble(xm.Text) /3600;
  912. double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
  913. Convert.ToDouble(ym.Text) /3600;
  914. xod.Text = Math.Round(dLongitude, 5).ToString();
  915. yod.Text = Math.Round(dLatitude, 5).ToString();
  916. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  917. pPoint.PutCoords(dLongitude, dLatitude);
  918. IProjectionCoordSystem projectionCoordSystem =
  919. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  920. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  921. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  922. pPoint.Project(projectionCoordSystem);
  923. double dy = pPoint.Y;
  924. if (dy != dLatitude)
  925. Project_y.Text = Math.Round(dy, 2).ToString();
  926. }
  927. else
  928. {
  929. if (selectCoordinateParams == null)
  930. return;
  931. double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
  932. Convert.ToDouble(xm.Text) /3600;
  933. double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
  934. Convert.ToDouble(ym.Text) /3600;
  935. xod.Text = Math.Round(dLongitude, 5).ToString();
  936. yod.Text = Math.Round(dLatitude, 5).ToString();
  937. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  938. pPoint.PutCoords(dLongitude, dLatitude);
  939. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
  940. selectCoordinateParams != null)
  941. {
  942. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  943. selectCoordinateParams
  944. .DaiHaoType ==
  945. DaiHaoType.Degree3);
  946. selectCoordinateParams.DaiHao = diahao;
  947. if (!coordinationsystem.ContainsKey(diahao))
  948. {
  949. ICoordinateSystem coordiante =
  950. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  951. selectCoordinateParams);
  952. coordinationsystem.Add(diahao, coordiante);
  953. }
  954. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  955. point.X = dLongitude;
  956. point.Y = dLatitude;
  957. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  958. point.Project(coordinationsystem[diahao]);
  959. Project_x.Text = Math.Round(point.X, 2).ToString();
  960. Project_y.Text = Math.Round(point.Y, 2).ToString();
  961. }
  962. }
  963. }
  964. catch (Exception ex)
  965. {
  966. }
  967. }
  968. private void xod_EditValueChanged(object sender, EventArgs e)
  969. {
  970. try
  971. {
  972. if (!BoolGeoXInit)
  973. return;
  974. BoolGeoXInit = false;
  975. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  976. {
  977. int iLongtitudeD, iLongtitudeM;
  978. double dLongtitudeS;
  979. double dLongitude = Convert.ToDouble(xod.Text);
  980. double dLatitude = Convert.ToDouble(yod.Text);
  981. GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  982. xd.Text = iLongtitudeD.ToString(); //度
  983. xf.Text = iLongtitudeM.ToString(); //分
  984. xm.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  985. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  986. pPoint.PutCoords(dLongitude, dLatitude);
  987. IProjectionCoordSystem projectionCoordSystem =
  988. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  989. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  990. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  991. pPoint.Project(projectionCoordSystem);
  992. double dx = pPoint.X;
  993. if (dx != dLongitude)
  994. Project_x.Text = Math.Round(dx, 2).ToString();
  995. }
  996. else
  997. {
  998. if (selectCoordinateParams == null)
  999. return;
  1000. int iLongtitudeD, iLongtitudeM;
  1001. double dLongtitudeS;
  1002. double dLongitude = Convert.ToDouble(xod.Text);
  1003. double dLatitude = Convert.ToDouble(yod.Text);
  1004. GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  1005. xd.Text = iLongtitudeD.ToString(); //度
  1006. xf.Text = iLongtitudeM.ToString(); //分
  1007. xm.Text = Math.Round(dLongtitudeS, 1).ToString(); //秒
  1008. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1009. pPoint.PutCoords(dLongitude, dLatitude);
  1010. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  1011. {
  1012. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  1013. selectCoordinateParams
  1014. .DaiHaoType ==
  1015. DaiHaoType.Degree3);
  1016. selectCoordinateParams.DaiHao = diahao;
  1017. if (!coordinationsystem.ContainsKey(diahao))
  1018. {
  1019. ICoordinateSystem coordiante =
  1020. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  1021. selectCoordinateParams);
  1022. coordinationsystem.Add(diahao, coordiante);
  1023. }
  1024. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1025. point.X = dLongitude;
  1026. point.Y = dLatitude;
  1027. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  1028. point.Project(coordinationsystem[diahao]);
  1029. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  1030. Project_x.Text = Math.Round(point.X, 2).ToString();
  1031. Project_y.Text = Math.Round(point.Y, 2).ToString();
  1032. }
  1033. }
  1034. }
  1035. catch (Exception ex)
  1036. {
  1037. }
  1038. }
  1039. private void yod_EditValueChanged(object sender, EventArgs e)
  1040. {
  1041. try
  1042. {
  1043. if (!BoolGeoYInit)
  1044. return;
  1045. BoolGeoYInit = false;
  1046. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  1047. {
  1048. int iLatitudeD, iLatitudeM;
  1049. double dLatitudeS;
  1050. double dLongitude = Convert.ToDouble(xod.Text);
  1051. double dLatitude = Convert.ToDouble(yod.Text);
  1052. GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  1053. yd.Text = iLatitudeD.ToString(); //度
  1054. yf.Text = iLatitudeM.ToString(); //分
  1055. ym.Text = Math.Round(dLatitudeS, 1).ToString(); //秒
  1056. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1057. pPoint.PutCoords(dLongitude, dLatitude);
  1058. IProjectionCoordSystem projectionCoordSystem =
  1059. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  1060. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  1061. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  1062. pPoint.Project(projectionCoordSystem);
  1063. double dy = pPoint.Y;
  1064. if (dy != dLatitude)
  1065. Project_y.Text = Math.Round(dy, 2).ToString();
  1066. }
  1067. else
  1068. {
  1069. if (selectCoordinateParams == null)
  1070. return;
  1071. int iLatitudeD, iLatitudeM;
  1072. double dLatitudeS;
  1073. double dLongitude = Convert.ToDouble(xod.Text);
  1074. double dLatitude = Convert.ToDouble(yod.Text);
  1075. GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  1076. yd.Text = iLatitudeD.ToString(); //度
  1077. yf.Text = iLatitudeM.ToString(); //分
  1078. ym.Text = Math.Round(dLatitudeS, 1).ToString(); //秒
  1079. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1080. pPoint.PutCoords(dLongitude, dLatitude);
  1081. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  1082. {
  1083. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  1084. selectCoordinateParams
  1085. .DaiHaoType ==
  1086. DaiHaoType.Degree3);
  1087. selectCoordinateParams.DaiHao = diahao;
  1088. if (!coordinationsystem.ContainsKey(diahao))
  1089. {
  1090. ICoordinateSystem coordiante =
  1091. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  1092. selectCoordinateParams);
  1093. coordinationsystem.Add(diahao, coordiante);
  1094. }
  1095. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1096. point.X = dLongitude;
  1097. point.Y = dLatitude;
  1098. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  1099. point.Project(coordinationsystem[diahao]);
  1100. Project_x.Text = Math.Round(point.X, 2).ToString();
  1101. Project_y.Text = Math.Round(point.Y, 2).ToString();
  1102. }
  1103. }
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. }
  1108. }
  1109. private void xd_KeyPress(object sender, KeyPressEventArgs e)
  1110. {
  1111. BoolGeoXInit = true;
  1112. BoolGeoYInit = true;
  1113. }
  1114. private void xd_Click(object sender, EventArgs e)
  1115. {
  1116. BoolGeoXInit = true;
  1117. BoolGeoYInit = true;
  1118. }
  1119. #endregion
  1120. public CoreUI.Control.IComboBox cmbTFType
  1121. {
  1122. get
  1123. {
  1124. throw new NotImplementedException();
  1125. }
  1126. set
  1127. {
  1128. throw new NotImplementedException();
  1129. }
  1130. }
  1131. private void Project_x_Click(object sender, EventArgs e)
  1132. {
  1133. BoolProXInit = true;
  1134. }
  1135. private void Project_x_KeyPress(object sender, KeyPressEventArgs e)
  1136. {
  1137. BoolProXInit = true;
  1138. }
  1139. private void Project_y_Click(object sender, EventArgs e)
  1140. {
  1141. BoolProYInit = true;
  1142. }
  1143. private void Project_y_KeyPress(object sender, KeyPressEventArgs e)
  1144. {
  1145. BoolProYInit = true;
  1146. }
  1147. }
  1148. }