/// <summary> /// Gets a list of all geotransforms that use the provided spatial reference and unprojected /// WGS84 /// </summary> /// <param name="sr">spatial reference to look for</param> /// <returns>List of applicable IGeoTransformation objects</returns> public static List <IGeoTransformation> GetTransformations(ISpatialReference sr) { GeoTransformationComparer transComparer = new GeoTransformationComparer(); IClone wgs84 = (IClone)EsriUtilities.GetWGS84(); IClone targetDatum = (IClone)EsriUtilities.GetDatum(sr); List <IGeoTransformation> transList = new List <IGeoTransformation>(); ISpatialReferenceFactory2 srFactory = new SpatialReferenceEnvironmentClass(); ISet transSet = srFactory.GetPredefinedGeographicTransformations(); IGeoTransformation trans; ISpatialReference fromDatum; ISpatialReference toDatum; for (int i = 0; i < transSet.Count; i++) { trans = (IGeoTransformation)transSet.Next(); trans.GetSpatialReferences(out fromDatum, out toDatum); if (wgs84.IsEqual((IClone)fromDatum) || wgs84.IsEqual((IClone)toDatum)) { if (targetDatum.IsEqual((IClone)fromDatum) || targetDatum.IsEqual((IClone)toDatum)) { transList.Add(trans); } } } transList.Sort(transComparer.Compare); return(transList); }
/// <summary> /// Determines whether the specified objects are equal. /// </summary> /// <param name="x">The first object of type <see cref="IGeometry"/> to compare.</param> /// <param name="y">The second object of type <see cref="IGeometry"/> to compare.</param> /// <returns> /// true if the specified objects are equal; otherwise, false. /// </returns> public virtual bool Equals(IGeometry x, IGeometry y) { IClone xc = x as IClone; IClone yc = y as IClone; return((xc != null && yc != null) && xc.IsEqual(yc)); }
/// <summary> /// Determines whether the specified objects are equal. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// Returns a <see cref="bool" /> representing <c>true</c> if the specified objects are equal; otherwise, <c>false</c>. /// </returns> protected virtual bool AreEqual(object x, object y) { IClone xClone = x as IClone; IClone yClone = y as IClone; if (xClone != null && yClone != null) { return(xClone.IsEqual(yClone)); } return(Equals(x, y)); }
public static bool AdjustSpatialRef(IGeometry igeometry_0, ISpatialReference ispatialReference_0) { bool result = false; IClone clone = igeometry_0.SpatialReference as IClone; if (!(clone is IUnknownCoordinateSystem) && !clone.IsEqual(ispatialReference_0 as IClone)) { igeometry_0.Project(ispatialReference_0); result = true; } return(result); }
private bool IsGeometryEqual(IGeometry shape1, IGeometry shape2) { if ((shape1 == null) & (shape2 == null)) { return(true); } if ((shape1 == null) ^ (shape2 == null)) { return(false); } IClone clone = (IClone)shape1; IClone other = (IClone)shape2; return(clone.IsEqual(other)); }
public void InsertPointAtIntersection(ref IPolyline pPolyline, IGeometry pOther, double hmgetal) { bool SplitHappened = false; int newPartIndex = 0; int newSegmentIndex = 0; int index = 0; List <int> indices; IPoint Point = null; IClone pClone = pPolyline.SpatialReference as IClone; if (pClone.IsEqual(pOther.SpatialReference as IClone) == false) { pOther.Project(pPolyline.SpatialReference); } ITopologicalOperator pTopoOp = pOther as ITopologicalOperator; pTopoOp.Simplify(); pTopoOp = pPolyline as ITopologicalOperator; IGeometry pGeomResult = pTopoOp.Intersect(pOther, esriGeometryDimension.esriGeometry0Dimension); indices = new List <int>(); if ((pGeomResult is IPointCollection) && ((pGeomResult as IPointCollection).PointCount > 0)) { for (int i = 0; i < (pGeomResult as IPointCollection).PointCount; i++) { (pPolyline as IPolycurve2).SplitAtPoint((pGeomResult as IPointCollection).get_Point(i), true, false, out SplitHappened, out newPartIndex, out newSegmentIndex); //TODO Zet de measure op het ingevoegde punt, houdt rekening met partindex en segmentindex for (int j = 0; j < newPartIndex; j++) { index += ((pPolyline as IGeometryCollection).get_Geometry(j) as IPointCollection).PointCount; } index += newSegmentIndex; Point = (pPolyline as IPointCollection).get_Point(index); Point.M = hmgetal; (pPolyline as IPointCollection).UpdatePoint(index, Point); } } (pPolyline as ITopologicalOperator2).IsKnownSimple_2 = false; (pPolyline as IPolyline4).SimplifyEx(true); }
//判断两个几何形状是否相等 // Method returning if two shapes are equal to one another. private bool IsGeometryEqual(IGeometry shape1, IGeometry shape2) { if (shape1 == null && shape2 == null) { return(true); } else if (shape1 == null || shape2 == null) { return(false); } else { IClone clone1 = (IClone)shape1; IClone clone2 = (IClone)shape2; return(clone1.IsEqual(clone2)); } }
public bool IsEqualObjectProperties(IClone pOriginal, IClone pOther) { try { if (pOriginal == null) { return(false); } if (pOther == null) { return(false); } return(pOriginal.IsEqual(pOther)); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.SystemFun", "IsEqualObjectProperties", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
private bool method_4(object object_0, object object_1) { try { bool flag = false; bool flag2 = false; flag = object_0 is DBNull; flag2 = object_1 is DBNull; if (flag != flag2) { return(false); } if (flag && flag2) { return(true); } if ((object_0 is IClone) && (object_1 is IClone)) { IClone clone = object_0 as IClone; return(clone.IsEqual(object_1 as IClone)); } if (!(!(object_0 is IClone) || (object_1 is IClone))) { return(false); } if (!(!(object_1 is IClone) || (object_0 is IClone))) { return(false); } bool flag4 = false; if (object_0.ToString() == object_1.ToString()) { flag4 = true; } return(flag4); } catch { } return(false); }
// Returns true if Spatial Systems is equal (without precision) private bool IsSREqual(ISpatialReference objSR1, ISpatialReference objSR2) { IClone objSRClone1 = objSR1 as IClone; return objSRClone1.IsEqual((IClone)objSR2); }
/// <summary> /// 创建同位流模式分析结果要素 /// </summary> /// <param name="originFeatureClass">输出的矢量要素</param> /// <param name="originUIDField">区分要素的唯一字段名</param> /// <param name="patternTable">同位流模式表</param> /// <param name="out_path">输出要素的路径</param> /// <param name="out_name">输出要素的名称</param> /// <param name="outObjectClass">输出区域要素类</param> /// <param name="outFlowClass">输出流线要素类</param> public void CreatePatternFeatures(IFeatureClass originFeatureClass, string originUIDField, IFeatureClass destFeatureClass, string destUIDField, DataTable patternTable, string out_path, string out_name, ref IFeatureClass outObjectClass, ref IFeatureClass outFlowClass, ref string message) { string parent_path = System.IO.Path.GetDirectoryName(out_path); string featuredataset_name = ""; string extension = System.IO.Path.GetExtension(parent_path); if (extension == ".gdb" || extension == ".mdb") { featuredataset_name = System.IO.Path.GetFileName(out_path); out_path = parent_path; } var originSpatialRef = ((IGeoDataset)originFeatureClass).SpatialReference; var destSpatialRef = ((IGeoDataset)destFeatureClass).SpatialReference; IClone comparison = originSpatialRef as IClone; if (!comparison.IsEqual((IClone)destSpatialRef)) { message = "Different Spatial Reference in Origin and Destination FeatureClass."; return; } // 获取 UID字段-要素 字典 var originPolygonDict = GetUIDPolygonDict(originFeatureClass, originUIDField); Dictionary <string, IPolygon> destPolygonDict = null; if (originFeatureClass == destFeatureClass) { destPolygonDict = originPolygonDict; } else { destPolygonDict = GetUIDPolygonDict(destFeatureClass, destUIDField); } // 字段的最大长度 int d_length = patternTable.AsEnumerable().Max(r => ((string)r["Dests"]).Length); int o_length = patternTable.AsEnumerable().Max(r => ((string)r["Origins"]).Length); int max_length = d_length; if (o_length > d_length) { max_length = o_length; } var dataMangementTools = new DataManagementTools(); // 合并后的区域要素 outObjectClass = dataMangementTools.CreateFeatureClass( out_path, out_name + "_OBJ", featuredataset_name, originFeatureClass.ShapeType, originSpatialRef); // 同位流要素 outFlowClass = dataMangementTools.CreateFeatureClass( out_path, out_name + "_FLOW", featuredataset_name, esriGeometryType.esriGeometryPolyline, originSpatialRef); // 复制合并前要素的字段 var pID = dataMangementTools.AddField((ITable)outObjectClass, "PID", esriFieldType.esriFieldTypeSmallInteger, true); var pType = dataMangementTools.AddField((ITable)outObjectClass, "PTYPE", esriFieldType.esriFieldTypeString, true); var pGUID = dataMangementTools.AddField((ITable)outObjectClass, "PGUID", esriFieldType.esriFieldTypeString, true, max_length); var pGCount = dataMangementTools.AddField((ITable)outObjectClass, "PGCOUNT", esriFieldType.esriFieldTypeString, true, max_length); int pID_idx = outObjectClass.FindField(pID); int pType_idx = outObjectClass.FindField(pType); int pZUID_idx = outObjectClass.FindField(pGUID); int pZCount_idx = outObjectClass.FindField(pGCount); // 复制同位流字段 var flowFieldDict = dataMangementTools.CopyFields(patternTable, (ITable)outFlowClass, max_length); IFeatureBuffer outObjectBuffer = null; IFeatureCursor outObjectCursor = outObjectClass.Insert(true); IFeatureBuffer outFlowBuffer = null; IFeatureCursor outFlowCursor = outFlowClass.Insert(true); AddStepProgressor(patternTable.Rows.Count, "Creating spatiotemporal self-co-location flow features . . . "); for (int i = 0; i < patternTable.Rows.Count; i++) { if (!ContinueStepProgressor(new object[] { outObjectCursor, outFlowCursor })) { return; } var dataRow = patternTable.Rows[i]; var rowPID = (int)dataRow["PID"]; string[] originStrArr = ((string)dataRow["Origins"]).Split(';'); IPolygon originPolygon = DissolvePolygon(originSpatialRef, originPolygonDict, originStrArr); outObjectBuffer = outObjectClass.CreateFeatureBuffer(); outObjectBuffer.Shape = originPolygon; outObjectBuffer.Value[pID_idx] = rowPID; outObjectBuffer.Value[pType_idx] = "Origin"; outObjectBuffer.Value[pZUID_idx] = string.Join(";", originStrArr); outObjectBuffer.Value[pZCount_idx] = originStrArr.Length; outObjectCursor.InsertFeature(outObjectBuffer); IPoint originPoint = ((IArea)originPolygon).Centroid; string[] destStrArr = ((string)dataRow["Dests"]).Split(';'); IPolygon destPolygon = DissolvePolygon(destSpatialRef, destPolygonDict, destStrArr); outObjectBuffer = outObjectClass.CreateFeatureBuffer(); outObjectBuffer.Shape = destPolygon; outObjectBuffer.Value[pID_idx] = rowPID; outObjectBuffer.Value[pType_idx] = "Destination"; outObjectBuffer.Value[pZUID_idx] = string.Join(";", destStrArr); outObjectBuffer.Value[pZCount_idx] = destStrArr.Length; outObjectCursor.InsertFeature(outObjectBuffer); IPoint destPoint = ((IArea)destPolygon).Centroid; // 创建同位流要素 outFlowBuffer = outFlowClass.CreateFeatureBuffer(); outFlowBuffer.Shape = CreateCirculeArc(originPoint, destPoint, 0.3); foreach (var item in flowFieldDict) { outFlowBuffer.Value[item.Value] = dataRow[item.Key]; } outFlowCursor.InsertFeature(outFlowBuffer); } // for (int i = 0; i < patternTable.Rows.Count; i++) outObjectCursor.Flush(); outFlowCursor.Flush(); Marshal.ReleaseComObject(outObjectCursor); Marshal.ReleaseComObject(outFlowCursor); GC.Collect(); GC.WaitForPendingFinalizers(); }
static void Main(string[] args) { int numLines = 100; DateTime t1 = DateTime.Now; IList <IPolyline> lines = new List <IPolyline>(numLines); IList <object> serializedLines = new List <object>(numLines); IList <IPolyline> Deserializedlines = new List <IPolyline>(numLines); IEsriSerializer serializer = new EsriVariantSerializer(); Console.WriteLine(String.Format("Creating {0} lines", numLines)); for (int i = 0; i < numLines; i++) { lines.Add(CreatePl()); Console.CursorLeft = 0; Console.Write(i.ToString()); } TimeSpan ts = DateTime.Now.Subtract(t1); Console.WriteLine(); Console.WriteLine(String.Format("Lines construction duration = {0}. Press any key to serialize", ts)); t1 = DateTime.Now; int j = 0; foreach (IPolyline line in lines) { serializedLines.Add(serializer.Serialize(line)); Console.CursorLeft = 0; Console.Write(j.ToString()); j++; } ts = DateTime.Now.Subtract(t1); Console.WriteLine(); Console.WriteLine(String.Format("Serialization duration = {0}. Press any key to deserialize", ts)); t1 = DateTime.Now; j = 0; foreach (object o in serializedLines) { IPolyline l = (IPolyline)serializer.Deserialize(o); Deserializedlines.Add(l); Console.CursorLeft = 0; Console.Write(j.ToString()); j++; } ts = DateTime.Now.Subtract(t1); Console.WriteLine(); Console.WriteLine(String.Format("Deserialization duration = {0}. Press any key to compare", ts)); int difs = 0; for (int i = 0; i < numLines; i++) { IClone clone = (IClone)lines[i]; if (!clone.IsEqual((IClone)Deserializedlines[i])) { Console.WriteLine(String.Format("Lines are not equal. index = {0}", i)); difs++; } } Console.WriteLine(String.Format("Number of non-equal serializings {0}. Press any key to compare", difs)); Console.ReadLine(); }