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 GetZPrecisionString( [NotNull] ISpatialReference spatialReference) { if (!spatialReference.HasZPrecision()) { return(LocalizableStrings.QaSchemaSpatialReference_NotDefined); } double zmin; double zmax; spatialReference.GetZDomain(out zmin, out zmax); var resolution = (ISpatialReferenceResolution)spatialReference; double zResolution = resolution.get_ZResolution(true); return(string.Format(LocalizableStrings.QaSchemaSpatialReference_ZPrecision, zmin, zmax, zResolution)); }
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)); }
/// <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); }
private void method_1(IName iname_2, string string_1) { try { double num = 1000.0; IDataset dataset = iname_2.Open() as IDataset; ISpatialReference spatialReference = ((IGeoDataset)dataset).SpatialReference; (this.ispatialReference_0 as IControlPrecision2).IsHighPrecision = (spatialReference as IControlPrecision2).IsHighPrecision; if (spatialReference.HasXYPrecision()) { double num2; double num3; double num4; double num5; spatialReference.GetDomain(out num2, out num3, out num4, out num5); new PointClass(); if (!(spatialReference is IUnknownCoordinateSystem)) { IEnvelope extent; if (spatialReference is IProjectedCoordinateSystem) { extent = ((IGeoDataset)dataset).Extent; extent.PutCoords(num2, num4, num3, num5); extent.Project(this.ispatialReference_0); if (!extent.IsEmpty) { this.ispatialReference_0.SetDomain(extent.XMin, extent.XMax, extent.YMin, extent.YMax); num = extent.Width / 2.0; } } else if (spatialReference is IGeographicCoordinateSystem) { extent = ((IGeoDataset)dataset).Extent; extent.Project(this.ispatialReference_0); if (!extent.IsEmpty) { this.ispatialReference_0.SetDomain(extent.XMin, extent.XMax, extent.YMin, extent.YMax); num = extent.Width / 2.0; } } } } if (spatialReference.HasZPrecision()) { double num6; double num7; spatialReference.GetZDomain(out num6, out num7); this.ispatialReference_0.SetZDomain(num6, num7); } if (spatialReference.HasMPrecision()) { double num8; double num9; spatialReference.GetZDomain(out num8, out num9); this.ispatialReference_0.SetZDomain(num8, num9); } SpatialReferenctOperator.ChangeCoordinateSystem(this.iworkspace_0 as IGeodatabaseRelease, this.ispatialReference_0, false); this.int_2 = this.int_3; this.progressBar1.Value = this.int_3; SRLibCommonFunc.m_pfrm = this; if (dataset is IFeatureClass) { if (this.iname_0 is IFeatureDatasetName) { SRLibCommonFunc.Project((IFeatureClass)dataset, this.ispatialReference_0, this.iname_0 as IFeatureDatasetName, string_1, num); } else { SRLibCommonFunc.Project((IFeatureClass)dataset, this.ispatialReference_0, this.iworkspace_0, string_1, num); } } else if (dataset is IFeatureDataset) { SRLibCommonFunc.Project((IFeatureDataset)dataset, this.ispatialReference_0, this.iworkspace_0, string_1); } dataset = null; } catch (Exception exception) { MessageBox.Show("无法对" + (iname_2 as IDatasetName).Name + "作变换,请查看错误日志文件!"); Logger.Current.Error("", exception, ""); } }
private void btnOK_Click(object sender, EventArgs e) { if ((this.string_0 != null) && (this.string_0.Length != 0)) { if (this.bool_0) { MessageBox.Show("输出要素类已存在,请重新指定输出要素类名!"); } else if (this.ispatialReference_0 == null) { MessageBox.Show("请输入投影坐标系!"); } else if (this.ispatialReference_0 is IGeographicCoordinateSystem) { MessageBox.Show("请输入投影坐标系!"); } else if (this.ispatialReference_0 is IUnknownCoordinateSystem) { MessageBox.Show("请输入投影坐标系!"); } else { double num = 1000.0; this.string_0 = System.IO.Path.GetFileName(this.txtOutFeat.Text); ISpatialReference spatialReference = ((IGeoDataset)this.idataset_0).SpatialReference; (this.ispatialReference_0 as IControlPrecision2).IsHighPrecision = (spatialReference as IControlPrecision2).IsHighPrecision; if (spatialReference.HasXYPrecision()) { double num2; double num3; double num4; double num5; spatialReference.GetDomain(out num2, out num3, out num4, out num5); new PointClass(); if (!(spatialReference is IUnknownCoordinateSystem)) { IEnvelope extent; if (spatialReference is IProjectedCoordinateSystem) { extent = ((IGeoDataset)this.idataset_0).Extent; extent.PutCoords(num2, num4, num3, num5); extent.Project(this.ispatialReference_0); if (!extent.IsEmpty) { this.ispatialReference_0.SetDomain(extent.XMin, extent.XMax, extent.YMin, extent.YMax); num = extent.Width / 2.0; } } else if (spatialReference is IGeographicCoordinateSystem) { extent = ((IGeoDataset)this.idataset_0).Extent; extent.Project(this.ispatialReference_0); if (!extent.IsEmpty) { this.ispatialReference_0.SetDomain(extent.XMin, extent.XMax, extent.YMin, extent.YMax); num = extent.Width / 2.0; } } } } if (spatialReference.HasZPrecision()) { double num6; double num7; spatialReference.GetZDomain(out num6, out num7); this.ispatialReference_0.SetZDomain(num6, num7); } if (spatialReference.HasMPrecision()) { double num8; double num9; spatialReference.GetZDomain(out num8, out num9); this.ispatialReference_0.SetZDomain(num8, num9); } SpatialReferenctOperator.ChangeCoordinateSystem(this.iworkspace_0 as IGeodatabaseRelease, this.ispatialReference_0, false); this.progressBar1.Visible = true; this.int_2 = this.int_3; this.progressBar1.Value = this.int_3; SRLibCommonFunc.m_pfrm = this; if (this.idataset_0 is IFeatureClass) { SRLibCommonFunc.Project((IFeatureClass)this.idataset_0, this.ispatialReference_0, this.iworkspace_0, this.string_0, num); } else if (this.idataset_0 is IFeatureDataset) { SRLibCommonFunc.Project((IFeatureDataset)this.idataset_0, this.ispatialReference_0, this.iworkspace_0, this.string_0); } this.progressBar1.Visible = false; this.string_0 = ""; this.idataset_0 = null; this.iworkspace_0 = null; this.txtInputFeat.Text = ""; this.txtOutFeat.Text = ""; } } }
private static bool GetCoincident([NotNull] SegmentProxy segment, [NotNull] SegmentProxy hull, bool is3D, out NearSegment hullStartNear, out NearSegment hullEndNear) { hullStartNear = NearSegment.NotNear; // TODO hullEndNear = NearSegment.NotNear; // TODO IPolyline segLine = segment.GetPolyline(false); IPolyline hullLine = hull.GetPolyline(false); if (!((IRelationalOperator)segLine).Equals(hullLine)) { return(false); } var coincident = true; Pnt segmentStart = segment.GetStart(is3D); Pnt segmentEnd = segment.GetEnd(is3D); Pnt hullStart = hull.GetStart(is3D); Pnt hullEnd = hull.GetEnd(is3D); double distFromSegFromHull; { double dx = segmentStart.X - hullStart.X; double dy = segmentStart.Y - hullStart.Y; distFromSegFromHull = dx * dx + dy * dy; } double distFromSegToHull; { double dx = segmentStart.X - hullEnd.X; double dy = segmentStart.Y - hullEnd.Y; distFromSegToHull = dx * dx + dy * dy; } bool isInverse = (distFromSegFromHull > distFromSegToHull); Pnt hullMatchSegFrom; Pnt hullMatchSegTo; if (!isInverse) { hullMatchSegFrom = hullStart; hullMatchSegTo = hullEnd; } else { hullMatchSegFrom = hullEnd; hullMatchSegTo = hullStart; } if (is3D) { double zPrecision = 0; ISpatialReference spatialReference = segment.SpatialReference; if (spatialReference != null && spatialReference.HasZPrecision()) { double falseZ; double zUnits; spatialReference.GetZFalseOriginAndUnits(out falseZ, out zUnits); zPrecision = 1 / zUnits; } if (Math.Abs(hullMatchSegFrom[2] - segmentStart[2]) > zPrecision || Math.Abs(hullMatchSegTo[2] - segmentStart[2]) > zPrecision) { coincident = false; } } if (coincident) { if (!isInverse) { hullStartNear = NearSegment.NearStart; hullEndNear = NearSegment.NearEnd; } else { hullStartNear = NearSegment.NearEnd; hullEndNear = NearSegment.NearStart; } } return(coincident); }