/// <summary> /// Gets the union of the input geometries. /// If no input geometries were provided but a <see cref="IGeometryFactory"/> was provided, /// an empty <see cref="IGeometryCollection"/> is returned. /// <para/>Otherwise, the return value is <c>null</c> /// </summary> /// <returns> /// A Geometry containing the union /// or an empty <see cref="IGeometryCollection"/> if no geometries were provided in the input, /// or <c>null</c> if not GeometryFactory was provided /// </returns> public IGeometry Union() { if (_geomFact == null) { return(null); } /** * For points and lines, only a single union operation is * required, since the OGC model allows self-intersecting * MultiPoint and MultiLineStrings. * This is not the case for polygons, so Cascaded Union is required. */ IGeometry unionPoints = null; if (_points.Count > 0) { var ptGeom = _geomFact.BuildGeometry(_points); unionPoints = UnionNoOpt(ptGeom); } IGeometry unionLines = null; if (_lines.Count > 0) { var lineGeom = _geomFact.BuildGeometry(_lines); unionLines = UnionNoOpt(lineGeom); } IGeometry unionPolygons = null; if (_polygons.Count > 0) { unionPolygons = CascadedPolygonUnion.Union(_polygons); } /* * Performing two unions is somewhat inefficient, * but is mitigated by unioning lines and points first */ var unionLA = UnionWithNull(unionLines, unionPolygons); IGeometry union; if (unionPoints == null) { union = unionLA; } else if (unionLA == null) { union = unionPoints; } else { union = PointGeometryUnion.Union((IPuntal)unionPoints, unionLA); } if (union == null) { return(_geomFact.CreateGeometryCollection()); } return(union); }
/// <summary> /// Computes the union of a <see cref="Point"/> geometry with /// another arbitrary <see cref="Geometry"/>. /// Does not copy any component geometries. /// </summary> /// <param name="pointGeom"></param> /// <param name="otherGeom"></param> /// <returns></returns> public static Geometry Union(IPuntal pointGeom, Geometry otherGeom) { var unioner = new PointGeometryUnion(pointGeom, otherGeom); return(unioner.Union()); }
///<summary> /// Computes the union of a <see cref="IPoint"/> geometry with /// another arbitrary <see cref="IGeometry"/>. /// Does not copy any component geometries. ///</summary> ///<param name="pointGeom"></param> ///<param name="otherGeom"></param> ///<returns></returns> public static IGeometry Union(IPuntal pointGeom, IGeometry otherGeom) { var unioner = new PointGeometryUnion(pointGeom, otherGeom); return unioner.Union(); }
/// <summary> /// Gets the union of the input geometries. /// <para/> /// The result of empty input is determined as follows: /// <list type="Bullet"> /// <item><description>If the input is empty and a dimension can be /// determined (i.e. an empty geometry is present), /// an empty atomic geometry of that dimension is returned.</description></item> /// <item><description>If no input geometries were provided but a <see cref="GeometryFactory"/> was provided, /// an empty <see cref="GeometryCollection"/> is returned.</description></item> /// <item><description>Otherwise, the return value is <c>null</c>.</description></item> /// </list> /// </summary> /// <returns> /// A Geometry containing the union, /// or an empty atomic geometry, or an empty <c>GEOMETRYCOLLECTION</c>, /// or<c>null</c> if no GeometryFactory was provided /// </returns> public Geometry Union() { if (_geomFact == null) { _geomFact = _extracter.Factory; } // Case 3 if (_geomFact == null) { return(null); } // Case 1 & 2 if (_extracter.IsEmpty) { return(_geomFact.CreateEmpty(_extracter.Dimension)); } var points = _extracter.GetExtract(Dimension.Point); var lines = _extracter.GetExtract(Dimension.Curve); var polygons = _extracter.GetExtract(Dimension.Surface); /** * For points and lines, only a single union operation is * required, since the OGC model allows self-intersecting * MultiPoint and MultiLineStrings. * This is not the case for polygons, so Cascaded Union is required. */ Geometry unionPoints = null; if (points.Count > 0) { var ptGeom = _geomFact.BuildGeometry(points); unionPoints = UnionNoOpt(ptGeom); } Geometry unionLines = null; if (lines.Count > 0) { var lineGeom = _geomFact.BuildGeometry(lines); unionLines = UnionNoOpt(lineGeom); } Geometry unionPolygons = null; if (polygons.Count > 0) { unionPolygons = CascadedPolygonUnion.Union(polygons); } /* * Performing two unions is somewhat inefficient, * but is mitigated by unioning lines and points first */ var unionLA = UnionWithNull(unionLines, unionPolygons); Geometry union; if (unionPoints == null) { union = unionLA; } else if (unionLA == null) { union = unionPoints; } else { union = PointGeometryUnion.Union((IPuntal)unionPoints, unionLA); } if (union == null) { return(_geomFact.CreateGeometryCollection()); } return(union); }