public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation, double distanceErrorPct = 0.025) { SpatialOperation spatialOperation; var shape = ReadShape(shapeWKT); switch (relation) { case SpatialRelation.Within: spatialOperation = SpatialOperation.IsWithin; break; case SpatialRelation.Contains: spatialOperation = SpatialOperation.Contains; break; case SpatialRelation.Disjoint: spatialOperation = SpatialOperation.IsDisjointTo; break; case SpatialRelation.Intersects: spatialOperation = SpatialOperation.Intersects; break; case SpatialRelation.Nearby: // only sort by this, do not filter return new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())); default: throw new ArgumentOutOfRangeException("relation"); } var args = new SpatialArgs(spatialOperation, shape) { DistErrPct = distanceErrorPct }; return spatialStrategy.MakeQuery(args); }
public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation, double distanceErrorPct = 0.025) { SpatialOperation spatialOperation; Shape shape = ShapeReadWriter.ReadShape(shapeWKT); switch (relation) { case SpatialRelation.Within: spatialOperation = SpatialOperation.IsWithin; break; case SpatialRelation.Contains: spatialOperation = SpatialOperation.Contains; break; case SpatialRelation.Disjoint: spatialOperation = SpatialOperation.IsDisjointTo; break; case SpatialRelation.Intersects: spatialOperation = SpatialOperation.Intersects; break; case SpatialRelation.Nearby: var nearbyArgs = new SpatialArgs(SpatialOperation.IsWithin, shape); nearbyArgs.SetDistPrecision(distanceErrorPct); // only sort by this, do not filter return new FunctionQuery(spatialStrategy.MakeValueSource(nearbyArgs)); default: throw new ArgumentOutOfRangeException("relation"); } var args = new SpatialArgs(spatialOperation, shape); args.SetDistPrecision(distanceErrorPct); return spatialStrategy.MakeQuery(args); }
public override void TearDown() { base.TearDown(); ctx = null; strategy = null; storeShape = true; }
public SpatialField(string fieldName, SpatialOptions options) { this.options = options; ntsContext = CreateNtsContext(options); shapeStringReadWriter = new ShapeStringReadWriter(options, ntsContext); strategy = CreateStrategy(fieldName, options, ntsContext); }
public static Filter MakeFilter(SpatialStrategy spatialStrategy, IndexQuery indexQuery) { var spatialQry = indexQuery as SpatialIndexQuery; if (spatialQry == null) return null; var args = new SpatialArgs(SpatialOperation.IsWithin, ShapeReadWriter.ReadShape(spatialQry.QueryShape)); return spatialStrategy.MakeFilter(args); }
protected void SetUp() { maxLength = GeohashPrefixTree.GetMaxLevelsPossible(); fieldInfo = new SimpleSpatialFieldInfo(GetType().Name); strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, maxLength)); _directory = new RAMDirectory(); _writer = new IndexWriter(_directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED); }
/// <param name="strategy">Needed to compute intersects</param> /// <param name="args">Used in spatial intersection</param> /// <param name="field"> /// This field is used to determine which docs have spatial data via /// <see cref="FieldCache.GetDocsWithField(AtomicReader, string)"/>. /// Passing null will assume all docs have spatial data. /// </param> public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string field) { this.field = field; // TODO consider making SpatialArgs cloneable SpatialOperation origOp = args.Operation; //copy so we can restore args.Operation = SpatialOperation.Intersects; //temporarily set to intersects intersectsFilter = strategy.MakeFilter(args); args.Operation = origOp; }
/// <param name="strategy">Needed to compute intersects</param> /// <param name="args">Used in spatial intersection</param> /// <param name="field"> /// This field is used to determine which docs have spatial data via /// <see cref="IFieldCache.GetDocsWithField(AtomicReader, string)"/>. /// Passing <c>null</c> will assume all docs have spatial data. /// </param> public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string?field) { // LUCENENET specific - added guard clauses if (strategy is null) { throw new ArgumentNullException(nameof(strategy)); } if (args is null) { throw new ArgumentNullException(nameof(args)); } this.field = field; // TODO consider making SpatialArgs cloneable SpatialOperation origOp = args.Operation; //copy so we can restore args.Operation = SpatialOperation.Intersects; //temporarily set to intersects intersectsFilter = strategy.MakeFilter(args); args.Operation = origOp; }
static void Main(string[] args) { int maxLength = GeohashPrefixTree.GetMaxLevelsPossible(); strategy = new RecursivePrefixTreeStrategy( new GeohashPrefixTree(context, maxLength)); var dir = new RAMDirectory(); var writer = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED); AddPoint(writer, "London", -81.233040, 42.983390); AddPoint(writer, "East New York", -73.882360, 40.666770); AddPoint(writer, "Manhattan", -73.966250, 40.783430); AddPoint(writer, "New York City", -74.005970, 40.714270); AddPoint(writer, "Oslo", 10.746090, 59.912730); AddPoint(writer, "Bergen", 5.324150, 60.392990); AddPoint(writer, "Washington, D. C.", -77.036370, 38.895110); writer.Close(); // Origin point - Oslo Spektrum const double lat = 59.9138688; const double lng = 10.752245399999993; const double radius = 600; var query = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, context.MakeCircle(lng, lat, radius)), fieldInfo); var searcher = new IndexSearcher(dir); var results = searcher.Search(query, null, 100); foreach (var topDoc in results.ScoreDocs) { var name = searcher.Doc(topDoc.doc).Get("Name"); Console.WriteLine(name); } searcher.Close(); dir.Close(); }
public ObjGeneratorDistanceValueSourceAnonymousClass(SpatialStrategy strategy) { this.strategy = strategy; }
public ObjGeneratorFilterAnonymousClass(SpatialStrategy strategy) { this.strategy = strategy; }
protected void Init() { //Typical geospatial context // These can also be constructed from SpatialContextFactory this.ctx = SpatialContext.GEO; int maxLevels = 11;//results in sub-meter precision for geohash //TODO demo lookup by detail distance // This can also be constructed from SpatialPrefixTreeFactory SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField"); this.directory = new RAMDirectory(); }
public Filter MakeFilter(SpatialStrategy spatialStrategy, IndexQuery indexQuery) { var spatialQry = indexQuery as SpatialIndexQuery; if (spatialQry == null) return null; var args = new SpatialArgs(SpatialOperation.IsWithin, ReadShape(spatialQry.QueryShape, spatialQry.RadiusUnitOverride)); return spatialStrategy.MakeFilter(args); }
public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation, double distanceErrorPct = 0.025, SpatialUnits? unitOverride = null) { SpatialOperation spatialOperation; var shape = ReadShape(shapeWKT, unitOverride); switch (relation) { case SpatialRelation.Within: spatialOperation = SpatialOperation.IsWithin; break; case SpatialRelation.Contains: spatialOperation = SpatialOperation.Contains; break; case SpatialRelation.Disjoint: spatialOperation = SpatialOperation.IsDisjointTo; break; case SpatialRelation.Intersects: spatialOperation = SpatialOperation.Intersects; break; case SpatialRelation.Nearby: // only sort by this, do not filter return new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())); default: throw new ArgumentOutOfRangeException("relation"); } var args = new SpatialArgs(spatialOperation, shape) { DistErrPct = distanceErrorPct }; if (existingQuery is MatchAllDocsQuery) return new CustomScoreQuery(spatialStrategy.MakeQuery(args), new ValueSourceQuery(spatialStrategy.MakeRecipDistanceValueSource(shape))); return spatialStrategy.MakeQuery(args); }
public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, SpatialIndexQuery spatialQuery) { return MakeQuery(existingQuery, spatialStrategy, spatialQuery.QueryShape, spatialQuery.SpatialRelation, spatialQuery.DistanceErrorPercentage, spatialQuery.RadiusUnitOverride); }
public ObjGeneratorQueryAnonymousHelper(SpatialStrategy strategy) { this.strategy = strategy; }
public Param(SpatialStrategy strategy) { this.strategy = strategy; }
internal Param(SpatialStrategy strategy) { this.strategy = strategy; }
internal Param(SpatialStrategy strategy) { this.strategy = strategy; }
static SpatialIndex() { maxLength = GeohashPrefixTree.GetMaxLevelsPossible(); fieldInfo = new SimpleSpatialFieldInfo(Constants.SpatialFieldName); strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(RavenSpatialContext, maxLength)); }