年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
11 KiB

6 months ago
using DevExpress.XtraEditors;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Plugin.LayerProperty.View.UC_Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KGIS.Plugin.LayerProperty.Utils
{
public class Util
{
public static StringBuilder GetCoordinateSystemInfo(ISpatialReference spatialReference)
{
StringBuilder stringBuilder = new StringBuilder();
if (spatialReference is IGeographicCoordinateSystem)
{
StringBuilder geographicCoordinateSystemInfo = Util.GetGeographicCoordinateSystemInfo(spatialReference);
stringBuilder.Append(geographicCoordinateSystemInfo);
}
else
{
if (spatialReference is IProjectedCoordinateSystem)
{
StringBuilder projectedCoordinateSystemInfo = Util.GetProjectedCoordinateSystemInfo(spatialReference);
stringBuilder.Append(projectedCoordinateSystemInfo);
}
else
{
if (spatialReference is IUnknownCoordinateSystem)
{
stringBuilder.AppendLine("未知坐标系统");
}
else
{
if (spatialReference == null)
{
stringBuilder.AppendLine("无投影");
}
}
}
}
return stringBuilder;
}
private static StringBuilder GetProjectedCoordinateSystemInfo(ISpatialReference spatialReference)
{
StringBuilder stringBuilder = new StringBuilder();
try
{
if (spatialReference is IProjectedCoordinateSystem)
{
IProjectedCoordinateSystem projectedCoordinateSystem = spatialReference as IProjectedCoordinateSystem;
ILinearUnit coordinateUnit = projectedCoordinateSystem.CoordinateUnit;
string text = (coordinateUnit != null) ? coordinateUnit.Name : "未知";
stringBuilder.AppendLine("投影坐标系统名称:".PadRight(11) + projectedCoordinateSystem.Name);
stringBuilder.AppendLine("投影:".PadRight(17) + projectedCoordinateSystem.Projection.Name);
stringBuilder.AppendLine("东偏:".PadRight(17) + projectedCoordinateSystem.FalseEasting.ToString());
stringBuilder.AppendLine("北偏:".PadRight(17) + projectedCoordinateSystem.FalseNorthing.ToString());
stringBuilder.AppendLine("缩放因子:".PadRight(15) + projectedCoordinateSystem.ScaleFactor.ToString());
try
{
stringBuilder.AppendLine("原点纬度:".PadRight(15) + projectedCoordinateSystem.LongitudeOfOrigin.ToString());
}
catch
{
}
stringBuilder.AppendLine(string.Concat(new object[]
{
"直线单位:".PadRight(15),
text,
"(",
projectedCoordinateSystem.CoordinateUnit.MetersPerUnit,
")"
}));
stringBuilder.AppendLine("");
stringBuilder.AppendLine(Util.GetGeographicCoordinateSystemInfo(projectedCoordinateSystem.GeographicCoordinateSystem).ToString());
}
}
catch
{
}
return stringBuilder;
}
private static StringBuilder GetGeographicCoordinateSystemInfo(ISpatialReference spatialReference)
{
StringBuilder stringBuilder = new StringBuilder();
try
{
if (spatialReference is IGeographicCoordinateSystem)
{
IGeographicCoordinateSystem geographicCoordinateSystem = spatialReference as IGeographicCoordinateSystem;
IAngularUnit coordinateUnit = geographicCoordinateSystem.CoordinateUnit;
string text = (coordinateUnit != null) ? coordinateUnit.Name : "未知";
stringBuilder.AppendLine("地理坐标系统名称:".PadRight(11) + geographicCoordinateSystem.Name);
stringBuilder.AppendLine(string.Concat(new object[]
{
"弧度单位:".PadRight(15),
text,
"(",
geographicCoordinateSystem.CoordinateUnit.RadiansPerUnit,
")"
}));
stringBuilder.AppendLine(string.Concat(new object[]
{
"本初子午线:".PadRight(14),
geographicCoordinateSystem.PrimeMeridian.Name,
"(",
geographicCoordinateSystem.PrimeMeridian.Longitude,
")"
}));
stringBuilder.AppendLine("水准面:".PadRight(16) + geographicCoordinateSystem.Datum.Name);
stringBuilder.AppendLine("椭球体:".PadRight(16) + geographicCoordinateSystem.Datum.Spheroid.Name);
stringBuilder.AppendLine("长半轴:".PadRight(16) + geographicCoordinateSystem.Datum.Spheroid.SemiMajorAxis.ToString());
stringBuilder.AppendLine("短半轴:".PadRight(16) + geographicCoordinateSystem.Datum.Spheroid.SemiMinorAxis.ToString());
stringBuilder.AppendLine("扁率倒数:".PadRight(15) + geographicCoordinateSystem.Datum.Spheroid.Flattening.ToString());
}
}
catch
{
}
return stringBuilder;
}
public static void InitFieldList(ref ComboBoxEdit cmb, IFields fields, string selected)
{
Util.InitFieldList(ref cmb, fields, selected, false, false, false, false);
}
public static void InitFieldList(ref ComboBoxEdit cmb, IFields fields, string selected, bool haveNone)
{
Util.InitFieldList(ref cmb, fields, selected, haveNone, false, false, false);
}
public static void InitFieldList(ref ComboBoxEdit cmb, IFields fields, string selected, bool haveNone, bool isNumberOnly)
{
Util.InitFieldList(ref cmb, fields, selected, haveNone, isNumberOnly, false, false);
}
public static void InitFieldList(ref ComboBoxEdit cmb, IFields fields, string selected, bool haveNone, bool isNumberOnly, bool useAlias)
{
Util.InitFieldList(ref cmb, fields, selected, haveNone, isNumberOnly, useAlias, true);
}
public static void InitFieldList(ref ComboBoxEdit cmb, IFields fields, string selected, bool haveNone, bool isNumberOnly, bool useAlias, bool hasObjID)
{
try
{
cmb.Properties.Items.Clear();
if (fields != null)
{
ItemInfo<IField, string> itemInfo = null;
IList<ItemInfo<IField, string>> list = new List<ItemInfo<IField, string>>();
if (haveNone)
{
itemInfo = new ItemInfo<IField, string>(null, "<none>");
list.Add(itemInfo);
}
int i = 0;
while (i < fields.FieldCount)
{
IField field = fields.get_Field(i);
ItemInfo<IField, string> itemInfo2 = null;
if (field.Type == esriFieldType.esriFieldTypeBlob || field.Type == esriFieldType.esriFieldTypeGeometry || field.Type == esriFieldType.esriFieldTypeRaster || field.Type == esriFieldType.esriFieldTypeXML)
{
goto IL_103;
}
if ((!isNumberOnly || field.Type == esriFieldType.esriFieldTypeDouble || field.Type == esriFieldType.esriFieldTypeInteger || field.Type == esriFieldType.esriFieldTypeSingle || field.Type == esriFieldType.esriFieldTypeSmallInteger) && (hasObjID || field.Type != esriFieldType.esriFieldTypeOID))
{
if (useAlias)
{
itemInfo2 = new ItemInfo<IField, string>(field, (field.AliasName == "") ? field.Name : field.AliasName);
}
else
{
itemInfo2 = new ItemInfo<IField, string>(field, field.Name);
}
if (itemInfo2 != null)
{
list.Add(itemInfo2);
goto IL_103;
}
goto IL_103;
}
IL_136:
i++;
continue;
IL_103:
if (field.Name.ToUpper() == selected.ToUpper() || field.AliasName.ToUpper() == selected.ToUpper())
{
itemInfo = itemInfo2;
goto IL_136;
}
goto IL_136;
}
DevExpressControlInitList<IField, string>.InitComboBoxEdit(ref cmb, list, itemInfo);
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public static List<string> GetUniqueValuesManyFields(List<IField> fieldNames, ICursor cursor)
{
List<string> list = new List<string>();
if (cursor == null)
{
return list;
}
string text = "";
for (IRow row = cursor.NextRow(); row != null; row = cursor.NextRow())
{
text = "";
foreach (IField current in fieldNames)
{
object obj = row.get_Value(row.Fields.FindField(current.Name));
if (obj == null)
{
if (text == "")
{
text = "<null>";
}
else
{
text += ", <null>";
}
}
else
{
if (obj.ToString() == "")
{
obj = "<null>";
}
if (text == "")
{
text = obj.ToString();
}
else
{
text = text + ", " + obj.ToString();
}
}
}
if (!list.Contains(text))
{
list.Add(text);
}
}
return list;
}
}
}