19 using System.Collections.Generic;
20 using Spatial4n.Core.Context;
21 using Spatial4n.Core.Distance;
23 namespace Lucene.Net.Spatial.Prefix.Tree
31 private const double DEFAULT_GEO_MAX_DETAIL_KM = 0.001;
32 public static readonly String PREFIX_TREE =
"prefixTree";
33 public static readonly String MAX_LEVELS =
"maxLevels";
34 public static readonly String MAX_DIST_ERR =
"maxDistErr";
36 protected Dictionary<String, String>
args;
37 protected SpatialContext
ctx;
47 public static SpatialPrefixTree MakeSPT(Dictionary<String, String> args, SpatialContext ctx)
51 if (!args.TryGetValue(PREFIX_TREE, out cname) || cname == null)
52 cname = ctx.IsGeo() ?
"geohash" :
"quad";
53 if (
"geohash".Equals(cname, StringComparison.InvariantCultureIgnoreCase))
55 else if (
"quad".Equals(cname, StringComparison.InvariantCultureIgnoreCase))
59 Type t = Type.GetType(cname);
62 instance.
Init(args, ctx);
66 protected void Init(Dictionary<String, String> args, SpatialContext ctx)
73 protected void InitMaxLevels()
76 if (args.TryGetValue(MAX_LEVELS, out mlStr) && mlStr != null)
78 maxLevels =
int.Parse(mlStr);
83 if (!args.TryGetValue(MAX_DIST_ERR, out mlStr) || mlStr == null)
87 degrees = DistanceUtils.Dist2Degrees(DEFAULT_GEO_MAX_DETAIL_KM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
91 degrees =
Double.Parse(mlStr);
93 maxLevels = GetLevelForDistance(degrees);
97 protected abstract int GetLevelForDistance(
double degrees);