Example #1
0
        /// <summary>
        /// Creates a Polygon using the next token in the stream.
        /// </summary>
        /// <param name="tokenizer">
        /// Tokenizer over a stream of text in Well-known Text
        /// format. The next tokens must form a &lt;Polygon Text&gt;.
        /// </param>
        /// <returns>
        /// A Polygon specified by the next token in the stream.
        /// </returns>
        /// <exception cref="GeometryIOException">
        /// If the coordinates used to create the Polygon shell and holes do
        /// not form closed linestrings, or if an unexpected token was
        /// encountered.
        /// </exception>
        /// <exception cref="IOException">
        /// If an I/O error occurs.
        /// </exception>
        private Polygon ReadPolygon(StreamTokenizer tokenizer)
        {
            string nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken.Equals(WktEmpty))
            {
                LinearRing objRing = m_objFactory.CreateLinearRing(new Coordinate[] {});

                return(m_objFactory.CreatePolygon(objRing, new LinearRing[] {}));
            }

            GeometryList holes = new GeometryList();
            LinearRing   shell = ReadLinearRing(tokenizer);

            nextToken = GetNextCloserOrComma(tokenizer);

            while (nextToken.Equals(TokenComma))
            {
                LinearRing hole = ReadLinearRing(tokenizer);
                holes.Add(hole);
                nextToken = GetNextCloserOrComma(tokenizer);
            }

            return(m_objFactory.CreatePolygon(shell,
                                              holes.ToLinearRingArray()));
        }
Example #2
0
        private Polygon EditPolygon(Polygon polygon, IGeometryEdit operation)
        {
            Polygon newPolygon = (Polygon)operation.Edit(polygon, m_objFactory);

            if (newPolygon.IsEmpty)
            {
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return(newPolygon);
            }

            LinearRing shell = (LinearRing)Edit(newPolygon.ExteriorRing, operation);

            if (shell.IsEmpty)
            {
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return(m_objFactory.CreatePolygon(null, null));
            }

            GeometryList holes = new GeometryList();

            for (int i = 0; i < newPolygon.NumInteriorRings; i++)
            {
                LinearRing hole = (LinearRing)Edit(newPolygon.InteriorRing(i), operation);

                if (hole.IsEmpty)
                {
                    continue;
                }

                holes.Add(hole);
            }

            return(m_objFactory.CreatePolygon(shell, holes.ToLinearRingArray()));
        }
Example #3
0
        protected virtual Geometry Transform(Polygon geom, Geometry parent)
        {
            bool     isAllValidLinearRings = true;
            Geometry shell = Transform(geom.ExteriorRing, geom);

            if (shell == null ||
                !(shell.GeometryType == GeometryType.LinearRing) ||
                shell.IsEmpty)
            {
                isAllValidLinearRings = false;
            }

            GeometryList holes = new GeometryList();

            for (int i = 0; i < geom.NumInteriorRings; i++)
            {
                Geometry hole = Transform(geom.InteriorRing(i), geom);
                if (hole == null || hole.IsEmpty)
                {
                    continue;
                }

                if (!(hole.GeometryType == GeometryType.LinearRing))
                {
                    isAllValidLinearRings = false;
                }

                holes.Add(hole);
            }

            if (isAllValidLinearRings)
            {
                return(geomFactory.CreatePolygon((LinearRing)shell,
                                                 holes.ToLinearRingArray()));
            }
            else
            {
                GeometryList components = new GeometryList();
                if (shell != null)
                {
                    components.Add(shell);
                }

                components.AddRange(holes);

                return(geomFactory.BuildGeometry(components));
            }
        }