Ejemplo n.º 1
0
        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), }));
        }
Ejemplo n.º 2
0
        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.ReadShape(shapeWKT);

            return(strategy.CreateIndexableFields(shape)
                   .Concat(new[] { new Field(Constants.SpatialShapeFieldName, SpatialIndex.WriteShape(shape), Field.Store.YES, Field.Index.NO), }));
        }
Ejemplo n.º 3
0
        public IEnumerable <IFieldable> SpatialGenerate(string fieldName, double?lat, double?lng)
        {
            var strategy = GetStrategyForField(fieldName);

            if (lng == null || double.IsNaN(lng.Value))
            {
                return(Enumerable.Empty <IFieldable>());
            }
            if (lat == null || double.IsNaN(lat.Value))
            {
                return(Enumerable.Empty <IFieldable>());
            }

            Shape shape = SpatialIndex.Context.MakePoint(lng.Value, lat.Value);

            return(strategy.CreateIndexableFields(shape)
                   .Concat(new[] { new Field(Constants.SpatialShapeFieldName, SpatialIndex.WriteShape(shape), Field.Store.YES, Field.Index.NO), }));
        }