Beispiel #1
0
        public void TestCreateEmpty()
        {
            CheckEmpty(Factory.CreateEmpty(Dimension.Point), typeof(Point));
            CheckEmpty(Factory.CreateEmpty(Dimension.Curve), typeof(LineString));
            CheckEmpty(Factory.CreateEmpty(Dimension.Surface), typeof(Polygon));

            CheckEmpty(Factory.CreatePoint(), typeof(Point));
            CheckEmpty(Factory.CreateLineString(), typeof(LineString));
            CheckEmpty(Factory.CreatePolygon(), typeof(Polygon));

            CheckEmpty(Factory.CreateMultiPoint(), typeof(MultiPoint));
            CheckEmpty(Factory.CreateMultiLineString(), typeof(MultiLineString));
            CheckEmpty(Factory.CreateMultiPolygon(), typeof(MultiPolygon));
            CheckEmpty(Factory.CreateGeometryCollection(), typeof(GeometryCollection));
        }
Beispiel #2
0
        /// <summary>
        /// Creates an empty result geometry of the appropriate dimension,
        /// based on the given overlay operation and the dimensions of the inputs.
        /// The created geometry is always an atomic geometry,
        /// not a collection.
        /// <para/>
        /// The empty result is constructed using the following rules:
        /// <list type="bullet">
        /// <item><description><see cref="SpatialFunction.Intersection"/> - result has the dimension of the lowest input dimension</description></item>
        /// <item><description><see cref="SpatialFunction.Union"/> - result has the dimension of the highest input dimension</description></item>
        /// <item><description><see cref="SpatialFunction.Difference"/> - result has the dimension of the left-hand input</description></item>
        /// <item><description><see cref="SpatialFunction.SymDifference"/> - result has the dimension of the highest input dimension
        /// (since symDifference is the union of the differences).</description></item>
        /// </list>
        /// </summary>
        /// <param name="overlayOpCode">The overlay operation being performed</param>
        /// <param name="a">An input geometry</param>
        /// <param name="b">An input geometry</param>
        /// <param name="geomFact">The geometry factory being used for the operation</param>
        /// <returns>An empty atomic geometry of the appropriate dimension</returns>
        public static Geometry CreateEmptyResult(SpatialFunction overlayOpCode, Geometry a, Geometry b, GeometryFactory geomFact)
        {
            var resultDim = ResultDimension(overlayOpCode, a, b);

            // Handles resultDim == Dimension.False, although it should not happen
            return(geomFact.CreateEmpty(resultDim));
        }
Beispiel #3
0
        private Geometry CreatePointResult(IReadOnlyCollection <Point> points)
        {
            if (points.Count == 0)
            {
                return(_geometryFactory.CreateEmpty(0));
            }
            if (points.Count == 1)
            {
                return(points.First());
            }

            var pointsArray = GeometryFactory.ToPointArray(points);

            return(_geometryFactory.CreateMultiPoint(pointsArray));
        }
Beispiel #4
0
        /// <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);
        }