Get() public static method

public static Get ( string v ) : SpatialOperation
v string
return SpatialOperation
Exemplo n.º 1
0
        /// <summary>
        /// Parses a string such as "Intersects(ENVELOPE(-10,-8,22,20)) distErrPct=0.025".
        /// </summary>
        /// <param name="v">The string to parse. Mandatory.</param>
        /// <param name="ctx">The spatial context. Mandatory.</param>
        /// <returns>Not null.</returns>
        /// <exception cref="ArgumentException">if the parameters don't make sense or an add-on parameter is unknown.</exception>
        /// <exception cref="Spatial4n.Exceptions.ParseException">If there is a problem parsing the string.</exception>
        /// <exception cref="InvalidShapeException">When the coordinates are invalid for the shape.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="v"/> or <paramref name="ctx"/> is <c>null</c>.</exception>
        public virtual SpatialArgs Parse(string v, SpatialContext ctx)
        {
            // LUCENENET specific - added guard clauses
            if (v is null)
            {
                throw new ArgumentNullException(nameof(v));
            }
            if (ctx is null)
            {
                throw new ArgumentNullException(nameof(ctx));
            }

            int idx = v.IndexOf('(');
            int edx = v.LastIndexOf(')');

            if (idx < 0 || idx > edx)
            {
                throw new Spatial4n.Exceptions.ParseException("missing parens: " + v, -1);
            }

            SpatialOperation op = SpatialOperation.Get(v.Substring(0, idx - 0).Trim());

            //Substring in .NET is (startPosn, length), But in Java it's (startPosn, endPosn)
            //see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int, int)
            string body = v.Substring(idx + 1, edx - (idx + 1)).Trim();

            if (body.Length < 1)
            {
                throw new Spatial4n.Exceptions.ParseException("missing body : " + v, idx + 1);
            }

            var shape = ParseShape(body, ctx);
            var args  = NewSpatialArgs(op, shape);

            if (v.Length > (edx + 1))
            {
                body = v.Substring(edx + 1).Trim();
                if (body.Length > 0)
                {
                    IDictionary <string, string> aa = ParseMap(body);
                    ReadNameValuePairs(args, aa);
                    if (aa.Count == 0)
                    {
                        throw new ArgumentException("unused parameters: " + aa);
                    }
                }
            }
            args.Validate();
            return(args);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a string such as "Intersects(-10,20,-8,22) distErrPct=0.025".
        /// </summary>
        /// <param name="v"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public SpatialArgs Parse(String v, SpatialContext ctx)
        {
            int idx = v.IndexOf('(');
            int edx = v.LastIndexOf(')');

            if (idx < 0 || idx > edx)
            {
                throw new ArgumentException("missing parens: " + v);
            }

            SpatialOperation op = SpatialOperation.Get(v.Substring(0, idx).Trim());

            //Substring in .NET is (startPosn, length), But in Java it's (startPosn, endPosn)
            //see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int, int)
            String body = v.Substring(idx + 1, edx - (idx + 1)).Trim();

            if (body.Length < 1)
            {
                throw new ArgumentException("missing body : " + v);
            }

            var shape = ctx.ReadShape(body);
            var args  = new SpatialArgs(op, shape);

            if (v.Length > (edx + 1))
            {
                body = v.Substring(edx + 1).Trim();
                if (body.Length > 0)
                {
                    Dictionary <String, String> aa = ParseMap(body);
                    args.DistErrPct = ReadDouble(aa["distErrPct"]); aa.Remove(DIST_ERR_PCT);
                    args.DistErr    = ReadDouble(aa["distErr"]); aa.Remove(DIST_ERR);
                    if (aa.Count != 0)
                    {
                        throw new ArgumentException("unused parameters: " + aa);
                    }
                }
            }
            args.Validate();
            return(args);
        }