Parse() 공개 메소드

Parses a string such as "Intersects(ENVELOPE(-10,-8,22,20)) distErrPct=0.025".
if the parameters don't make sense or an add-on parameter is unknown If there is a problem parsing the string When the coordinates are invalid for the shape
public Parse ( string v, SpatialContext ctx ) : SpatialArgs
v string The string to parse. Mandatory.
ctx Spatial4n.Core.Context.SpatialContext The spatial context. Mandatory.
리턴 SpatialArgs
예제 #1
0
        public virtual void TestArgsParser()
        {
            SpatialArgsParser parser = new SpatialArgsParser();

            String arg = SpatialOperation.IsWithin + "(Envelope(-10, 10, 20, -20))";
            SpatialArgs @out = parser.Parse(arg, ctx);
            assertEquals(SpatialOperation.IsWithin, @out.Operation);
            IRectangle bounds = (IRectangle)@out.Shape;
            assertEquals(-10.0, bounds.MinX, 0D);
            assertEquals(10.0, bounds.MaxX, 0D);

            // Disjoint should not be scored
            arg = SpatialOperation.IsDisjointTo + " (Envelope(-10,-20,20,10))";
            @out = parser.Parse(arg, ctx);
            assertEquals(SpatialOperation.IsDisjointTo, @out.Operation);

            try
            {
                parser.Parse(SpatialOperation.IsDisjointTo + "[ ]", ctx);
                fail("spatial operations need args");
            }
            catch (Exception ex)
            {//expected
            }

            try
            {
                parser.Parse("XXXX(Envelope(-10, 10, 20, -20))", ctx);
                fail("unknown operation!");
            }
            catch (Exception ex)
            {//expected
            }
        }
예제 #2
0
        public virtual void TestArgsParser()
        {
            SpatialArgsParser parser = new SpatialArgsParser();

            String      arg  = SpatialOperation.IsWithin + "(Envelope(-10, 10, 20, -20))";
            SpatialArgs @out = parser.Parse(arg, ctx);

            assertEquals(SpatialOperation.IsWithin, @out.Operation);
            IRectangle bounds = (IRectangle)@out.Shape;

            assertEquals(-10.0, bounds.MinX, 0D);
            assertEquals(10.0, bounds.MaxX, 0D);

            // Disjoint should not be scored
            arg  = SpatialOperation.IsDisjointTo + " (Envelope(-10,-20,20,10))";
            @out = parser.Parse(arg, ctx);
            assertEquals(SpatialOperation.IsDisjointTo, @out.Operation);

            try
            {
                parser.Parse(SpatialOperation.IsDisjointTo + "[ ]", ctx);
                fail("spatial operations need args");
            }
#pragma warning disable 168
            catch (Exception ex)
#pragma warning restore 168
            {//expected
            }

            try
            {
                parser.Parse("XXXX(Envelope(-10, 10, 20, -20))", ctx);
                fail("unknown operation!");
            }
#pragma warning disable 168
            catch (Exception ex)
#pragma warning restore 168
            {//expected
            }
        }
예제 #3
0
        /**
         * Get Test Queries.  The InputStream is closed.
         */
        public static IEnumerator<SpatialTestQuery> GetTestQueries(
            SpatialArgsParser parser,
            SpatialContext ctx,
            string name,
            Stream @in)
        {

            List<SpatialTestQuery> results = new List<SpatialTestQuery>();

            TextReader bufInput = new StreamReader(@in, Encoding.UTF8);
            try
            {
                String line;
                for (int lineNumber = 1; (line = bufInput.ReadLine()) != null; lineNumber++)
                {
                    SpatialTestQuery test = new SpatialTestQuery();
                    test.line = line;
                    test.lineNumber = lineNumber;

                    try
                    {
                        // skip a comment
                        if (line.StartsWith("[", StringComparison.Ordinal))
                        {
                            int idx2 = line.IndexOf(']');
                            if (idx2 > 0)
                            {
                                line = line.Substring(idx2 + 1);
                            }
                        }

                        int idx = line.IndexOf('@');
                        StringTokenizer st = new StringTokenizer(line.Substring(0, idx - 0));
                        while (st.HasMoreTokens())
                        {
                            test.ids.Add(st.NextToken().Trim());
                        }
                        test.args = parser.Parse(line.Substring(idx + 1).Trim(), ctx);
                        results.Add(test);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("invalid query line: " + test.line, ex);
                    }
                }
            }
            finally
            {
                bufInput.Dispose();
            }
            return results.GetEnumerator();
        }
예제 #4
0
        public void TestArgParser()
        {
            SpatialArgsParser parser = new SpatialArgsParser();

            String arg = SpatialOperation.IsWithin + "(-10 -20 10 20)";
            SpatialArgs outValue = parser.Parse(arg, ctx);
            Assert.AreEqual(SpatialOperation.IsWithin, outValue.Operation);
            Rectangle bounds = (Rectangle)outValue.Shape;
            Assert.AreEqual(-10.0, bounds.GetMinX(), 0D);
            Assert.AreEqual(10.0, bounds.GetMaxX(), 0D);

            // Disjoint should not be scored
            arg = SpatialOperation.IsDisjointTo + " (-10 10 -20 20)";
            outValue = parser.Parse(arg, ctx);
            Assert.AreEqual(SpatialOperation.IsDisjointTo, outValue.Operation);

            try
            {
                parser.Parse(SpatialOperation.IsDisjointTo + "[ ]", ctx);
                Assert.True(false, "spatial operations need args");
            }
            catch (Exception)
            {
                //expected
            }

            try
            {
                parser.Parse("XXXX(-10 10 -20 20)", ctx);
                Assert.True(false, "unknown operation!");
            }
            catch (Exception)
            {
                //expected
            }
        }