Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
SpatialOperation.cs
Go to the documentation of this file.
1 /* See the NOTICE file distributed with
2  * this work for additional information regarding copyright ownership.
3  * Esri Inc. licenses this file to You under the Apache License, Version 2.0
4  * (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 using System;
17 using System.Collections.Generic;
18 using System.Globalization;
19 using System.Linq;
20 using Spatial4n.Core.Exceptions;
21 
22 namespace Lucene.Net.Spatial.Queries
23 {
24  public class SpatialOperation
25  {
26  // Private registry
27  private static readonly Dictionary<String, SpatialOperation> registry = new Dictionary<string, SpatialOperation>();
28  private static readonly IList<SpatialOperation> list = new List<SpatialOperation>();
29 
30  // Geometry Operations
31 
35  public static readonly SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);
36 
40  public static readonly SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);
41 
42  public static readonly SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);
43  public static readonly SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);
44  public static readonly SpatialOperation IsEqualTo = new SpatialOperation("IsEqualTo", false, false, false);
45  public static readonly SpatialOperation IsDisjointTo = new SpatialOperation("IsDisjointTo", false, false, false);
46  public static readonly SpatialOperation IsWithin = new SpatialOperation("IsWithin", true, false, true);
47  public static readonly SpatialOperation Overlaps = new SpatialOperation("Overlaps", true, false, true);
48 
49  // Member variables
50  private readonly bool scoreIsMeaningful;
51  private readonly bool sourceNeedsArea;
52  private readonly bool targetNeedsArea;
53  private readonly String name;
54 
55  protected SpatialOperation(String name, bool scoreIsMeaningful, bool sourceNeedsArea, bool targetNeedsArea)
56  {
57  this.name = name;
58  this.scoreIsMeaningful = scoreIsMeaningful;
59  this.sourceNeedsArea = sourceNeedsArea;
60  this.targetNeedsArea = targetNeedsArea;
61  registry[name] = this;
62  registry[name.ToUpper(CultureInfo.CreateSpecificCulture("en-US"))] = this;
63  list.Add(this);
64  }
65 
66  public static SpatialOperation Get(String v)
67  {
69  if (!registry.TryGetValue(v, out op) || op == null)
70  {
71  if (!registry.TryGetValue(v.ToUpper(CultureInfo.CreateSpecificCulture("en-US")), out op) || op == null)
72  throw new ArgumentException("Unknown Operation: " + v, "v");
73  }
74  return op;
75  }
76 
77  public static IList<SpatialOperation> Values()
78  {
79  return list;
80  }
81 
82  public static bool Is(SpatialOperation op, params SpatialOperation[] tst)
83  {
84  return tst.Any(t => op == t);
85  }
86 
87 
88  // ================================================= Getters / Setters =============================================
89 
90  public bool IsScoreIsMeaningful()
91  {
92  return scoreIsMeaningful;
93  }
94 
95  public bool IsSourceNeedsArea()
96  {
97  return sourceNeedsArea;
98  }
99 
100  public bool IsTargetNeedsArea()
101  {
102  return targetNeedsArea;
103  }
104 
105  public String GetName()
106  {
107  return name;
108  }
109 
110  public override String ToString()
111  {
112  return name;
113  }
114 
115  }
116 }