public IEnumerable <IFieldable> SpatialGenerate(string fieldName, string shapeWKT, SpatialSearchStrategy spatialSearchStrategy = SpatialSearchStrategy.GeohashPrefixTree, int maxTreeLevel = 0, double distanceErrorPct = 0.025) { if (string.IsNullOrEmpty(shapeWKT)) { return(Enumerable.Empty <IFieldable>()); } if (maxTreeLevel == 0) { switch (spatialSearchStrategy) { case SpatialSearchStrategy.GeohashPrefixTree: maxTreeLevel = 9; // about 2 meters, should be good enough (see: http://unterbahn.com/2009/11/metric-dimensions-of-geohash-partitions-at-the-equator/) break; case SpatialSearchStrategy.QuadPrefixTree: maxTreeLevel = 25; // about 1 meter, should be good enough break; default: throw new ArgumentOutOfRangeException("spatialSearchStrategy"); } } var strategy = SpatialStrategies.GetOrAdd(fieldName, s => SpatialIndex.CreateStrategy(fieldName, spatialSearchStrategy, maxTreeLevel)); var shape = SpatialIndex.ReadShape(shapeWKT); return(strategy.CreateIndexableFields(shape) .Concat(new[] { new Field(Constants.SpatialShapeFieldName, SpatialIndex.WriteShape(shape), Field.Store.YES, Field.Index.NO), })); }
public SpatialStrategy GetStrategyForField(string fieldName) { return(SpatialStrategies.GetOrAdd(fieldName, s => { if (SpatialStrategies.Count > 1024) { throw new InvalidOperationException("The number of spatial fields in an index is limited ot 1,024"); } return SpatialIndex.CreateStrategy(fieldName, SpatialSearchStrategy.GeohashPrefixTree, GeohashPrefixTree.GetMaxLevelsPossible()); })); }
public IEnumerable <IFieldable> SpatialGenerate(string fieldName, double?lat, double?lng) { var strategy = SpatialStrategies.GetOrAdd(fieldName, s => SpatialIndex.CreateStrategy(fieldName, SpatialSearchStrategy.GeohashPrefixTree, GeohashPrefixTree.GetMaxLevelsPossible())); // ReSharper disable CSharpWarnings::CS0612 Shape shape = SpatialIndex.Context.MakePoint(lng ?? 0, lat ?? 0); return(strategy.CreateIndexableFields(shape) .Concat(new[] { new Field(Constants.SpatialShapeFieldName, SpatialIndex.ShapeReadWriter.WriteShape(shape), Field.Store.YES, Field.Index.NO), })); // ReSharper restore CSharpWarnings::CS0612 }
public IEnumerable <IFieldable> SpatialGenerate(string fieldName, string shapeWKT, SpatialSearchStrategy spatialSearchStrategy = SpatialSearchStrategy.GeohashPrefixTree, int maxTreeLevel = 0, double distanceErrorPct = 0.025) { if (maxTreeLevel == 0) { maxTreeLevel = GeohashPrefixTree.GetMaxLevelsPossible(); } var strategy = SpatialStrategies.GetOrAdd(fieldName, s => SpatialIndex.CreateStrategy(fieldName, spatialSearchStrategy, maxTreeLevel)); var shape = SpatialIndex.ShapeReadWriter.ReadShape(shapeWKT); return(strategy.CreateIndexableFields(shape) .Concat(new[] { new Field(Constants.SpatialShapeFieldName, SpatialIndex.ShapeReadWriter.WriteShape(shape), Field.Store.YES, Field.Index.NO), })); }