public string GetDomainInfo(ISpatialReference ispatialReference_1) { double num5; double num6; string str = ""; if (ispatialReference_1.HasXYPrecision()) { double num; double num2; double num3; double num4; ispatialReference_1.GetDomain(out num, out num2, out num3, out num4); str = ((((str + "X/Y Domain: \r\n") + " Min X:" + num.ToString("#.######") + "\r\n") + " Min Y:" + num3.ToString("#.######") + "\r\n") + " Max X:" + num2.ToString("#.######") + "\r\n") + " Max Y:" + num4.ToString("#.######") + "\r\n"; num5 = ((num2 - num) > (num4 - num3)) ? (num2 - num) : (num4 - num3); num6 = 2147483645.0 / num5; str = str + " Scale:" + num6.ToString("#.######") + "\r\n"; } if (ispatialReference_1.HasZPrecision()) { double num7; double num8; str = str + "\r\n"; ispatialReference_1.GetZDomain(out num7, out num8); str = ((str + "Z Domain: \r\n") + " Min :" + num7.ToString("#.######") + "\r\n") + " Max :" + num8.ToString("#.######") + "\r\n"; num5 = num8 - num7; num6 = 2147483645.0 / num5; str = str + " Scale:" + num6.ToString("#.######") + "\r\n"; } if (ispatialReference_1.HasMPrecision()) { double num9; double num10; str = str + "\r\n"; ispatialReference_1.GetMDomain(out num9, out num10); str = ((str + "M Domain: \r\n") + " Min :" + num9.ToString("#.######") + "\r\n") + " Max :" + num10.ToString("#.######") + "\r\n"; num5 = num10 - num9; str = str + " Scale:" + ((2147483645.0 / num5)).ToString("#.######") + "\r\n"; } return(str); }
private static string GetMPrecisionString( [NotNull] ISpatialReference spatialReference) { if (!spatialReference.HasZPrecision()) { return(LocalizableStrings.QaSchemaSpatialReference_NotDefined); } double mmin; double mmax; spatialReference.GetMDomain(out mmin, out mmax); var resolution = (ISpatialReferenceResolution)spatialReference; double mResolution = resolution.MResolution; return(string.Format(LocalizableStrings.QaSchemaSpatialReference_MPrecision, mmin, mmax, mResolution)); }
public static string FormatSpatialReference(ISpatialReference sr) { try { if (sr == null) { return ""; } StringBuilder builder = new StringBuilder(); if (sr is UnknownCoordinateSystemClass) { builder.Append("UnknownCoordinateSystem"); } else { if (sr.Name == "Unknown") { builder.Append("UnknownCoordinateSystem"); } else { IGeographicCoordinateSystem system2; if (sr is IProjectedCoordinateSystem) { Exception exception; IProjectedCoordinateSystem system = sr as IProjectedCoordinateSystem; builder.Append("投影坐标系:\n"); builder.Append(" Name:").Append(system.Name).Append("\n"); builder.Append(" Alias:").Append(system.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system.Remarks).Append("\n"); builder.Append("投影:").Append(system.Projection.Name).Append("\n"); builder.Append("投影参数:\n"); builder.Append(" False_Easting:").Append(system.FalseEasting).Append("\n"); builder.Append(" False_Northing:").Append(system.FalseNorthing).Append("\n"); builder.Append(" Central_Meridian:").Append(system.get_CentralMeridian(true)).Append("\n"); try { builder.Append(" Scale_Factor:").Append(system.ScaleFactor).Append("\n"); } catch { } builder.Append(" Latitude_Of_Origin:0\n"); builder.Append("Linear Unit:").Append(system.CoordinateUnit.Name).Append("(").Append(system.CoordinateUnit.MetersPerUnit).Append(")\n"); builder.Append("Geographic Coordinate System:\n"); system2 = system.GeographicCoordinateSystem; builder.Append(" Name:").Append(system2.Name).Append("\n"); builder.Append(" Alias:").Append(system2.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system2.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system2.Remarks).Append("\n"); builder.Append(" Angular Unit:").Append(system2.CoordinateUnit.Name).Append("(").Append(system2.CoordinateUnit.RadiansPerUnit).Append(")\n"); builder.Append(" Prime Meridian:").Append(system2.PrimeMeridian.Name).Append("(").Append(system2.PrimeMeridian.Longitude).Append(")\n"); builder.Append(" Datum:").Append(system2.Datum.Name).Append("\n"); builder.Append(" Spheroid:").Append(system2.Datum.Spheroid.Name).Append("\n"); builder.Append(" Semimajor Axis:").Append(system2.Datum.Spheroid.SemiMajorAxis).Append("\n"); builder.Append(" Semiminor Axis:").Append(system2.Datum.Spheroid.SemiMinorAxis).Append("\n"); builder.Append(" Inverse Flattening:").Append((double)(1.0 / system2.Datum.Spheroid.Flattening)).Append("\n"); builder.Append("X/Y Domain:\n"); try { double num = 0.0; double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; double num5 = 0.0; sr.GetDomain(out num, out num3, out num2, out num4); sr.GetFalseOriginAndUnits(out num, out num2, out num5); builder.Append(" Min X:").Append(num).Append("\n"); builder.Append(" Min Y:").Append(num2).Append("\n"); builder.Append(" Max X:").Append(num3).Append("\n"); builder.Append(" Max Y:").Append(num4).Append("\n"); builder.Append(" XYScale:").Append(num5).Append("\n"); builder.Append("\n"); } catch (Exception exception1) { exception = exception1; } builder.Append("Z Domain:\n"); try { double num6; double num7; double num8 = 0.0; sr.GetZDomain(out num6, out num7); sr.GetZFalseOriginAndUnits(out num6, out num8); builder.Append(" Min Z:").Append(num6).Append("\n"); builder.Append(" Max Z:").Append(num7).Append("\n"); builder.Append(" ZScale:").Append(num8).Append("\n"); builder.Append("\n"); } catch (Exception exception2) { exception = exception2; } try { double num9; double num10; builder.Append("M Domain:\n"); double num11 = 0.0; sr.GetMDomain(out num9, out num10); sr.GetMFalseOriginAndUnits(out num9, out num11); builder.Append(" Min M:").Append(num9).Append("\n"); builder.Append(" Max M:").Append(num10).Append("\n"); builder.Append(" MScale:").Append(num11).Append("\n"); } catch (Exception exception3) { exception = exception3; } } else if (sr is IGeographicCoordinateSystem) { builder.Append("Geographic Coordinate System:\n"); system2 = sr as IGeographicCoordinateSystem; builder.Append(" Name:").Append(system2.Name).Append("\n"); builder.Append(" Alias:").Append(system2.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system2.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system2.Remarks).Append("\n"); builder.Append(" Angular Unit:").Append(system2.CoordinateUnit.Name).Append("(").Append(system2.CoordinateUnit.RadiansPerUnit).Append(")\n"); builder.Append(" Prime Meridian:").Append(system2.PrimeMeridian.Name).Append("(").Append(system2.PrimeMeridian.Longitude).Append(")\n"); builder.Append(" Datum:").Append(system2.Datum.Name).Append("\n"); builder.Append(" Spheroid:").Append(system2.Datum.Spheroid.Name).Append("\n"); builder.Append(" Semimajor Axis:").Append(system2.Datum.Spheroid.SemiMajorAxis).Append("\n"); builder.Append(" Semiminor Axis:").Append(system2.Datum.Spheroid.SemiMinorAxis).Append("\n"); builder.Append(" Inverse Flattening:").Append((double)(1.0 / system2.Datum.Spheroid.Flattening)).Append("\n"); } } } return builder.ToString(); } catch (Exception ex) { return ""; } }
/// <summary> /// 以原工作空间为模板创建新的工作空间 /// </summary> private void CreatWorkspaceFromOrig() { WaitForm.SetCaption("正在创建新的工作空间...请稍后"); IFeatureClassContainer pFcContainer = null; IFeatureClass pFcTemp = null; IFeatureClass pNewFc = null; ISpatialReference pSr = null; ISpatialReference pSrTemp = null; IFields pflds = null; double dblXmin, dblXmax, dblYmin, dblYmax; double dblZmin, dblZmax, dblMmin, dblMmax; CreateWorkspaceDomains(m_pOrigWorkspace, m_pDestWorkspace); IFeatureWorkspace pFeaWorkspace = m_pDestWorkspace as IFeatureWorkspace; IEnumDataset enumDs = m_pOrigWorkspace.get_Datasets(esriDatasetType.esriDTAny); IDataset pDs = enumDs.Next(); while (pDs != null) { if (pDs.Type == esriDatasetType.esriDTFeatureDataset) { pSr = new UnknownCoordinateSystemClass(); pSrTemp = (pDs as IGeoDataset).SpatialReference; if (pSrTemp.HasXYPrecision()) { pSrTemp.GetDomain(out dblXmin, out dblXmax, out dblYmin, out dblYmax); pSr.SetDomain(dblXmin, dblXmax, dblYmin, dblYmax); } if (pSrTemp.HasZPrecision()) { pSrTemp.GetZDomain(out dblZmin, out dblZmax); pSr.SetZDomain(dblZmin, dblZmax); } if (pSrTemp.HasMPrecision()) { pSrTemp.GetMDomain(out dblMmin, out dblMmax); pSr.SetMDomain(dblMmin, dblMmax); } IFeatureDataset pFeaDs = pFeaWorkspace.CreateFeatureDataset(pDs.Name, pSr); pFcContainer = (IFeatureClassContainer)pDs; if (pFcContainer.ClassCount > 0) { for (int i = 0; i < pFcContainer.ClassCount; i++) { try { pFcTemp = pFcContainer.get_Class(i); pflds = CommonFunction.GetFieldsFormFeatureClass(pFcTemp); //若为注记 if (pFcTemp.FeatureType == esriFeatureType.esriFTAnnotation) { IFeatureWorkspaceAnno pFWSAno = pFeaWorkspace as IFeatureWorkspaceAnno; IAnnoClass pAnnoClass = pFcTemp.Extension as IAnnoClass; IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass(); pGLS.ReferenceScale = pAnnoClass.ReferenceScale; pGLS.Units = pAnnoClass.ReferenceScaleUnits; pNewFc = pFWSAno.CreateAnnotationClass((pFcTemp as IDataset).Name, pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.ShapeFieldName, "", pFeaDs, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true); (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName); } else//若为地理要素 { try { pNewFc = pFeaDs.CreateFeatureClass((pFcTemp as IDataset).Name, pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null); if (pFcTemp.AliasName == "图廓线") { int n = 0; } (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName); } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } } } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } } } } else if (pDs.Type == esriDatasetType.esriDTFeatureClass) { pFcTemp = (IFeatureClass)pDs; pflds = CommonFunction.GetFieldsFormFeatureClass(pFcTemp, pSr); try { pNewFc = pFeaWorkspace.CreateFeatureClass(pDs.Name, pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } } else if (pDs.Type == esriDatasetType.esriDTTable) { ITable pTable = (ITable)pDs; try { ITable pNewTable = pFeaWorkspace.CreateTable(pDs.Name, pTable.Fields, pTable.CLSID, pTable.EXTCLSID, null); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } } pDs = enumDs.Next(); } }
//** 功能描述: 通过一个字段集,创建另外一个字段集,直接添加传入的字段集中的所有字段的话 // 会产生高版本和低版本不兼容的问题, public static IFields GetFieldsByFields(IFields pFields, ref ISpatialReference pDesSpatialReference, Dictionary <string, string> pDicField) { //pDesSpatialReference = null; //pDicField = null; int i = 0; IField pField = default(IField); IFieldEdit pFieldEdit = default(IFieldEdit); IFieldsEdit pFieldsEdit = default(IFieldsEdit); IField pCreateField = default(IField); ISpatialReference pOriSpatialReference = default(ISpatialReference); IGeometryDef pGeometryDef = default(IGeometryDef); IGeometryDefEdit pGeometryDefEdit = default(IGeometryDefEdit); double ymin = 0; double xmin = 0; double xmax = 0; double ymax = 0; double mMin = 0; double zmin = 0; double zmax = 0; double mMax = 0; IEnvelope pEnvelop = default(IEnvelope); IGeometry pGeometry = default(IGeometry); IClone pClone = default(IClone); //标识该字段是否被添加 bool bIsAddField = false; //应该把OID字段添加进去,否则会产生错误 pFieldsEdit = new FieldsClass(); for (i = 0; i <= pFields.FieldCount - 1; i++) { pField = pFields.get_Field(i); if (pField.Editable | pField.Type == esriFieldType.esriFieldTypeOID | pField.Type == esriFieldType.esriFieldTypeGlobalID | pField.Type == esriFieldType.esriFieldTypeGUID) { pClone = (IClone)pField; pCreateField = (IField)pClone.Clone(); //如果更改字段名称:如果是OID字段的话,即便不在dic中也要进行添加 if ((pDicField != null)) { if (pDicField.ContainsKey(Strings.Trim(pField.Name))) { bIsAddField = true; //修改字段的名称 pFieldEdit = (IFieldEdit)pCreateField; pFieldEdit.Name_2 = pDicField[Strings.Trim(pField.Name)]; //需不需要把别名赋过去,根据需要再看吧,现在看的话应该不要赋过去,因此一般字段名和别名是一样的 //如果赋过去的话,显示的是原字段的别名,即不是用户想看到的字段名 //pFieldEdit.AliasName = pField.AliasName } else if (pField.Type == esriFieldType.esriFieldTypeOID | pField.Type == esriFieldType.esriFieldTypeGlobalID | pField.Type == esriFieldType.esriFieldTypeGUID) { bIsAddField = true; } else { bIsAddField = false; } } else { bIsAddField = true; } if (pField.Type == esriFieldType.esriFieldTypeGeometry) { pGeometryDef = pCreateField.GeometryDef; pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef; if ((pDesSpatialReference != null)) { pOriSpatialReference = pGeometryDef.SpatialReference; //从原来的空间参考中得到domain if (pOriSpatialReference.HasXYPrecision()) { pOriSpatialReference.GetDomain(out xmin, out xmax, out ymin, out ymax); } pEnvelop = new EnvelopeClass(); pEnvelop.PutCoords(xmin, ymin, xmax, ymax); pGeometry = pEnvelop; pGeometry.SpatialReference = pOriSpatialReference; pGeometry.Project(pDesSpatialReference); xmax = pEnvelop.XMax; xmin = pEnvelop.XMin; ymax = pEnvelop.YMax; ymin = pEnvelop.YMin; pDesSpatialReference.SetDomain(xmin, xmax, ymin, ymax); if (pOriSpatialReference.HasZPrecision()) { pOriSpatialReference.GetZDomain(out zmin, out zmax); pDesSpatialReference.SetZDomain(zmin, zmax); } if (pOriSpatialReference.HasMPrecision()) { pOriSpatialReference.GetMDomain(out mMin, out mMax); pDesSpatialReference.SetMDomain(mMin, mMax); } pGeometryDefEdit.SpatialReference_2 = pDesSpatialReference; } //修改grid的大小 if (pGeometryDef.GridCount != 0) { if (pGeometryDef.get_GridSize(0) < 100) { pGeometryDefEdit.set_GridSize(0, 100); } } bIsAddField = true; } if (bIsAddField == true) { pFieldsEdit.AddField(pCreateField); bIsAddField = false; } } } return(pFieldsEdit); }
public static string FormatSpatialReference(ISpatialReference sr) { try { if (sr == null) { return(""); } StringBuilder builder = new StringBuilder(); if (sr is UnknownCoordinateSystemClass) { builder.Append("UnknownCoordinateSystem"); } else { if (sr.Name == "Unknown") { builder.Append("UnknownCoordinateSystem"); } else { IGeographicCoordinateSystem system2; if (sr is IProjectedCoordinateSystem) { Exception exception; IProjectedCoordinateSystem system = sr as IProjectedCoordinateSystem; builder.Append("投影坐标系:\n"); builder.Append(" Name:").Append(system.Name).Append("\n"); builder.Append(" Alias:").Append(system.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system.Remarks).Append("\n"); builder.Append("投影:").Append(system.Projection.Name).Append("\n"); builder.Append("投影参数:\n"); builder.Append(" False_Easting:").Append(system.FalseEasting).Append("\n"); builder.Append(" False_Northing:").Append(system.FalseNorthing).Append("\n"); builder.Append(" Central_Meridian:").Append(system.get_CentralMeridian(true)).Append("\n"); try { builder.Append(" Scale_Factor:").Append(system.ScaleFactor).Append("\n"); } catch { } builder.Append(" Latitude_Of_Origin:0\n"); builder.Append("Linear Unit:").Append(system.CoordinateUnit.Name).Append("(").Append(system.CoordinateUnit.MetersPerUnit).Append(")\n"); builder.Append("Geographic Coordinate System:\n"); system2 = system.GeographicCoordinateSystem; builder.Append(" Name:").Append(system2.Name).Append("\n"); builder.Append(" Alias:").Append(system2.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system2.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system2.Remarks).Append("\n"); builder.Append(" Angular Unit:").Append(system2.CoordinateUnit.Name).Append("(").Append(system2.CoordinateUnit.RadiansPerUnit).Append(")\n"); builder.Append(" Prime Meridian:").Append(system2.PrimeMeridian.Name).Append("(").Append(system2.PrimeMeridian.Longitude).Append(")\n"); builder.Append(" Datum:").Append(system2.Datum.Name).Append("\n"); builder.Append(" Spheroid:").Append(system2.Datum.Spheroid.Name).Append("\n"); builder.Append(" Semimajor Axis:").Append(system2.Datum.Spheroid.SemiMajorAxis).Append("\n"); builder.Append(" Semiminor Axis:").Append(system2.Datum.Spheroid.SemiMinorAxis).Append("\n"); builder.Append(" Inverse Flattening:").Append((double)(1.0 / system2.Datum.Spheroid.Flattening)).Append("\n"); builder.Append("X/Y Domain:\n"); try { double num = 0.0; double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; double num5 = 0.0; sr.GetDomain(out num, out num3, out num2, out num4); sr.GetFalseOriginAndUnits(out num, out num2, out num5); builder.Append(" Min X:").Append(num).Append("\n"); builder.Append(" Min Y:").Append(num2).Append("\n"); builder.Append(" Max X:").Append(num3).Append("\n"); builder.Append(" Max Y:").Append(num4).Append("\n"); builder.Append(" XYScale:").Append(num5).Append("\n"); builder.Append("\n"); } catch (Exception exception1) { exception = exception1; } builder.Append("Z Domain:\n"); try { double num6; double num7; double num8 = 0.0; sr.GetZDomain(out num6, out num7); sr.GetZFalseOriginAndUnits(out num6, out num8); builder.Append(" Min Z:").Append(num6).Append("\n"); builder.Append(" Max Z:").Append(num7).Append("\n"); builder.Append(" ZScale:").Append(num8).Append("\n"); builder.Append("\n"); } catch (Exception exception2) { exception = exception2; } try { double num9; double num10; builder.Append("M Domain:\n"); double num11 = 0.0; sr.GetMDomain(out num9, out num10); sr.GetMFalseOriginAndUnits(out num9, out num11); builder.Append(" Min M:").Append(num9).Append("\n"); builder.Append(" Max M:").Append(num10).Append("\n"); builder.Append(" MScale:").Append(num11).Append("\n"); } catch (Exception exception3) { exception = exception3; } } else if (sr is IGeographicCoordinateSystem) { builder.Append("Geographic Coordinate System:\n"); system2 = sr as IGeographicCoordinateSystem; builder.Append(" Name:").Append(system2.Name).Append("\n"); builder.Append(" Alias:").Append(system2.Alias).Append("\n"); builder.Append(" Abbreviation:").Append(system2.Abbreviation).Append("\n"); builder.Append(" Remarks:").Append(system2.Remarks).Append("\n"); builder.Append(" Angular Unit:").Append(system2.CoordinateUnit.Name).Append("(").Append(system2.CoordinateUnit.RadiansPerUnit).Append(")\n"); builder.Append(" Prime Meridian:").Append(system2.PrimeMeridian.Name).Append("(").Append(system2.PrimeMeridian.Longitude).Append(")\n"); builder.Append(" Datum:").Append(system2.Datum.Name).Append("\n"); builder.Append(" Spheroid:").Append(system2.Datum.Spheroid.Name).Append("\n"); builder.Append(" Semimajor Axis:").Append(system2.Datum.Spheroid.SemiMajorAxis).Append("\n"); builder.Append(" Semiminor Axis:").Append(system2.Datum.Spheroid.SemiMinorAxis).Append("\n"); builder.Append(" Inverse Flattening:").Append((double)(1.0 / system2.Datum.Spheroid.Flattening)).Append("\n"); } } } return(builder.ToString()); } catch (Exception ex) { return(""); } }