1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using Tofly.Core.Context;
- using Tofly.Core.Context.Support;
- using Tofly.GIS;
- using Tofly.GIS.Carto;
- using Tofly.GIS.Display;
- using Tofly.GIS.Geometry;
- using Tofly.GIS.SpatialReference;
- using Tofly.SearchUI.Common;
- using System.Collections.Generic;
- using Tofly.GIS.Util;
- using Tofly.GISUI.Utils;
- namespace Tofly.SearchUI.Win
- {
- [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "IControlCoodinateLocal2")]
- public partial class ControlCoodinateLocal2 : Tofly.CoreUI.Win.Control.UserControlClass, IlocalControl
- {
-
- private IActiveView curView;
- public double X;
- public double Y;
- public double NormalScale;
- public bool IsClear1 = false;
- private const double c_LONGMAXLIMIT = 180.0;
- private const double c_LONGMINLIMIT = -180.0;
- private const double c_LATITUDEMAXLIMIT = 90.0;
- private const double c_LATITUDEMINLIMIT = -90.0;
- private List<IElement> LstElements = new List<IElement>();
- private bool BoolGeoXInit = true;
- private bool BoolGeoYInit = true;
- private bool BoolProXInit = true;
- private bool BoolProYInit = true;
- private double CentralMeridian = 0;
- private int ChangeExtent = 3;
- private double ProXMax = 0;
- private double ProXMin = 0;
- private double GeoXMax = 0;
- private double GeoXMin = 0;
-
- private bool showFalseButton = true;
- private CoordinateCreateParams selectCoordinateParams = null;
- private Dictionary<int,ICoordinateSystem> coordinationsystem = new Dictionary<int, ICoordinateSystem>();
-
- public ControlCoodinateLocal2(IActiveView view, double scacle, bool showFalseButton, CoordinateCreateParams SelectCoordinateParams)
- {
- curView = view;
- NormalScale = scacle;
- this.selectCoordinateParams = SelectCoordinateParams;
- if(selectCoordinateParams!=null)
- this.selectCoordinateParams.AddDiaHao = true;
- InitializeComponent();
- InitSpatialReference();
- if (!showFalseButton)
- this.btnAddLablePoint.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
- }
- public bool IsClear
- {
- get
- {
- return IsClear1;
- }
- set
- {
- IsClear1=value;
- }
- }
- private enum EnumBtnEvent
- {
- enumbtnPan,
- enumbtnZoomIn,
- enumbtnFlash,
- enumbtnAddPoint,
- enumbtnAddLablePoint,
- enumbtnAddCallout,
- enumbtnQuery
- }
- private void Button_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- try
- {
- switch (e.Item.Name)
- {
- case "btnClear":
-
-
-
-
- curView.FocusMap.DeleteAllElements();
- curView.Refresh();
- LstElements.Clear();
- break;
- case "local":
- OrientationLocal(EnumBtnEvent.enumbtnQuery);
- OrientationLocal(EnumBtnEvent.enumbtnAddLablePoint);
- break;
- case "btnFlash":
- OrientationLocal(EnumBtnEvent.enumbtnFlash);
- break;
- case "btnAddPoint":
- OrientationLocal(EnumBtnEvent.enumbtnAddPoint);
- break;
- case "btnAddLablePoint":
- OrientationLocal(EnumBtnEvent.enumbtnAddLablePoint);
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- private void OrientationLocal(EnumBtnEvent pEnumBtnEvent)
- {
- try
- {
- ICoordinateSystem pSpatialReference;
- pSpatialReference = curView.FocusMap.SpatialReference;
- if (pSpatialReference is IUnknownCoordSystem || pSpatialReference == null)
- {
- LocationByXY(pEnumBtnEvent, Convert.ToDouble(X), Convert.ToDouble(Y));
- string strText = X + "," + Y;
- }
- else if (pSpatialReference is IGeoCoordinateSystem)
- {
- GeographicLocation(pEnumBtnEvent);
- }
- else if (pSpatialReference is IProjectionCoordSystem)
- {
-
- LocationByXY(pEnumBtnEvent, Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- string strText = Project_x + "," + Project_y;
- }
- }
- catch (Exception ex)
- {
-
- }
- }
- private static void GetDMS(double dValue, bool bLatitude, out int iDegrees, out int iMinutes, out double DSecondes)
- {
- try
- {
-
-
-
-
-
- iDegrees = -1;
- iMinutes = -1;
- DSecondes = -1;
- if (bLatitude &&( dValue <= 0 || dValue > 180))
- return;
-
-
- iDegrees = Convert.ToInt16(Math.Truncate(dValue));
- dValue = dValue - iDegrees;
- iMinutes = Convert.ToInt16(Math.Truncate((dValue) * 60));
- DSecondes = Convert.ToInt16(Math.Round((dValue * 60 - iMinutes) * 60));
-
- if (DSecondes == 60)
- {
- iMinutes = iMinutes + 1;
- DSecondes = 0;
- }
-
- if (iMinutes == 60)
- {
- iMinutes = 0;
- iDegrees = iDegrees + 1;
- }
- }
- catch (Exception ex)
- {
- iDegrees = 0;
- iMinutes = 0;
- DSecondes = 0;
- }
- }
- private void LocationByXY(EnumBtnEvent pEnumBtnEvent, double dx, double dy)
- {
- try
- {
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dx, dy);
- switch (pEnumBtnEvent)
- {
- case EnumBtnEvent.enumbtnFlash:
-
- curView.FocusMap.FlashGeometry(pPoint);
- break;
- case EnumBtnEvent.enumbtnAddPoint:
- AddPointElement(dx,dy, false, string.Format("{0},{1}", dx.ToString(),dy.ToString()));
- break;
- case EnumBtnEvent.enumbtnAddLablePoint:
- if (xtraTabControl1.SelectedTabPage==xtraTabPage1)
- {
- AddPointElement(dx, dy, true, string.Format("{0}°{1}′{2}″,{3}°{4}′{5}″", xd.Text, xf.Text, xm.Text, yd.Text, yf.Text, ym.Text));
- }
- else if (xtraTabControl1.SelectedTabPage == xtraTabPage3)
- {
- AddPointElement(dx, dy, true, string.Format("{0}°,{1}°", xod.Text, yod.Text));
- }
- else
- {
- AddPointElement(dx, dy, true, string.Format("{0},{1}", Project_x.Text.ToString(), Project_y.Text.ToString()));
- }
- break;
- case EnumBtnEvent.enumbtnQuery:
- LocalOprate(dx, dy, curView);
- break;
- }
- }
- catch (Exception ex)
- {
- }
- }
- #region 按钮事件
- private void repositoryItemCheckEdit1_CheckStateChanged(object sender, EventArgs e)
- {
- if (((DevExpress.XtraEditors.CheckEdit)(sender)).CheckState == CheckState.Checked)
- IsClear = true;
- else
- IsClear = false;
- }
- private void GeographicLocation(EnumBtnEvent pEnumBtnEvent)
- {
- try
- {
- double dLongitude = 0;
- double dLatitude = 0;
- if (this.xtraTabControl1.SelectedTabPageIndex == 0)
- {
- dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
- Convert.ToDouble(xm.Text) /3600;
- dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
- Convert.ToDouble(ym.Text) /3600;
- }
- else if (this.xtraTabControl1.SelectedTabPageIndex == 1)
- {
- dLongitude = Convert.ToDouble(xod.Text);
- dLatitude = Convert.ToDouble(yod.Text);
- }
- else if (this.xtraTabControl1.SelectedTabPageIndex == 2)
- {
- int diahao = int.Parse(Project_x.Text.Substring(0, 2));
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- point.CoordinateSystem = coordinationsystem[diahao];
- point.Project(curView.FocusMap.SpatialReference);
- dLongitude = point.X;
- dLatitude = point.Y;
- }
-
- if (dLongitude >= c_LONGMINLIMIT && dLongitude <= c_LONGMAXLIMIT && dLatitude >= c_LATITUDEMINLIMIT && dLatitude <= c_LATITUDEMAXLIMIT)
- {
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- LocationByXY(pEnumBtnEvent, GeoCoordinateConvertProjection(dLongitude, dLatitude).X, GeoCoordinateConvertProjection(dLongitude, dLatitude).Y);
- }
- else
- {
- LocationByXY(pEnumBtnEvent, dLongitude, dLatitude);
- }
- string strText = dLongitude.ToString("0.00") + "," + dLatitude.ToString("0.00");
-
-
-
-
- }
- else
- {
-
- }
- }
- catch (Exception ex)
- {
- }
- }
- public void LocalOprate(double dx, double dy, IActiveView pAv)
- {
- try
- {
- IEnvelope pEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dx, dy);
- pEnv = pAv.Extent;
- pEnv.CenterAt(pPoint);
- pAv.Extent = pEnv;
- pAv.FocusMap.SetMapScale(NormalScale, true);
- pAv.Refresh();
-
- pAv.FocusMap.FlashGeometry(pPoint);
- }
- catch (Exception ex)
- {
- }
- }
- public void AddPointElement(double x, double y, bool bIsAddLablePoint, string strLableText)
- {
- IGraphicsContainer pGraphicsContainer;
- pGraphicsContainer = curView as IGraphicsContainer;
-
- IPoint pPoint;
- pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.Project(curView.FocusMap.SpatialReference);
- pPoint.PutCoords(x, y);
-
-
-
-
-
-
- IPictureMarkerSymbol pSymlbol = ContextRegistry.GetContext().GetObject("GIS_PictureMarkerSymbolClass") as IPictureMarkerSymbol;
- pSymlbol.CreateMarkerSymbolFromFile(Application.StartupPath + @"\Icon\Flag.png");
- pSymlbol.Size = 60;
- IMarkerElement pMarket = ContextRegistry.GetContext().GetObject("GIS_MarkerElement") as IMarkerElement;
- pMarket.Symbol = pSymlbol;
- IElement pElemt = (IElement)pMarket;
- pElemt.Geometry = pPoint;
- pGraphicsContainer.AddElement(pElemt, 0);
- if (!LstElements.Contains(pElemt))
- LstElements.Add(pElemt);
- if (bIsAddLablePoint)
- {
- IElement element;
- ITextElement textelement = ContextRegistry.GetContext().GetObject("GIS_TextElementClass") as ITextElement;
- textelement.Text = strLableText;
- element = textelement as IElement;
- IPoint pTextPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pTextPoint.X = pPoint.X;
- double YChange = ConvertPixelsToAVUnits(curView, 1);
- pTextPoint.Y = pPoint.Y + YChange;
- pTextPoint.Project(curView.FocusMap.SpatialReference);
- element.Geometry = pTextPoint;
- pGraphicsContainer.AddElement(element, 0);
- if (!LstElements.Contains(element))
- LstElements.Add(element);
- }
- curView.PartialRefresh(ViewDrawPhase.ViewGraphics, null, null);
- }
- #endregion
- #region 初始化坐标
-
-
-
-
-
-
- private IPoint GeoCoordinateConvertProjection(double dlongitude, double dlatitude)
- {
- try
- {
- if (curView.FocusMap.SpatialReference == null) return null;
- if (curView.FocusMap.SpatialReference is IUnknownCoordSystem) return null;
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.Project(curView.FocusMap.SpatialReference);
- ICoordinateSystem pSpatialReference;
- IGeoCoordinateSystem pGeographicCoordinateSystem;
- IProjectionCoordSystem pProjectedCoordinateSystem;
- pSpatialReference = curView.FocusMap.SpatialReference;
- pProjectedCoordinateSystem = (IProjectionCoordSystem)pSpatialReference;
- pGeographicCoordinateSystem = pProjectedCoordinateSystem.GeographicCoordinateSystem;
- pPoint.Project((ICoordinateSystem)pGeographicCoordinateSystem);
- pPoint.PutCoords(dlongitude, dlatitude);
- pPoint.Project(curView.FocusMap.SpatialReference);
- return pPoint;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
- private void InitSpatialReference()
- {
- try
- {
- BoolGeoXInit = true;
- ICoordinateSystem pSpatialReference = curView.FocusMap.SpatialReference;
- if (pSpatialReference is IGeoCoordinateSystem)
- {
- BoolProXInit = false;
- BoolProYInit = false;
- InitGeographicCoordinate();
- }
- else if (pSpatialReference is IUnknownCoordSystem || pSpatialReference == null)
- {
- InitUnknowCoordinate();
-
- this.PanelGeo.Visible = false;
- this.panelGeoD.Visible = false;
- this.xtraTabPage2.PageVisible = false;
- this.panelPro.Dock = System.Windows.Forms.DockStyle.Fill;
- }
- else if(pSpatialReference is IProjectionCoordSystem)
- {
- BoolGeoXInit = false;
- BoolGeoYInit = false;
- InitProjectedCoordinate(pSpatialReference as IProjectionCoordSystem);
- this.panelPro.Visible = true;
- }
-
- }
- catch (Exception ex)
- {
- }
- }
-
-
-
- private void InitProjectedCoordinate(IProjectionCoordSystem projectionCoordSystem)
- {
- try
- {
- IEnvelope pEnvelope;
- pEnvelope = curView.Extent;
- X = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 2);
- Y = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 2);
- this.Project_x.Text = X.ToString();
- this.Project_y.Text = Y.ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(X, Y);
- pPoint.CoordinateSystem = projectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.Project(pGeoCoordinateSystem);
- double dx = pPoint.X;
- double dy = pPoint.Y;
- xod.Text = Math.Round(dx, 5).ToString();
- yod.Text = Math.Round(dy, 5).ToString();
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- int iLatitudeD, iLatitudeM;
- double dLatitudeS;
- GetDMS(dx, true , out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- if (dLongtitudeS >= 60)
- {
- dLongtitudeS = dLongtitudeS - 60;
- iLongtitudeM = iLongtitudeM + 1;
- }
- if (iLongtitudeM >= 60)
- {
- iLongtitudeM = iLongtitudeM - 60;
- iLongtitudeD = iLongtitudeD + 1;
- }
- xd.Text = iLongtitudeD.ToString();
- xf.Text = iLongtitudeM.ToString();
- xm.Text = Math.Round(dLongtitudeS, 1).ToString();
- GetDMS(dy,false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
- if (dLatitudeS >= 60)
- {
- dLatitudeS = dLatitudeS - 60;
- iLatitudeM = iLatitudeM + 1;
- }
- if (iLatitudeM >= 60)
- {
- iLatitudeM = iLatitudeM - 60;
- iLatitudeD = iLatitudeD + 1;
- }
- yd.Text = iLatitudeD.ToString();
- yf.Text = iLatitudeM.ToString();
- ym.Text = Math.Round(dLatitudeS, 1).ToString();
-
- #region 计算投影坐标的经纬度范围用
- CentralMeridian = projectionCoordSystem.GetCentralMeridian(true);
- int TempInt = Convert.ToInt32(Math.Round(CentralMeridian, 0) + 3) % 6;
- if (TempInt != 0)
- {
- ChangeExtent = 3;
- }
- else
- {
- TempInt = Convert.ToInt32(Math.Round(CentralMeridian, 0) + 3) / 6;
- if (TempInt > 23 || TempInt < 13)
- {
- ChangeExtent = 3;
- }
- else
- {
- ChangeExtent = 6;
- }
- }
- GeoXMax = Math.Round(CentralMeridian, 0) + ChangeExtent * 0.5;
- double TempYA = dy;
- IPoint TempPointA = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- TempPointA.PutCoords(GeoXMax, TempYA);
- TempPointA.CoordinateSystem = pGeoCoordinateSystem;
- TempPointA.Project(projectionCoordSystem);
- ProXMax = TempPointA.X;
- GeoXMin = Math.Round(CentralMeridian, 0) - ChangeExtent * 0.5;
- double TempYB = dy;
- IPoint TempPointB = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- TempPointB.PutCoords(GeoXMin, TempYB);
- TempPointB.CoordinateSystem = pGeoCoordinateSystem;
- TempPointB.Project(projectionCoordSystem);
- ProXMin = TempPointB.X;
- #endregion
- }
- catch (Exception ex)
- {
- }
- }
-
-
-
- private void InitUnknowCoordinate()
- {
- IEnvelope pEnvelope;
- pEnvelope = curView.Extent;
- X = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 2);
- Y = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 2);
- this.Project_x.Text = X.ToString();
- this.Project_y.Text = Y.ToString();
- }
-
-
-
- private void InitGeographicCoordinate()
- {
- try
- {
- IEnvelope pEnvelope;
- pEnvelope = curView.Extent;
- double dx = Math.Round(pEnvelope.XMin + pEnvelope.Width / 2, 12);
- double dy = Math.Round(pEnvelope.YMin + pEnvelope.Height / 2, 12);
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- int iLatitudeD, iLatitudeM;
- double dLatitudeS;
- GetDMS(dx, true , out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- xd.Text = iLongtitudeD.ToString();
- xf.Text = iLongtitudeM.ToString();
- xm.Text = Math.Round(dLongtitudeS, 1).ToString();
- xod.Text = Math.Round(dx, 5).ToString();
- GetDMS(dy, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
- yd.Text = iLatitudeD.ToString();
- yf.Text = iLatitudeM.ToString();
- ym.Text = Math.Round(dLatitudeS, 1).ToString();
- yod.Text = Math.Round(dy, 5).ToString();
- if (coordinationsystem != null && selectCoordinateParams != null)
- {
- int diahao = MapSpatialReferenceUtils.GetDaihao(dx,
- selectCoordinateParams
- .DaiHaoType ==
- DaiHaoType.Degree3);
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.X = dx;
- point.Y = dy;
- point.CoordinateSystem = curView.FocusMap.SpatialReference;
- point.Project(coordinationsystem[diahao]);
-
- Project_x.Text = Math.Round(point.X, 2).ToString();
- Project_y.Text = Math.Round(point.Y, 2).ToString();
- }
- }
- catch (Exception ex)
- {
- }
- }
- #endregion
- public CoreUI.Control.IUserControl curControl
- {
- get { return null; }
- }
- public List<IElement> Elements { get { return LstElements; } }
- private void barEditItem1_EditValueChanged(object sender, EventArgs e)
- {
-
-
-
-
-
-
-
-
- }
- private double ConvertPixelsToAVUnits(IActiveView pAv, long lTolerance)
- {
- if (pAv == null) return 5;
- IDisplayTransformation pTransformation;
- IScreenDisplay pScreenDisplay = pAv.ScreenDisplay;
- pTransformation = pScreenDisplay.DisplayTransformation;
- WKSPoint pOutPoint;
- TagPOINT pInPoint;
- pOutPoint.X = 0;
- pOutPoint.Y = 0;
- pInPoint.x = (int)lTolerance;
- pInPoint.y = (int)lTolerance;
- pTransformation.TransformCoords(ref pOutPoint, ref pInPoint, 1, 6);
- return pOutPoint.X;
- }
- #region 同步更新
- private void Project_x_EditValueChanged(object sender, EventArgs e)
- {
- try
- {
- if (!BoolProXInit)
- return;
- BoolProXInit = false;
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- pPoint.CoordinateSystem = projectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.Project(pGeoCoordinateSystem);
- double dx = pPoint.X;
- xod.EditValue = Math.Round(dx,5);
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- if (dLongtitudeS >= 60)
- {
- dLongtitudeS = dLongtitudeS - 60;
- iLongtitudeM = iLongtitudeM + 1;
- }
- if (iLongtitudeM >= 60)
- {
- iLongtitudeM = iLongtitudeM - 60;
- iLongtitudeD = iLongtitudeD + 1;
- }
- int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
- if (Convert.ToInt32(yd.Text) != iLongtitudeD)
- xd.Text = iLongtitudeD.ToString();
- if (Convert.ToInt32(yf.Text) != iLongtitudeM)
- xf.Text = iLongtitudeM.ToString();
- if (Convert.ToInt32(ym.Text) != iLongtitudeS)
- xm.Text = iLongtitudeS.ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
- {
- int diahao = int.Parse(Project_x.Text.Substring(0, 2));
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- point.CoordinateSystem = coordinationsystem[diahao];
- point.Project(curView.FocusMap.SpatialReference);
- double dx = point.X;
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- GetDMS(dx, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
-
- if (dLongtitudeS >= 60)
- {
- dLongtitudeS = dLongtitudeS - 60;
- iLongtitudeM = iLongtitudeM + 1;
- }
- if (iLongtitudeM >= 60)
- {
- iLongtitudeM = iLongtitudeM - 60;
- iLongtitudeD = iLongtitudeD + 1;
- }
- int iLongtitudeS = Convert.ToInt32(dLongtitudeS);
- if (Convert.ToInt32(yd.Text) != iLongtitudeD)
- xd.Text = iLongtitudeD.ToString();
- if (Convert.ToInt32(yf.Text) != iLongtitudeM)
- xf.Text = iLongtitudeM.ToString();
- if (Convert.ToInt32(ym.Text) != iLongtitudeS)
- xm.Text = iLongtitudeS.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void xd_EditValueChanged(object sender, EventArgs e)
- {
- try
- {
- if (!BoolGeoXInit)
- return;
- BoolGeoXInit = false;
- if (Convert.ToDouble(xm.Text) >= 60)
- {
- xm.Text = (Convert.ToDouble(xm.Text) - 60).ToString();
- xf.Text = (Convert.ToDouble(xf.Text) + 1).ToString();
- }
- if (Convert.ToDouble(xf.Text) >= 60)
- {
- xf.Text = (Convert.ToDouble(xf.Text) - 60).ToString();
- xd.Text = (Convert.ToDouble(xd.Text) + 1).ToString();
- }
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- double oldx = Convert.ToDouble(xm.Text);
- if (oldx >= 60)
- {
- xm.Text = (oldx%60).ToString();
- oldx = oldx - oldx%60;
- double addf = oldx/60;
- xf.Text = (Convert.ToDouble(xf.Text) + addf).ToString();
- }
- oldx = Convert.ToDouble(xf.Text);
- if (oldx >= 60)
- {
- xf.Text = (oldx%60).ToString();
- oldx = oldx - oldx%60;
- double addd = oldx/60;
- xd.Text = (Convert.ToDouble(xd.Text) + addd).ToString();
- }
- double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
- Convert.ToDouble(xm.Text) /3600;
- double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
- Convert.ToDouble(ym.Text) /3600;
- xod.Text = Math.Round(dLongitude, 5).ToString();
- yod.Text = Math.Round(dLatitude, 5).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.CoordinateSystem = pGeoCoordinateSystem;
- pPoint.Project(projectionCoordSystem);
- double dx = pPoint.X;
- if (dx != dLongitude)
- Project_x.Text = Math.Round(dx, 2).ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
- Convert.ToDouble(xm.Text) /3600;
- double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
- Convert.ToDouble(ym.Text) /3600;
- xod.Text = Math.Round(dLongitude, 5).ToString();
- yod.Text = Math.Round(dLatitude, 5).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
- selectCoordinateParams != null)
- {
- int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
- selectCoordinateParams
- .DaiHaoType ==
- DaiHaoType.Degree3);
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.X = dLongitude;
- point.Y = dLatitude;
- point.CoordinateSystem = curView.FocusMap.SpatialReference;
- point.Project(coordinationsystem[diahao]);
-
- Project_x.Text = Math.Round(point.X, 2).ToString();
- Project_y.Text = Math.Round(point.Y, 2).ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void Project_y_EditValueChanged(object sender, EventArgs e)
- {
- try{
- if (!BoolProYInit)
- return;
- BoolProYInit = false;
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem )
- {
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- pPoint.CoordinateSystem = projectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.Project(pGeoCoordinateSystem);
- double dy = pPoint.Y;
- yod.Text = Math.Round(dy, 5).ToString();
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- if (dLongtitudeS >= 60)
- {
- dLongtitudeS = dLongtitudeS - 60;
- iLongtitudeM = iLongtitudeM + 1;
- }
- if (iLongtitudeM >= 60)
- {
- iLongtitudeM = iLongtitudeM - 60;
- iLongtitudeD = iLongtitudeD + 1;
- }
- if (Convert.ToInt32(yd.Text) != iLongtitudeD)
- yd.Text = iLongtitudeD.ToString();
- if (Convert.ToInt32(yf.Text) != iLongtitudeM)
- yf.Text = iLongtitudeM.ToString();
- if (Convert.ToDouble(ym.Text) != Math.Round(dLongtitudeS, 1))
- ym.Text = Math.Round(dLongtitudeS, 1).ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) / 60 + Convert.ToDouble(xm.Text) / 3600;
-
- double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) / 60 + Convert.ToDouble(ym.Text) / 3600;
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
- {
- int diahao = int.Parse(Project_x.Text.Substring(0, 2));
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.PutCoords(Convert.ToDouble(Project_x.Text), Convert.ToDouble(Project_y.Text));
- point.CoordinateSystem = coordinationsystem[diahao];
- point.Project(curView.FocusMap.SpatialReference);
- double dy = point.Y;
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- GetDMS(dy, false, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- if (dLongtitudeS >= 60)
- {
- dLongtitudeS = dLongtitudeS - 60;
- iLongtitudeM = iLongtitudeM + 1;
- }
- if (iLongtitudeM >= 60)
- {
- iLongtitudeM = iLongtitudeM - 60;
- iLongtitudeD = iLongtitudeD + 1;
- }
- if (Convert.ToInt32(yd.Text) != iLongtitudeD)
- yd.Text = iLongtitudeD.ToString();
- if (Convert.ToInt32(yf.Text) != iLongtitudeM)
- yf.Text = iLongtitudeM.ToString();
- if (Convert.ToDouble(ym.Text) != Math.Round(dLongtitudeS, 1))
- ym.Text = Math.Round(dLongtitudeS, 1).ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void yd_EditValueChanged(object sender, EventArgs e)
- {
- try
- {
- if (!BoolGeoYInit)
- return;
- BoolGeoYInit = false;
- if (Convert.ToDouble(ym.Text) >= 60)
- {
- ym.Text = (Convert.ToDouble(ym.Text) - 60).ToString();
- yf.Text = (Convert.ToDouble(yf.Text) + 1).ToString();
- }
- if (Convert.ToDouble(yf.Text) >= 60)
- {
- yf.Text = (Convert.ToDouble(yf.Text) - 60).ToString();
- yd.Text = (Convert.ToDouble(yd.Text) + 1).ToString();
- }
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- double oldy = Convert.ToDouble(ym.Text);
- if (oldy >= 60)
- {
- ym.Text = (oldy%60).ToString();
- oldy = oldy - oldy%60;
- double addf = oldy/60;
- yf.Text = (Convert.ToDouble(yf.Text) + addf).ToString();
- }
- oldy = Convert.ToDouble(yf.Text);
- if (oldy >= 60)
- {
- yf.Text = (oldy%60).ToString();
- oldy = oldy - oldy%60;
- double addd = oldy/60;
- yd.Text = (Convert.ToDouble(yd.Text) + addd).ToString();
- }
- double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
- Convert.ToDouble(xm.Text) /3600;
- double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
- Convert.ToDouble(ym.Text) /3600;
- xod.Text = Math.Round(dLongitude, 5).ToString();
- yod.Text = Math.Round(dLatitude, 5).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.CoordinateSystem = pGeoCoordinateSystem;
- pPoint.Project(projectionCoordSystem);
- double dy = pPoint.Y;
- if (dy != dLatitude)
- Project_y.Text = Math.Round(dy, 2).ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- double dLongitude = Convert.ToDouble(xd.Text) + Convert.ToDouble(xf.Text) /60 +
- Convert.ToDouble(xm.Text) /3600;
- double dLatitude = Convert.ToDouble(yd.Text) + Convert.ToDouble(yf.Text) /60 +
- Convert.ToDouble(ym.Text) /3600;
- xod.Text = Math.Round(dLongitude, 5).ToString();
- yod.Text = Math.Round(dLatitude, 5).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null &&
- selectCoordinateParams != null)
- {
- int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
- selectCoordinateParams
- .DaiHaoType ==
- DaiHaoType.Degree3);
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.X = dLongitude;
- point.Y = dLatitude;
- point.CoordinateSystem = curView.FocusMap.SpatialReference;
- point.Project(coordinationsystem[diahao]);
- Project_x.Text = Math.Round(point.X, 2).ToString();
- Project_y.Text = Math.Round(point.Y, 2).ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void xod_EditValueChanged(object sender, EventArgs e)
- {
- try
- {
- if (!BoolGeoXInit)
- return;
- BoolGeoXInit = false;
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- double dLongitude = Convert.ToDouble(xod.Text);
- double dLatitude = Convert.ToDouble(yod.Text);
- GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- xd.Text = iLongtitudeD.ToString();
- xf.Text = iLongtitudeM.ToString();
- xm.Text = Math.Round(dLongtitudeS, 1).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.CoordinateSystem = pGeoCoordinateSystem;
- pPoint.Project(projectionCoordSystem);
- double dx = pPoint.X;
- if (dx != dLongitude)
- Project_x.Text = Math.Round(dx, 2).ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- int iLongtitudeD, iLongtitudeM;
- double dLongtitudeS;
- double dLongitude = Convert.ToDouble(xod.Text);
- double dLatitude = Convert.ToDouble(yod.Text);
- GetDMS(dLongitude, true, out iLongtitudeD, out iLongtitudeM, out dLongtitudeS);
- xd.Text = iLongtitudeD.ToString();
- xf.Text = iLongtitudeM.ToString();
- xm.Text = Math.Round(dLongtitudeS, 1).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
- {
- int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
- selectCoordinateParams
- .DaiHaoType ==
- DaiHaoType.Degree3);
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.X = dLongitude;
- point.Y = dLatitude;
- point.CoordinateSystem = curView.FocusMap.SpatialReference;
- point.Project(coordinationsystem[diahao]);
-
- Project_x.Text = Math.Round(point.X, 2).ToString();
- Project_y.Text = Math.Round(point.Y, 2).ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void yod_EditValueChanged(object sender, EventArgs e)
- {
- try
- {
- if (!BoolGeoYInit)
- return;
- BoolGeoYInit = false;
- if (curView.FocusMap.SpatialReference is IProjectionCoordSystem)
- {
- int iLatitudeD, iLatitudeM;
- double dLatitudeS;
- double dLongitude = Convert.ToDouble(xod.Text);
- double dLatitude = Convert.ToDouble(yod.Text);
- GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
- yd.Text = iLatitudeD.ToString();
- yf.Text = iLatitudeM.ToString();
- ym.Text = Math.Round(dLatitudeS, 1).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- IProjectionCoordSystem projectionCoordSystem =
- curView.FocusMap.SpatialReference as IProjectionCoordSystem;
- IGeoCoordinateSystem pGeoCoordinateSystem = projectionCoordSystem.GeographicCoordinateSystem;
- pPoint.CoordinateSystem = pGeoCoordinateSystem;
- pPoint.Project(projectionCoordSystem);
- double dy = pPoint.Y;
- if (dy != dLatitude)
- Project_y.Text = Math.Round(dy, 2).ToString();
- }
- else
- {
- if (selectCoordinateParams == null)
- return;
- int iLatitudeD, iLatitudeM;
- double dLatitudeS;
- double dLongitude = Convert.ToDouble(xod.Text);
- double dLatitude = Convert.ToDouble(yod.Text);
- GetDMS(dLatitude, false, out iLatitudeD, out iLatitudeM, out dLatitudeS);
- yd.Text = iLatitudeD.ToString();
- yf.Text = iLatitudeM.ToString();
- ym.Text = Math.Round(dLatitudeS, 1).ToString();
- IPoint pPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pPoint.PutCoords(dLongitude, dLatitude);
- if (curView.FocusMap.SpatialReference is IGeoCoordinateSystem && coordinationsystem != null && selectCoordinateParams != null)
- {
- int diahao = MapSpatialReferenceUtils.GetDaihao(dLongitude,
- selectCoordinateParams
- .DaiHaoType ==
- DaiHaoType.Degree3);
- selectCoordinateParams.DaiHao = diahao;
- if (!coordinationsystem.ContainsKey(diahao))
- {
- ICoordinateSystem coordiante =
- SpatialReferenceUtils.GetSelectSpatialReference(curView.FocusMap.SpatialReference,
- selectCoordinateParams);
- coordinationsystem.Add(diahao, coordiante);
- }
- IPoint point = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- point.X = dLongitude;
- point.Y = dLatitude;
- point.CoordinateSystem = curView.FocusMap.SpatialReference;
- point.Project(coordinationsystem[diahao]);
- Project_x.Text = Math.Round(point.X, 2).ToString();
- Project_y.Text = Math.Round(point.Y, 2).ToString();
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void xd_KeyPress(object sender, KeyPressEventArgs e)
- {
- BoolGeoXInit = true;
- BoolGeoYInit = true;
- }
- private void xd_Click(object sender, EventArgs e)
- {
- BoolGeoXInit = true;
- BoolGeoYInit = true;
- }
- #endregion
- public CoreUI.Control.IComboBox cmbTFType
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- private void Project_x_Click(object sender, EventArgs e)
- {
- BoolProXInit = true;
- }
- private void Project_x_KeyPress(object sender, KeyPressEventArgs e)
- {
- BoolProXInit = true;
- }
- private void Project_y_Click(object sender, EventArgs e)
- {
- BoolProYInit = true;
- }
- private void Project_y_KeyPress(object sender, KeyPressEventArgs e)
- {
- BoolProYInit = true;
- }
- }
- }
|