19 using System.Collections.Generic;
20 using Spatial4n.Core.Context;
21 using Spatial4n.Core.Shapes;
22 using Spatial4n.Core.Util;
24 namespace Lucene.Net.Spatial.Prefix.Tree
36 protected override int GetLevelForDistance(
double degrees)
50 : base(ctx, maxLevels)
52 Rectangle bounds = ctx.GetWorldBounds();
53 if (bounds.GetMinX() != -180)
54 throw new ArgumentException(
"Geohash only supports lat-lon world bounds. Got " + bounds);
55 int MAXP = GetMaxLevelsPossible();
56 if (maxLevels <= 0 || maxLevels > MAXP)
57 throw new ArgumentException(
"maxLen must be [1-" + MAXP +
"] but got " + maxLevels);
65 public static int GetMaxLevelsPossible()
67 return GeohashUtils.MAX_PRECISION;
70 public override int GetLevelForDistance(
double dist)
74 int level = GeohashUtils.LookupHashLenForWidthHeight(dist, dist);
75 return Math.Max(Math.Min(level, maxLevels), 1);
78 protected override Node GetNode(Point p,
int level)
80 return new GhCell(GeohashUtils.EncodeLatLon(p.GetY(), p.GetX(), level),
this);
83 public override Node GetNode(
string token)
85 return new GhCell(token,
this);
88 public override Node GetNode(byte[] bytes,
int offset,
int len)
90 throw new System.NotImplementedException();
93 public override IList<Node> GetNodes(Shape shape,
int detailLevel,
bool inclParents)
95 var s = shape as Point;
96 return (s != null) ? base.GetNodesAltPoint(s, detailLevel, inclParents) : base.GetNodes(shape, detailLevel, inclParents);
102 : base(enclosingInstance, token)
106 public override void Reset(
string newToken)
108 base.Reset(newToken);
112 public override IList<Node> GetSubCells()
114 String[] hashes = GeohashUtils.GetSubGeohashes(GetGeohash());
115 var cells =
new List<Node>(hashes.Length);
118 foreach (String hash
in hashes)
120 cells.Add(
new GhCell(hash, enclosingInstance));
125 public override int GetSubCellsSize()
130 public override Node GetSubCell(Point p)
137 public override Shape GetShape()
141 shape = GeohashUtils.DecodeBoundary(GetGeohash(), ((
GeohashPrefixTree)spatialPrefixTree).ctx);
146 public override Point GetCenter()
148 return GeohashUtils.Decode(GetGeohash(), ((
GeohashPrefixTree)spatialPrefixTree).ctx);
151 private String GetGeohash()
153 return GetTokenString();