Exemple #1
0
 public SpatialArgs(SpatialOperation operation, Shape shape)
 {
     if (operation == null || shape == null)
         throw new ArgumentException("operation and shape are required");
     this.Operation = operation;
     this.Shape = shape;
 }
Exemple #2
0
 public SpatialArgs(SpatialOperation operation, IShape shape)
 {
     if (operation == null || shape == null)
     {
         throw new ArgumentException("operation and shape are required");
     }
     this.Operation = operation;
     this.Shape     = shape;
 }
Exemple #3
0
 public static bool Is(SpatialOperation op, params SpatialOperation[] tst)
 {
     foreach (SpatialOperation t in tst)
     {
         if (op == t)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
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);
        }
Exemple #5
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);
        }
 protected virtual SpatialArgs NewSpatialArgs(SpatialOperation op, IShape shape)
 {
     return new SpatialArgs(op, shape);
 }
Exemple #7
0
 protected virtual SpatialArgs NewSpatialArgs(SpatialOperation op, IShape shape)
 {
     return(new SpatialArgs(op, shape));
 }
 public static bool Is(SpatialOperation op, params SpatialOperation[] tst)
 {
     return(tst.Any(t => op == t));
 }
 public UnsupportedSpatialOperation(SpatialOperation op)
     : base(op.Name)
 {
 }
Exemple #10
0
		public static bool Is(SpatialOperation op, params SpatialOperation[] tst)
		{
			return tst.Any(t => op == t);
		}
Exemple #11
0
		public SpatialArgs(SpatialOperation operation, Shape shape)
		{
			this.Operation = operation;
			this.shape = shape;
		}
Exemple #12
0
		public SpatialArgs(SpatialOperation operation)
		{
			this.Operation = operation;
		}
        private readonly IShape queryShape;//the right hand side (constant)

        /// <summary>
        /// 
        /// </summary>
        /// <param name="shapeValuesource">
        /// Must yield <see cref="IShape"/> instances from it's ObjectVal(doc). If null
        /// then the result is false. This is the left-hand (indexed) side.
        /// </param>
        /// <param name="op">the predicate</param>
        /// <param name="queryShape">The shape on the right-hand (query) side.</param>
        public ShapePredicateValueSource(ValueSource shapeValuesource, SpatialOperation op, IShape queryShape)
        {
            this.shapeValuesource = shapeValuesource;
            this.op = op;
            this.queryShape = queryShape;
        }
        private void doTest(SpatialOperation operation)
        {
            //first show that when there's no data, a query will result in no results
            {
                Query query = strategy.MakeQuery(new SpatialArgs(operation, randomRectangle()));
                SearchResults searchResults = executeQuery(query, 1);
                assertEquals(0, searchResults.numFound);
            }

            bool biasContains = (operation == SpatialOperation.Contains);

            //Main index loop:
            IDictionary<String, IShape> indexedShapes = new LinkedHashMap<String, IShape>();
            IDictionary<String, IShape> indexedShapesGS = new LinkedHashMap<String, IShape>();//grid snapped
            int numIndexedShapes = randomIntBetween(1, 6);
            bool indexedAtLeastOneShapePair = false;
            for (int i = 0; i < numIndexedShapes; i++)
            {
                String id = "" + i;
                IShape indexedShape;
                int R = Random().nextInt(12);
                if (R == 0)
                {//1 in 12
                    indexedShape = null;
                }
                else if (R == 1)
                {//1 in 12
                    indexedShape = randomPoint();//just one point
                }
                else if (R <= 4)
                {//3 in 12
                 //comprised of more than one shape
                    indexedShape = randomShapePairRect(biasContains);
                    indexedAtLeastOneShapePair = true;
                }
                else
                {
                    indexedShape = randomRectangle();//just one rect
                }

                indexedShapes.Put(id, indexedShape);
                indexedShapesGS.Put(id, gridSnap(indexedShape));

                adoc(id, indexedShape);

                if (Random().nextInt(10) == 0)
                    Commit();//intermediate commit, produces extra segments

            }
            //delete some documents randomly
            IEnumerator<String> idIter = indexedShapes.Keys.ToList().GetEnumerator();
            while (idIter.MoveNext())
            {
                String id = idIter.Current;
                if (Random().nextInt(10) == 0)
                {
                    DeleteDoc(id);
                    //idIter.Remove();
                    indexedShapes.Remove(id); // LUCENENET TODO: Verify this works.
                    indexedShapesGS.Remove(id);
                }
            }

            Commit();

            //Main query loop:
            int numQueryShapes = AtLeast(20);
            for (int i = 0; i < numQueryShapes; i++)
            {
                int scanLevel = randomInt(grid.MaxLevels);
                ((RecursivePrefixTreeStrategy)strategy).PrefixGridScanLevel = (scanLevel);

                IShape queryShape;
                switch (randomInt(10))
                {
                    case 0: queryShape = randomPoint(); break;
                    // LUCENE-5549
                    //TODO debug: -Dtests.method=testWithin -Dtests.multiplier=3 -Dtests.seed=5F5294CE2E075A3E:AAD2F0F79288CA64
                    //        case 1:case 2:case 3:
                    //          if (!indexedAtLeastOneShapePair) { // avoids ShapePair.relate(ShapePair), which isn't reliable
                    //            queryShape = randomShapePairRect(!biasContains);//invert biasContains for query side
                    //            break;
                    //          }
                    default: queryShape = randomRectangle(); break;
                }
                IShape queryShapeGS = gridSnap(queryShape);

                bool opIsDisjoint = operation == SpatialOperation.IsDisjointTo;

                //Generate truth via brute force:
                // We ensure true-positive matches (if the predicate on the raw shapes match
                //  then the search should find those same matches).
                // approximations, false-positive matches
                ISet<String> expectedIds = new /* LinkedHashSet<string>*/ HashSet<string>();//true-positives
                ISet<String> secondaryIds = new /* LinkedHashSet<string>*/ HashSet<string>();//false-positives (unless disjoint)
                foreach (var entry in indexedShapes)
                {
                    String id = entry.Key;
                    IShape indexedShapeCompare = entry.Value;
                    if (indexedShapeCompare == null)
                        continue;
                    IShape queryShapeCompare = queryShape;

                    if (operation.Evaluate(indexedShapeCompare, queryShapeCompare))
                    {
                        expectedIds.add(id);
                        if (opIsDisjoint)
                        {
                            //if no longer intersect after buffering them, for disjoint, remember this
                            indexedShapeCompare = indexedShapesGS[id];
                            queryShapeCompare = queryShapeGS;
                            if (!operation.Evaluate(indexedShapeCompare, queryShapeCompare))
                                secondaryIds.add(id);
                        }
                    }
                    else if (!opIsDisjoint)
                    {
                        //buffer either the indexed or query shape (via gridSnap) and try again
                        if (operation == SpatialOperation.Intersects)
                        {
                            indexedShapeCompare = indexedShapesGS[id];
                            queryShapeCompare = queryShapeGS;
                            //TODO Unfortunately, grid-snapping both can result in intersections that otherwise
                            // wouldn't happen when the grids are adjacent. Not a big deal but our test is just a
                            // bit more lenient.
                        }
                        else if (operation == SpatialOperation.Contains)
                        {
                            indexedShapeCompare = indexedShapesGS[id];
                        }
                        else if (operation == SpatialOperation.IsWithin)
                        {
                            queryShapeCompare = queryShapeGS;
                        }
                        if (operation.Evaluate(indexedShapeCompare, queryShapeCompare))
                            secondaryIds.add(id);
                    }
                }

                //Search and verify results
                SpatialArgs args = new SpatialArgs(operation, queryShape);
                if (queryShape is ShapePair)
                    args.DistErrPct = (0.0);//a hack; we want to be more detailed than gridSnap(queryShape)
                Query query = strategy.MakeQuery(args);
                SearchResults got = executeQuery(query, 100);
                ISet<String> remainingExpectedIds = new /* LinkedHashSet<string>*/ HashSet<string>(expectedIds);
                foreach (SearchResult result in got.results)
                {
                    String id = result.GetId();
                    bool removed = remainingExpectedIds.remove(id);
                    if (!removed && (!opIsDisjoint && !secondaryIds.contains(id)))
                    {
                        fail("Shouldn't match", id, indexedShapes, indexedShapesGS, queryShape);
                    }
                }
                if (opIsDisjoint)
                    remainingExpectedIds.removeAll(secondaryIds);
                if (remainingExpectedIds.Any())
                {
                    var iter = remainingExpectedIds.GetEnumerator();
                    iter.MoveNext();
                    String id = iter.Current;
                    fail("Should have matched", id, indexedShapes, indexedShapesGS, queryShape);
                }
            }
        }
 public UnsupportedSpatialOperation(SpatialOperation op)
     : base(op.Name)
 {
 }
Exemple #16
0
 public UnsupportedSpatialOperation(SpatialOperation op) : base(op.GetName())
 {
 }
Exemple #17
0
 public SpatialArgs(SpatialOperation operation, IShape shape)
 {
     // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention)
     this.operation = operation ?? throw new ArgumentNullException(nameof(operation), "operation and shape are required");
     this.shape     = shape ?? throw new ArgumentNullException(nameof(shape), "operation and shape are required");
 }
Exemple #18
0
        protected virtual void AssertOperation(IDictionary<String, IShape> indexedDocs,
                                       SpatialOperation operation, IShape queryShape)
        {
            //Generate truth via brute force
            ISet<string> expectedIds = new HashSet<string>();
            foreach (var stringShapeEntry in indexedDocs)
            {
                if (operation.Evaluate(stringShapeEntry.Value, queryShape))
                    expectedIds.add(stringShapeEntry.Key);
            }

            SpatialTestQuery testQuery = new SpatialTestQuery();
            testQuery.args = new SpatialArgs(operation, queryShape);
            testQuery.ids = new List<string>(expectedIds);
            runTestQuery(SpatialMatchConcern.FILTER, testQuery);
        }