Esempio n. 1
0
        /// <summary>
        /// Parses a MULTIPOLYGON shape from the raw string.
        /// <code>
        ///   '(' polygon (',' polygon )* ')'
        /// </code>
        /// </summary>
        protected virtual IShape ParseMulitPolygonShape(WktShapeParser.State state)
        {
            if (state.NextIfEmptyAndSkipZM())
            {
                return(m_ctx.MakeCollection(new List <IShape>()));
            }

            IList <IShape> polygons = new List <IShape>();

            state.NextExpect('(');
            do
            {
                polygons.Add(ParsePolygonShape(state));
            } while (state.NextIf(','));
            state.NextExpect(')');

            return(m_ctx.MakeCollection(polygons));
        }
Esempio n. 2
0
        public virtual void TestParsePolygon()
        {
            IShape polygonNoHoles = new PolygonBuilder(ctx)
                                    .Point(100, 0)
                                    .Point(101, 0)
                                    .Point(101, 1)
                                    .Point(100, 2)
                                    .Point(100, 0)
                                    .Build();
            string polygonNoHolesSTR = "POLYGON ((100 0, 101 0, 101 1, 100 2, 100 0))";

            AssertParses(polygonNoHolesSTR, polygonNoHoles);
            AssertParses("POLYGON((100 0,101 0,101 1,100 2,100 0))", polygonNoHoles);

            AssertParses("GEOMETRYCOLLECTION ( " + polygonNoHolesSTR + ")",
                         ctx.MakeCollection(new List <IShape>(new IShape[] { polygonNoHoles })));

            IShape polygonWithHoles = new PolygonBuilder(ctx)
                                      .Point(100, 0)
                                      .Point(101, 0)
                                      .Point(101, 1)
                                      .Point(100, 1)
                                      .Point(100, 0)
                                      .NewHole()
                                      .Point(100.2, 0.2)
                                      .Point(100.8, 0.2)
                                      .Point(100.8, 0.8)
                                      .Point(100.2, 0.8)
                                      .Point(100.2, 0.2)
                                      .EndHole()
                                      .Build();

            AssertParses("POLYGON ((100 0, 101 0, 101 1, 100 1, 100 0), (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2))", polygonWithHoles);

            GeometryFactory gf = ctx.GeometryFactory;

            AssertParses("POLYGON EMPTY", ctx.MakeShape(
                             gf.CreatePolygon(gf.CreateLinearRing(new Coordinate[] { }), null)
                             ));
        }