ControlCoodinateLocal.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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 = "IControlCoodinateLocal")]
  18. public partial class ControlCoodinateLocal : 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 ControlCoodinateLocal(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)
  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.EditValue.ToString(), xf.EditValue.ToString(), xm.EditValue.ToString(), yd.EditValue.ToString(), yf.EditValue.ToString(), ym.EditValue.ToString()));
  200. }
  201. else if (xtraTabControl1.SelectedTabPage == xtraTabPage3)
  202. {
  203. AddPointElement(dx, dy, true, string.Format("{0}°,{1}°", xod.EditValue.ToString(), yod.EditValue.ToString()));
  204. }
  205. else
  206. {
  207. AddPointElement(dx, dy, true, string.Format("{0},{1}", Project_x.EditValue.ToString(), Project_y.EditValue.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.EditValue) + Convert.ToDouble(xf.EditValue)/60 +
  236. Convert.ToDouble(xm.EditValue)/3600;
  237. dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue)/60 +
  238. Convert.ToDouble(ym.EditValue)/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.Value.ToString().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.EditValue), Convert.ToDouble(Project_y.EditValue));
  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.Value = X;
  431. this.Project_y.Value = Y;
  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.EditValue = Math.Round(dx, 5);
  440. yod.EditValue = Math.Round(dy, 5);
  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.EditValue = iLongtitudeD; //度
  457. xf.EditValue = iLongtitudeM; //分
  458. xm.EditValue = Math.Round(dLongtitudeS, 1); //秒
  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.EditValue = iLatitudeD; //度
  471. yf.EditValue = iLatitudeM; //分
  472. ym.EditValue = Math.Round(dLatitudeS, 1); //秒
  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.Value = X;
  522. this.Project_y.Value = Y;
  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.EditValue = iLongtitudeD; //度
  541. xf.EditValue = iLongtitudeM; //分
  542. xm.EditValue = Math.Round(dLongtitudeS, 1); //秒
  543. GetDMS(dy, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  544. yd.EditValue = iLatitudeD; //度
  545. yf.EditValue = iLatitudeM; //分
  546. ym.EditValue = Math.Round(dLatitudeS, 1); //秒
  547. if (coordinationsystem != null && selectCoordinateParams != null)
  548. {
  549. int diahao = MapSpatialReferenceUtils.GetDaihao(dx,
  550. selectCoordinateParams
  551. .DaiHaoType ==
  552. DaiHaoType.Degree3);
  553. selectCoordinateParams.DaiHao = diahao;
  554. if (!coordinationsystem.ContainsKey(diahao))
  555. {
  556. ICoordinateSystem coordiante =
  557. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  558. selectCoordinateParams);
  559. coordinationsystem.Add(diahao, coordiante);
  560. }
  561. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  562. point.X = dx;
  563. point.Y = dy;
  564. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  565. point.Project(coordinationsystem[diahao]);
  566. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  567. Project_x.Value = Math.Round(point.X, 2).ToString();
  568. Project_y.Value = Math.Round(point.Y, 2);
  569. }
  570. }
  571. catch (Exception ex)
  572. {
  573. }
  574. }
  575. #endregion
  576. public CoreUI.Control.IUserControl curControl
  577. {
  578. get { return null; }
  579. }
  580. public List<IElement> Elements { get { return LstElements; } }
  581. private void barEditItem1_EditValueChanged(object sender, EventArgs e)
  582. {
  583. //if (Convert.ToBoolean(barEditItem1.EditValue))
  584. //{
  585. // IsClear1 = true;
  586. //}
  587. //else
  588. //{
  589. // IsClear1 = false;
  590. //}
  591. }
  592. private double ConvertPixelsToAVUnits(IActiveView pAv, long lTolerance)
  593. {
  594. if (pAv == null) return 5;
  595. IDisplayTransformation pTransformation;
  596. IScreenDisplay pScreenDisplay = pAv.ScreenDisplay;
  597. pTransformation = pScreenDisplay.DisplayTransformation;
  598. WKSPoint pOutPoint;
  599. TagPOINT pInPoint;
  600. pOutPoint.X = 0;
  601. pOutPoint.Y = 0;
  602. pInPoint.x = (int)lTolerance;
  603. pInPoint.y = (int)lTolerance;
  604. pTransformation.TransformCoords(ref pOutPoint, ref pInPoint, 1, 6);
  605. return pOutPoint.X;
  606. }
  607. #region 同步更新
  608. private void Project_x_EditValueChanged(object sender, EventArgs e)
  609. {
  610. try
  611. {
  612. if (!BoolProXInit)
  613. return;
  614. BoolProXInit = false;
  615. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  616. {
  617. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  618. pPoint.PutCoords(Convert.ToDouble(Project_x.EditValue), Convert.ToDouble(Project_y.EditValue));
  619. IProjectionCoordSystem projectionCoordSystem =
  620. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  621. pPoint.CoordinateSystem = projectionCoordSystem;
  622. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  623. pPoint.Project(pGeoCoordinateSystem);
  624. double dx = pPoint.X;
  625. xod.EditValue = Math.Round(dx,5);
  626. int iLongtitudeD, iLongtitudeM;
  627. double dLongtitudeS;
  628. GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  629. if (dLongtitudeS >= 60)
  630. {
  631. dLongtitudeS = dLongtitudeS - 60;
  632. iLongtitudeM = iLongtitudeM + 1;
  633. }
  634. if (iLongtitudeM >= 60)
  635. {
  636. iLongtitudeM = iLongtitudeM - 60;
  637. iLongtitudeD = iLongtitudeD + 1;
  638. }
  639. int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
  640. if (Convert.ToInt32(yd.EditValue) != iLongtitudeD)
  641. xd.EditValue = iLongtitudeD; //度
  642. if (Convert.ToInt32(yf.EditValue) != iLongtitudeM)
  643. xf.EditValue = iLongtitudeM; //分
  644. if (Convert.ToInt32(ym.EditValue) != iLongtitudeS)
  645. xm.EditValue = iLongtitudeS;
  646. }
  647. else
  648. {
  649. if (selectCoordinateParams == null)
  650. return;
  651. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  652. {
  653. int diahao = int.Parse(Project_x.Value.ToString().Substring(0, 2));
  654. selectCoordinateParams.DaiHao = diahao;
  655. if (!coordinationsystem.ContainsKey(diahao))
  656. {
  657. ICoordinateSystem coordiante =
  658. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  659. selectCoordinateParams);
  660. coordinationsystem.Add(diahao, coordiante);
  661. }
  662. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  663. point.PutCoords(Convert.ToDouble(Project_x.EditValue), Convert.ToDouble(Project_y.EditValue));
  664. point.CoordinateSystem = coordinationsystem[diahao];
  665. point.Project(curView.FocusMap.SpatialReference);
  666. double dx = point.X;
  667. int iLongtitudeD, iLongtitudeM;
  668. double dLongtitudeS;
  669. GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  670. if (dLongtitudeS >= 60)
  671. {
  672. dLongtitudeS = dLongtitudeS - 60;
  673. iLongtitudeM = iLongtitudeM + 1;
  674. }
  675. if (iLongtitudeM >= 60)
  676. {
  677. iLongtitudeM = iLongtitudeM - 60;
  678. iLongtitudeD = iLongtitudeD + 1;
  679. }
  680. int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
  681. if (Convert.ToInt32(yd.EditValue) != iLongtitudeD)
  682. xd.EditValue = iLongtitudeD; //度
  683. if (Convert.ToInt32(yf.EditValue) != iLongtitudeM)
  684. xf.EditValue = iLongtitudeM; //分
  685. if (Convert.ToInt32(ym.EditValue) != iLongtitudeS)
  686. xm.EditValue = iLongtitudeS;
  687. }
  688. }
  689. }
  690. catch (Exception ex)
  691. {
  692. }
  693. }
  694. private void xd_EditValueChanged(object sender, EventArgs e)
  695. {
  696. try
  697. {
  698. if (!BoolGeoXInit)
  699. return;
  700. BoolGeoXInit = false;
  701. if (Convert.ToDouble(xm.EditValue) >= 60)
  702. {
  703. xm.EditValue = Convert.ToDouble(xm.EditValue) - 60;
  704. xf.EditValue = Convert.ToDouble(xf.EditValue) + 1;
  705. }
  706. if (Convert.ToDouble(xf.EditValue) >= 60)
  707. {
  708. xf.EditValue = Convert.ToDouble(xf.EditValue) - 60;
  709. xd.EditValue = Convert.ToDouble(xd.EditValue) + 1;
  710. }
  711. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  712. {
  713. double oldx = Convert.ToDouble(xm.EditValue);
  714. if (oldx >= 60)
  715. {
  716. xm.EditValue = oldx%60;
  717. oldx = oldx - oldx%60;
  718. double addf = oldx/60;
  719. xf.EditValue = Convert.ToDouble(xf.EditValue) + addf;
  720. }
  721. oldx = Convert.ToDouble(xf.EditValue);
  722. if (oldx >= 60)
  723. {
  724. xf.EditValue = oldx%60;
  725. oldx = oldx - oldx%60;
  726. double addd = oldx/60;
  727. xd.EditValue = Convert.ToDouble(xd.EditValue) + addd;
  728. }
  729. double dLongitude = Convert.ToDouble(xd.EditValue) + Convert.ToDouble(xf.EditValue)/60 +
  730. Convert.ToDouble(xm.EditValue)/3600;
  731. double dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue)/60 +
  732. Convert.ToDouble(ym.EditValue)/3600;
  733. xod.EditValue = Math.Round(dLongitude, 5);
  734. yod.EditValue = Math.Round(dLatitude, 5);
  735. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  736. pPoint.PutCoords(dLongitude, dLatitude);
  737. IProjectionCoordSystem projectionCoordSystem =
  738. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  739. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  740. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  741. pPoint.Project(projectionCoordSystem);
  742. double dx = pPoint.X;
  743. if (dx != dLongitude)
  744. Project_x.EditValue = Math.Round(dx, 2);
  745. }
  746. else
  747. {
  748. if (selectCoordinateParams == null)
  749. return;
  750. double dLongitude = Convert.ToDouble(xd.EditValue) + Convert.ToDouble(xf.EditValue)/60 +
  751. Convert.ToDouble(xm.EditValue)/3600;
  752. double dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue)/60 +
  753. Convert.ToDouble(ym.EditValue)/3600;
  754. xod.EditValue = Math.Round(dLongitude, 5);
  755. yod.EditValue = Math.Round(dLatitude, 5);
  756. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  757. pPoint.PutCoords(dLongitude, dLatitude);
  758. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
  759. selectCoordinateParams != null)
  760. {
  761. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  762. selectCoordinateParams
  763. .DaiHaoType ==
  764. DaiHaoType.Degree3);
  765. selectCoordinateParams.DaiHao = diahao;
  766. if (!coordinationsystem.ContainsKey(diahao))
  767. {
  768. ICoordinateSystem coordiante =
  769. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  770. selectCoordinateParams);
  771. coordinationsystem.Add(diahao, coordiante);
  772. }
  773. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  774. point.X = dLongitude;
  775. point.Y = dLatitude;
  776. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  777. point.Project(coordinationsystem[diahao]);
  778. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  779. Project_x.Value = Math.Round(point.X, 2).ToString();
  780. Project_y.Value = Math.Round(point.Y, 2);
  781. }
  782. }
  783. }
  784. catch (Exception ex)
  785. {
  786. }
  787. }
  788. private void Project_y_EditValueChanged(object sender, EventArgs e)
  789. {
  790. try{
  791. if (!BoolProYInit)
  792. return;
  793. BoolProYInit = false;
  794. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem )
  795. {
  796. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  797. pPoint.PutCoords(Convert.ToDouble(Project_x.EditValue), Convert.ToDouble(Project_y.EditValue));
  798. IProjectionCoordSystem projectionCoordSystem =
  799. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  800. pPoint.CoordinateSystem = projectionCoordSystem;
  801. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  802. pPoint.Project(pGeoCoordinateSystem);
  803. double dy = pPoint.Y;
  804. yod.EditValue = Math.Round(dy, 5);
  805. int iLongtitudeD, iLongtitudeM;
  806. double dLongtitudeS;
  807. GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  808. if (dLongtitudeS >= 60)
  809. {
  810. dLongtitudeS = dLongtitudeS - 60;
  811. iLongtitudeM = iLongtitudeM + 1;
  812. }
  813. if (iLongtitudeM >= 60)
  814. {
  815. iLongtitudeM = iLongtitudeM - 60;
  816. iLongtitudeD = iLongtitudeD + 1;
  817. }
  818. if (Convert.ToInt32(yd.EditValue) != iLongtitudeD)
  819. yd.EditValue = iLongtitudeD; //度
  820. if (Convert.ToInt32(yf.EditValue) != iLongtitudeM)
  821. yf.EditValue = iLongtitudeM; //分
  822. if (Convert.ToDouble(ym.EditValue) != Math.Round(dLongtitudeS, 1))
  823. ym.EditValue = Math.Round(dLongtitudeS, 1); //秒
  824. }
  825. else
  826. {
  827. if (selectCoordinateParams == null)
  828. return;
  829. double dLongitude = Convert.ToDouble(xd.EditValue) + Convert.ToDouble(xf.EditValue) / 60 + Convert.ToDouble(xm.EditValue) / 3600;
  830. double dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue) / 60 + Convert.ToDouble(ym.EditValue) / 3600;
  831. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  832. {
  833. int diahao = int.Parse(Project_x.Value.ToString().Substring(0, 2));
  834. selectCoordinateParams.DaiHao = diahao;
  835. if (!coordinationsystem.ContainsKey(diahao))
  836. {
  837. ICoordinateSystem coordiante =
  838. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  839. selectCoordinateParams);
  840. coordinationsystem.Add(diahao, coordiante);
  841. }
  842. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  843. point.PutCoords(Convert.ToDouble(Project_x.EditValue), Convert.ToDouble(Project_y.EditValue));
  844. point.CoordinateSystem = coordinationsystem[diahao];
  845. point.Project(curView.FocusMap.SpatialReference);
  846. double dy = point.Y;
  847. int iLongtitudeD, iLongtitudeM;
  848. double dLongtitudeS;
  849. GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  850. if (dLongtitudeS >= 60)
  851. {
  852. dLongtitudeS = dLongtitudeS - 60;
  853. iLongtitudeM = iLongtitudeM + 1;
  854. }
  855. if (iLongtitudeM >= 60)
  856. {
  857. iLongtitudeM = iLongtitudeM - 60;
  858. iLongtitudeD = iLongtitudeD + 1;
  859. }
  860. if (Convert.ToInt32(yd.EditValue) != iLongtitudeD)
  861. yd.EditValue = iLongtitudeD; //度
  862. if (Convert.ToInt32(yf.EditValue) != iLongtitudeM)
  863. yf.EditValue = iLongtitudeM; //分
  864. if (Convert.ToDouble(ym.EditValue) != Math.Round(dLongtitudeS, 1))
  865. ym.EditValue = Math.Round(dLongtitudeS, 1); //秒
  866. }
  867. }
  868. }
  869. catch (Exception ex)
  870. {
  871. }
  872. }
  873. private void yd_EditValueChanged(object sender, EventArgs e)
  874. {
  875. try
  876. {
  877. if (!BoolGeoYInit)
  878. return;
  879. BoolGeoYInit = false;
  880. if (Convert.ToDouble(ym.EditValue) >= 60)
  881. {
  882. ym.EditValue = Convert.ToDouble(ym.EditValue) - 60;
  883. yf.EditValue = Convert.ToDouble(yf.EditValue) + 1;
  884. }
  885. if (Convert.ToDouble(yf.EditValue) >= 60)
  886. {
  887. yf.EditValue = Convert.ToDouble(yf.EditValue) - 60;
  888. yd.EditValue = Convert.ToDouble(yd.EditValue) + 1;
  889. }
  890. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  891. {
  892. double oldy = Convert.ToDouble(ym.EditValue);
  893. if (oldy >= 60)
  894. {
  895. ym.EditValue = oldy%60;
  896. oldy = oldy - oldy%60;
  897. double addf = oldy/60;
  898. yf.EditValue = Convert.ToDouble(yf.EditValue) + addf;
  899. }
  900. oldy = Convert.ToDouble(yf.EditValue);
  901. if (oldy >= 60)
  902. {
  903. yf.EditValue = oldy%60;
  904. oldy = oldy - oldy%60;
  905. double addd = oldy/60;
  906. yd.EditValue = Convert.ToDouble(yd.EditValue) + addd;
  907. }
  908. double dLongitude = Convert.ToDouble(xd.EditValue) + Convert.ToDouble(xf.EditValue)/60 +
  909. Convert.ToDouble(xm.EditValue)/3600;
  910. double dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue)/60 +
  911. Convert.ToDouble(ym.EditValue)/3600;
  912. xod.EditValue = Math.Round(dLongitude, 5);
  913. yod.EditValue = Math.Round(dLatitude, 5);
  914. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  915. pPoint.PutCoords(dLongitude, dLatitude);
  916. IProjectionCoordSystem projectionCoordSystem =
  917. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  918. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  919. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  920. pPoint.Project(projectionCoordSystem);
  921. double dy = pPoint.Y;
  922. if (dy != dLatitude)
  923. Project_y.EditValue = Math.Round(dy, 2);
  924. }
  925. else
  926. {
  927. if (selectCoordinateParams == null)
  928. return;
  929. double dLongitude = Convert.ToDouble(xd.EditValue) + Convert.ToDouble(xf.EditValue)/60 +
  930. Convert.ToDouble(xm.EditValue)/3600;
  931. double dLatitude = Convert.ToDouble(yd.EditValue) + Convert.ToDouble(yf.EditValue)/60 +
  932. Convert.ToDouble(ym.EditValue)/3600;
  933. xod.EditValue = Math.Round(dLongitude, 5);
  934. yod.EditValue = Math.Round(dLatitude, 5);
  935. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  936. pPoint.PutCoords(dLongitude, dLatitude);
  937. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
  938. selectCoordinateParams != null)
  939. {
  940. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  941. selectCoordinateParams
  942. .DaiHaoType ==
  943. DaiHaoType.Degree3);
  944. selectCoordinateParams.DaiHao = diahao;
  945. if (!coordinationsystem.ContainsKey(diahao))
  946. {
  947. ICoordinateSystem coordiante =
  948. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  949. selectCoordinateParams);
  950. coordinationsystem.Add(diahao, coordiante);
  951. }
  952. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  953. point.X = dLongitude;
  954. point.Y = dLatitude;
  955. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  956. point.Project(coordinationsystem[diahao]);
  957. Project_x.Value = Math.Round(point.X, 2);
  958. Project_y.Value = Math.Round(point.Y, 2);
  959. }
  960. }
  961. }
  962. catch (Exception ex)
  963. {
  964. }
  965. }
  966. private void xod_EditValueChanged(object sender, EventArgs e)
  967. {
  968. try
  969. {
  970. if (!BoolGeoXInit)
  971. return;
  972. BoolGeoXInit = false;
  973. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  974. {
  975. int iLongtitudeD, iLongtitudeM;
  976. double dLongtitudeS;
  977. double dLongitude = Convert.ToDouble(xod.EditValue);
  978. double dLatitude = Convert.ToDouble(yod.EditValue);
  979. GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  980. xd.EditValue = iLongtitudeD; //度
  981. xf.EditValue = iLongtitudeM; //分
  982. xm.EditValue = Math.Round(dLongtitudeS, 1); //秒
  983. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  984. pPoint.PutCoords(dLongitude, dLatitude);
  985. IProjectionCoordSystem projectionCoordSystem =
  986. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  987. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  988. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  989. pPoint.Project(projectionCoordSystem);
  990. double dx = pPoint.X;
  991. if (dx != dLongitude)
  992. Project_x.EditValue = Math.Round(dx, 2);
  993. }
  994. else
  995. {
  996. if (selectCoordinateParams == null)
  997. return;
  998. int iLongtitudeD, iLongtitudeM;
  999. double dLongtitudeS;
  1000. double dLongitude = Convert.ToDouble(xod.EditValue);
  1001. double dLatitude = Convert.ToDouble(yod.EditValue);
  1002. GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
  1003. xd.EditValue = iLongtitudeD; //度
  1004. xf.EditValue = iLongtitudeM; //分
  1005. xm.EditValue = Math.Round(dLongtitudeS, 1); //秒
  1006. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1007. pPoint.PutCoords(dLongitude, dLatitude);
  1008. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  1009. {
  1010. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  1011. selectCoordinateParams
  1012. .DaiHaoType ==
  1013. DaiHaoType.Degree3);
  1014. selectCoordinateParams.DaiHao = diahao;
  1015. if (!coordinationsystem.ContainsKey(diahao))
  1016. {
  1017. ICoordinateSystem coordiante =
  1018. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  1019. selectCoordinateParams);
  1020. coordinationsystem.Add(diahao, coordiante);
  1021. }
  1022. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1023. point.X = dLongitude;
  1024. point.Y = dLatitude;
  1025. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  1026. point.Project(coordinationsystem[diahao]);
  1027. //string x = diahao.ToString() + Math.Round(point.X, 2).ToString();
  1028. Project_x.Value = Math.Round(point.X, 2).ToString();
  1029. Project_y.Value = Math.Round(point.Y, 2);
  1030. }
  1031. }
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. }
  1036. }
  1037. private void yod_EditValueChanged(object sender, EventArgs e)
  1038. {
  1039. try
  1040. {
  1041. if (!BoolGeoYInit)
  1042. return;
  1043. BoolGeoYInit = false;
  1044. if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
  1045. {
  1046. int iLatitudeD, iLatitudeM;
  1047. double dLatitudeS;
  1048. double dLongitude = Convert.ToDouble(xod.EditValue);
  1049. double dLatitude = Convert.ToDouble(yod.EditValue);
  1050. GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  1051. yd.EditValue = iLatitudeD; //度
  1052. yf.EditValue = iLatitudeM; //分
  1053. ym.EditValue = Math.Round(dLatitudeS, 1); //秒
  1054. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1055. pPoint.PutCoords(dLongitude, dLatitude);
  1056. IProjectionCoordSystem projectionCoordSystem =
  1057. curView.FocusMap.SpatialReference as IProjectionCoordSystem;
  1058. IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
  1059. pPoint.CoordinateSystem = pGeoCoordinateSystem;
  1060. pPoint.Project(projectionCoordSystem);
  1061. double dy = pPoint.Y;
  1062. if (dy != dLatitude)
  1063. Project_y.EditValue = Math.Round(dy, 2);
  1064. }
  1065. else
  1066. {
  1067. if (selectCoordinateParams == null)
  1068. return;
  1069. int iLatitudeD, iLatitudeM;
  1070. double dLatitudeS;
  1071. double dLongitude = Convert.ToDouble(xod.EditValue);
  1072. double dLatitude = Convert.ToDouble(yod.EditValue);
  1073. GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
  1074. yd.EditValue = iLatitudeD; //度
  1075. yf.EditValue = iLatitudeM; //分
  1076. ym.EditValue = Math.Round(dLatitudeS, 1); //秒
  1077. IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1078. pPoint.PutCoords(dLongitude, dLatitude);
  1079. if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
  1080. {
  1081. int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
  1082. selectCoordinateParams
  1083. .DaiHaoType ==
  1084. DaiHaoType.Degree3);
  1085. selectCoordinateParams.DaiHao = diahao;
  1086. if (!coordinationsystem.ContainsKey(diahao))
  1087. {
  1088. ICoordinateSystem coordiante =
  1089. SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
  1090. selectCoordinateParams);
  1091. coordinationsystem.Add(diahao, coordiante);
  1092. }
  1093. IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
  1094. point.X = dLongitude;
  1095. point.Y = dLatitude;
  1096. point.CoordinateSystem = curView.FocusMap.SpatialReference;
  1097. point.Project(coordinationsystem[diahao]);
  1098. Project_x.Value = Math.Round(point.X, 2);
  1099. Project_y.Value = Math.Round(point.Y, 2);
  1100. }
  1101. }
  1102. }
  1103. catch (Exception ex)
  1104. {
  1105. }
  1106. }
  1107. private void xd_KeyPress(object sender, KeyPressEventArgs e)
  1108. {
  1109. BoolGeoXInit = true;
  1110. BoolGeoYInit = true;
  1111. }
  1112. private void xd_Click(object sender, EventArgs e)
  1113. {
  1114. BoolGeoXInit = true;
  1115. BoolGeoYInit = true;
  1116. }
  1117. #endregion
  1118. public CoreUI.Control.IComboBox cmbTFType
  1119. {
  1120. get
  1121. {
  1122. throw new NotImplementedException();
  1123. }
  1124. set
  1125. {
  1126. throw new NotImplementedException();
  1127. }
  1128. }
  1129. private void Project_x_Click(object sender, EventArgs e)
  1130. {
  1131. BoolProXInit = true;
  1132. }
  1133. private void Project_x_KeyPress(object sender, KeyPressEventArgs e)
  1134. {
  1135. BoolProXInit = true;
  1136. }
  1137. private void Project_y_Click(object sender, EventArgs e)
  1138. {
  1139. BoolProYInit = true;
  1140. }
  1141. private void Project_y_KeyPress(object sender, KeyPressEventArgs e)
  1142. {
  1143. BoolProYInit = true;
  1144. }
  1145. }
  1146. }