/// <summary> /// Considers the ShapeType and upgrades the extent class to accommodate M and Z. /// This is automatically called form the setter of ShapeType. /// </summary> public void UpgradeExtent() { if (_shapeType == ShapeType.MultiPointZ || _shapeType == ShapeType.PointZ || _shapeType == ShapeType.PolygonZ || _shapeType == ShapeType.PolyLineZ) { IExtentZ zTest = Extent as IExtentZ; if (zTest == null) { Extent ext = new ExtentMz(); if (_extent != null) { ext.CopyFrom(_extent); } _extent = ext; } // Already implements M and Z } else if (_shapeType == ShapeType.MultiPointM || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PolygonM || _shapeType == ShapeType.PolyLineM) { IExtentM mTest = Extent as IExtentM; if (mTest == null) { Extent ext = new ExtentMz(); if (_extent != null) { ext.CopyFrom(_extent); } _extent = ext; } // already at least implements M } // No upgrade necessary }
/// <summary> /// Calculates the intersection of this extent and the other extent. A result /// with a min greater than the max in either direction is considered invalid /// and represents no intersection. /// </summary> /// <param name="other">The other extent to intersect with.</param> /// <returns>The resulting intersection.</returns> public override Extent Intersection(Extent other) { IExtentZ zOther = other as IExtentZ; IExtentM mOther = other as IExtentM; Extent result = null; if (HasZ && zOther != null && other.HasZ) { ExtentMz zResult = new ExtentMz { MinZ = MinZ > zOther.MinZ ? MinZ : zOther.MinZ, MaxZ = MaxZ < zOther.MaxZ ? MaxZ : zOther.MaxZ }; result = zResult; } if (HasM && mOther != null && other.HasM) { ExtentM mResult = (ExtentM)result ?? new ExtentM(); mResult.MinM = MinM > mOther.MinM ? MinM : mOther.MinM; mResult.MaxM = MaxM < mOther.MaxM ? MaxM : mOther.MaxM; result = mResult; } else { result = new Extent(); } result.MinX = MinX > other.MinX ? MinX : other.MinX; result.MaxX = MaxX < other.MaxX ? MaxX : other.MaxX; result.MinY = MinY > other.MinY ? MinY : other.MinY; result.MaxY = MaxY < other.MaxY ? MaxY : other.MaxY; return(result); }
/// <summary> /// This allows parsing the X and Y values from a string version of the extent as: 'X[-180|180], Y[-90|90]' /// Where minimum always precedes maximum. The correct M or MZ version of extent will be returned if the string has those values. /// </summary> /// <param name="text">Text that contains the extent values.</param> /// <param name="result">Extent that was created.</param> /// <param name="nameFailed">Indicates which value failed.</param> /// <returns>True if the string could be parsed to an extent.</returns> public static bool TryParse(string text, out Extent result, out string nameFailed) { double xmin, xmax, ymin, ymax, mmin, mmax; result = null; if (text.Contains("Z")) { double zmin, zmax; nameFailed = "Z"; ExtentMz mz = new ExtentMz(); if (!TryExtract(text, "Z", out zmin, out zmax)) { return(false); } mz.MinZ = zmin; mz.MaxZ = zmax; nameFailed = "M"; if (!TryExtract(text, "M", out mmin, out mmax)) { return(false); } mz.MinM = mmin; mz.MaxM = mmax; result = mz; } else if (text.Contains("M")) { nameFailed = "M"; ExtentM me = new ExtentM(); if (!TryExtract(text, "M", out mmin, out mmax)) { return(false); } me.MinM = mmin; me.MaxM = mmax; result = me; } else { result = new Extent(); } nameFailed = "X"; if (!TryExtract(text, "X", out xmin, out xmax)) { return(false); } result.MinX = xmin; result.MaxX = xmax; nameFailed = "Y"; if (!TryExtract(text, "Y", out ymin, out ymax)) { return(false); } result.MinY = ymin; result.MaxY = ymax; return(true); }
/// <summary> /// Calculates the intersection of this extent and the other extent. A result /// with a min greater than the max in either direction is considered invalid /// and represents no intersection. /// </summary> /// <param name="other">The other extent to intersect with.</param> /// <returns>The resulting intersection.</returns> public override Extent Intersection(Extent other) { Extent result = null; if (HasZ && other is IExtentZ zOther && other.HasZ) { ExtentMz zResult = new ExtentMz { MinZ = MinZ > zOther.MinZ ? MinZ : zOther.MinZ, MaxZ = MaxZ < zOther.MaxZ ? MaxZ : zOther.MaxZ }; result = zResult; } if (HasM && other is IExtentM mOther && other.HasM) { ExtentM mResult = (ExtentM)result ?? new ExtentM(); mResult.MinM = MinM > mOther.MinM ? MinM : mOther.MinM; mResult.MaxM = MaxM < mOther.MaxM ? MaxM : mOther.MaxM; result = mResult; }
/// <summary> /// Produces a clone, rather than using this same object. /// </summary> /// <returns>Returns a copy of this object.</returns> public override object Clone() { ExtentMz copy = new ExtentMz(MinX, MinY, MinM, MinZ, MaxX, MaxY, MaxM, MinZ); return(copy); }