123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using DevExpress.XtraEditors;
- using DevExpress.XtraGrid;
- using DevExpress.XtraGrid.Columns;
- using DevExpress.XtraGrid.Views.Grid;
- using DevExpress.XtraTreeList;
- using DevExpress.XtraTreeList.Columns;
- using Tofly.Core.Context.Support;
- using Tofly.GIS.CoordinateConvert;
- using Tofly.GIS.Geometry;
- using Tofly.GIS.SpatialReference;
- using Tofly.GIS.Util;
- namespace CoordinateConvert.Win
- {
- class CoordinateConvertCommon
- {
-
-
-
-
-
-
-
- public static void AddColumn<T>(T pControl, string[] sColumnNames, string[] sColumnCaption, bool[] bAllowEidt)
- {
- if (pControl is GridView)
- {
- AddColumnMethod(pControl, sColumnNames, sColumnCaption, bAllowEidt);
- }
- else if (pControl is GridControl)
- {
- AddColumnMethod((pControl as GridControl).MainView, sColumnNames, sColumnCaption, bAllowEidt);
- }
- }
-
-
-
-
-
-
-
- internal static void AddColumnMethod<T>(T pControl, string[] sColumnNames, string[] sColumnCaption, bool[] bAllowEidt)
- {
- if (pControl == null)
- throw new Exception("控件对象为空!");
- if (sColumnNames == null || sColumnNames.Length == 0)
- throw new Exception("字段名称为空!");
- if (sColumnCaption == null)
- sColumnCaption = sColumnNames;
- if (sColumnCaption.Length != sColumnNames.Length)
- throw new Exception("字段标题与字段名个数不一致!");
- if (bAllowEidt != null && bAllowEidt.Length != sColumnNames.Length)
- throw new Exception("字段是否可编辑设置与字段名个数不一致!");
- if (typeof(T) == typeof(GridView))
- {
- GridView pGridView = pControl as GridView;
- GridColumn gridColumn = null;
- for (int i = 0; i < sColumnNames.Length; i++)
- {
- gridColumn = pGridView.Columns.Add();
- gridColumn.Visible = true;
- gridColumn.Name = sColumnNames[i];
- gridColumn.Caption = sColumnCaption[i];
- gridColumn.FieldName = sColumnNames[i];
- if (bAllowEidt != null)
- {
- gridColumn.OptionsColumn.AllowEdit = bAllowEidt[i];
- }
- }
- }
- else if (typeof(T) == typeof(TreeList))
- {
- TreeList pTreeList = pControl as TreeList;
- TreeListColumn pTreeListColumn = null;
- for (int i = 0; i < sColumnNames.Length; i++)
- {
- pTreeListColumn = pTreeList.Columns.Add();
- pTreeListColumn.Visible = true;
- pTreeListColumn.Name = sColumnNames[i];
- pTreeListColumn.FieldName = sColumnNames[i];
- pTreeListColumn.Caption = sColumnCaption[i];
- if (bAllowEidt != null)
- {
- pTreeListColumn.OptionsColumn.AllowEdit = bAllowEidt[i];
- }
- }
- }
- }
-
-
-
-
-
-
- public static void HiddenColumn<T>(T pControl, string[] sColumnNames)
- {
- if (pControl is GridView)
- {
- HiddenColumnMethod(pControl, sColumnNames);
- }
- else if (pControl is GridControl)
- {
- HiddenColumnMethod((pControl as GridControl).MainView, sColumnNames);
- }
- }
-
-
-
-
-
-
- internal static void HiddenColumnMethod<T>(T pControl, string[] sColumnNames)
- {
- if (pControl == null)
- throw new Exception("控件对象为空!");
- if (sColumnNames == null || sColumnNames.Length == 0)
- throw new Exception("字段名称为空!");
- if (typeof(T) == typeof(GridView))
- {
- GridView pGridView = pControl as GridView;
- GridColumn pGridColumn = null;
- for (int i = 0; i < sColumnNames.Length; i++)
- {
- pGridColumn = pGridView.Columns.ColumnByFieldName(sColumnNames[i]);
- if (pGridColumn != null)
- {
- pGridColumn.Visible = false;
- }
- }
- }
- else if (typeof(T) == typeof(TreeList))
- {
- TreeList pTreeList = pControl as TreeList;
- TreeListColumn pTreeListColumn = null;
- for (int i = 0; i < sColumnNames.Length; i++)
- {
- pTreeListColumn = pTreeList.Columns.ColumnByFieldName(sColumnNames[i]);
- if (pTreeListColumn != null)
- {
- pTreeListColumn.Visible = false;
- }
- }
- }
- }
-
-
-
-
-
-
-
- public static DataTable CreateDataTable(string[] sColumnNames, string[] sColumnsAilas, Type[] tColumnTypes)
- {
- if (sColumnNames == null || sColumnNames.Length == 0) return null;
- if (sColumnsAilas == null || sColumnsAilas.Length != sColumnNames.Length) return null;
- if (tColumnTypes == null || tColumnTypes.Length != sColumnNames.Length) return null;
- DataTable dtResult = new DataTable();
- DataColumn dcNewColumn = null;
- if (sColumnsAilas == null) sColumnsAilas = sColumnNames;
- for (int i = 0; i < sColumnNames.Length; i++)
- {
- dcNewColumn = dtResult.Columns.Add();
- dcNewColumn.ColumnName = sColumnNames[i];
- dcNewColumn.Caption = sColumnsAilas[i];
- dcNewColumn.DataType = tColumnTypes[i];
- }
- return dtResult;
- }
-
-
-
-
-
- public static void AddItem(List<object> lstItems, ComboBoxEdit pComboBoxEdit)
- {
- if (lstItems == null || lstItems.Count == 0)
- throw new Exception("添加数据项为空!");
- if (pComboBoxEdit == null)
- throw new Exception("控件对象为空!");
- for (int i = 0; i < lstItems.Count; i++)
- {
- pComboBoxEdit.Properties.Items.Add(lstItems[i]);
- }
- }
-
-
-
-
-
-
- public static ICoordinateSystem GetMapFrameSpatailReference(double dX, int iZone, EnumConvertSpatialType pEnumOffsetType)
- {
- try
- {
- int iResulteZone = GetPositionZone(dX, iZone);
- switch (pEnumOffsetType)
- {
- case EnumConvertSpatialType.Bj54ToXa80:
- case EnumConvertSpatialType.Bj54ToWgs84:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("Beijing54 {0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_Beijing54());
- case EnumConvertSpatialType.Xa80ToBj54:
- case EnumConvertSpatialType.Xa80ToWgs84:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("Xian 80 {0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_XiAn80());
- case EnumConvertSpatialType.Wgs84ToXa80:
- case EnumConvertSpatialType.Wgs84ToBj54:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("WGS 84 {0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_WGS84());
- default:
- return null;
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
- public static ICoordinateSystem GetMapFrameSpatailReference2(double dX, int iZone, EnumConvertSpatialType pEnumOffsetType)
- {
- try
- {
- int iResulteZone = GetPositionZone(dX, iZone);
- switch (pEnumOffsetType)
- {
- case EnumConvertSpatialType.Bj54ToXa80:
- case EnumConvertSpatialType.Wgs84ToXa80:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("Xian 80{0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_XiAn80());
- case EnumConvertSpatialType.Xa80ToBj54:
- case EnumConvertSpatialType.Wgs84ToBj54:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("Beijing 54 {0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_Beijing54());
- case EnumConvertSpatialType.Bj54ToWgs84:
- case EnumConvertSpatialType.Xa80ToWgs84:
- return MapSpatialReferenceUtils.CreateProjectSR_GaussKruger
- (String.Format("WGS 84 {0} Zone", iZone), iResulteZone, true, true,
- MapSpatialReferenceUtils.CreateGSR_WGS84());
- default:
- return null;
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
-
-
-
-
-
- public static int GetPositionZone(double dX, int iZone)
- {
- int iResulteZone = 0;
- if ((dX % iZone) != 0)
- {
- int iTempMaxValue = Convert.ToInt32(Convert.ToDouble((dX / iZone)).ToString().Split('.')[0]);
- if (iTempMaxValue * iZone + (iZone / 2) < dX)
- {
- iResulteZone = iTempMaxValue + 1;
- }
- else
- {
- iResulteZone = iTempMaxValue;
- }
- }
- else
- {
- iResulteZone = Convert.ToInt32(dX / iZone);
- }
- return iResulteZone;
- }
-
-
-
-
-
- public static IEnvelope GetEnvelope(string sNewNumber)
- {
- IEnvelope pEnvelope = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- IPoint pLeftDown = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- double delx = 0;
- double dely = 0;
- GetScaleDelxy(sNewNumber[3], out delx, out dely);
- pLeftDown = GetPointFromMapFrame(sNewNumber);
- IPoint pLeftUp = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pLeftUp.X = pLeftDown.X;
- pLeftUp.Y = pLeftDown.Y + dely;
- pLeftUp.Z = 1;
- IPoint pRightUp = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pRightUp.X = pLeftDown.X + delx;
- pRightUp.Y = pLeftDown.Y + dely;
- pRightUp.Z = 1;
- IPoint pRightDown = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pRightDown.X = pLeftDown.X + delx;
- pRightDown.Y = pLeftDown.Y;
- pRightDown.Z = 1;
- pEnvelope.XMin = pLeftDown.X;
- pEnvelope.YMin = pLeftDown.Y;
- pEnvelope.XMax = pRightUp.X;
- pEnvelope.YMax = pRightUp.Y;
- return pEnvelope;
- }
-
-
-
-
-
- static void GetScaleDelxy(char sValue, out double delX, out double delY)
- {
- delX = 0;
- delY = 0;
- switch (sValue)
- {
- case 'B':
- delX = 3;
- delY = 2;
- break;
- case 'C':
- delX = 1.5;
- delY = 1;
- break;
- case 'D':
- delX = 0.5;
- delY = 1.0 / 3;
- break;
- case 'E':
- delX = 0.25;
- delY = 1.0 / 6;
- break;
- case 'F':
- delX = 0.125;
- delY = 5 / 60;
- break;
- case 'G':
- delX = 0.0625;
- delY = 0.125 / 3;
- break;
- case 'H':
- delX = 0.03125;
- delY = 0.125 / 6;
- break;
- default:
- break;
- }
- }
-
-
-
- public static IPoint GetPointFromMapFrame(string sNewNumber)
- {
-
- double delX = 0;
- double delY = 0;
-
- int iH = 0, iL = 0;
-
- int ih = 0, il = 0;
-
- if (sNewNumber.Length == 3)
- {
- delX = 6;
- delY = 4;
- }
- else
- {
-
- if (!int.TryParse(sNewNumber.Substring(4, 3), out ih)
- || !int.TryParse(sNewNumber.Substring(7, 3), out il))
- return null;
- }
- if (!int.TryParse(sNewNumber.Substring(1, 2), out iL))
- return null;
- iH = (int)sNewNumber[0] - (int)'A' + 1;
- GetScaleDelxy(sNewNumber[3], out delX, out delY);
-
- double x = (iL - 31) * 6 + (il - 1) * delX;
- double y = (iH - 1) * 4 + (4 / delY - ih) * delY;
- IPoint pResultPoint = ContextRegistry.GetContext().GetObject("GIS_Point") as IPoint;
- pResultPoint.PutCoords(x, y);
-
- pResultPoint.Z = 1;
- return pResultPoint;
- }
- }
- }
|