Permalink
Browse files

Updating to Spatial4n v0.3 + additional fixes

LUCENE-4342, LUCENE-4351

git-svn-id: https://svn.apache.org/repos/asf/lucene.net/trunk@1388446 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 52fd789 commit 425dfd80baf4511522f401033cfcd9ad72ac010a @synhershko synhershko committed Sep 21, 2012
Showing with 601 additions and 747 deletions.
  1. BIN lib/Spatial4n/NET35/Spatial4n.Core.NTS.dll
  2. BIN lib/Spatial4n/NET35/Spatial4n.Core.NTS.pdb
  3. +79 −125 lib/Spatial4n/NET35/Spatial4n.Core.NTS.xml
  4. +71 −124 lib/Spatial4n/NET35/Spatial4n.Core.XML
  5. BIN lib/Spatial4n/NET35/Spatial4n.Core.dll
  6. BIN lib/Spatial4n/NET35/Spatial4n.Core.pdb
  7. BIN lib/Spatial4n/NET40/Spatial4n.Core.NTS.dll
  8. BIN lib/Spatial4n/NET40/Spatial4n.Core.NTS.pdb
  9. +79 −125 lib/Spatial4n/NET40/Spatial4n.Core.NTS.xml
  10. +71 −124 lib/Spatial4n/NET40/Spatial4n.Core.XML
  11. BIN lib/Spatial4n/NET40/Spatial4n.Core.dll
  12. BIN lib/Spatial4n/NET40/Spatial4n.Core.pdb
  13. +5 −7 src/contrib/Spatial/BBox/AreaSimilarity.cs
  14. +6 −4 src/contrib/Spatial/BBox/BBoxSimilarityValueSource.cs
  15. +1 −1 src/contrib/Spatial/BBox/BBoxStrategy.cs
  16. +1 −1 src/contrib/Spatial/Prefix/RecursivePrefixTreeFilter.cs
  17. +127 −127 src/contrib/Spatial/Prefix/Tree/GeohashPrefixTree.cs
  18. +1 −1 src/contrib/Spatial/Prefix/Tree/Node.cs
  19. +8 −8 src/contrib/Spatial/Prefix/Tree/QuadPrefixTree.cs
  20. +31 −31 src/contrib/Spatial/Prefix/Tree/SpatialPrefixTree.cs
  21. +26 −24 src/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeFactory.cs
  22. +8 −7 src/contrib/Spatial/Queries/SpatialArgs.cs
  23. +6 −4 src/contrib/Spatial/Queries/SpatialArgsParser.cs
  24. +1 −1 src/contrib/Spatial/Queries/SpatialOperation.cs
  25. +2 −1 test/contrib/Spatial/PortedSolr3Test.cs
  26. +55 −31 test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
  27. +23 −1 test/core/Util/LuceneTestCase.cs
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
Binary file not shown.
@@ -54,18 +54,16 @@ public class AreaSimilarity : BBoxSimilarity
/**
* Properties associated with the query envelope
*/
- private readonly SpatialContext ctx;
private readonly Rectangle queryExtent;
private readonly double queryArea;
private readonly double targetPower;
private readonly double queryPower;
- public AreaSimilarity(SpatialContext ctx, Rectangle queryExtent, double queryPower, double targetPower)
+ public AreaSimilarity(Rectangle queryExtent, double queryPower, double targetPower)
{
- this.ctx = ctx;
this.queryExtent = queryExtent;
- this.queryArea = queryExtent.GetArea(ctx);
+ this.queryArea = queryExtent.GetArea(null);
this.queryPower = queryPower;
this.targetPower = targetPower;
@@ -78,8 +76,8 @@ public AreaSimilarity(SpatialContext ctx, Rectangle queryExtent, double queryPow
// }
}
- public AreaSimilarity(SpatialContext ctx, Rectangle queryExtent)
- : this(ctx, queryExtent, 2.0, 0.5)
+ public AreaSimilarity(Rectangle queryExtent)
+ : this(queryExtent, 2.0, 0.5)
{
}
@@ -94,7 +92,7 @@ public double Score(Rectangle target, Explanation exp)
{
return 0;
}
- double targetArea = target.GetArea(ctx);
+ double targetArea = target.GetArea(null);
if (targetArea <= 0)
{
return 0;
@@ -38,7 +38,8 @@ public BBoxSimilarityValueSource(BBoxStrategy strategy, BBoxSimilarity similarit
private class BBoxSimilarityValueSourceDocValues : DocValues
{
private readonly BBoxSimilarityValueSource _enclosingInstance;
- private readonly double[] minX;
+ private readonly Rectangle rect;
+ private readonly double[] minX;
private readonly double[] minY;
private readonly double[] maxX;
private readonly double[] maxY;
@@ -48,8 +49,9 @@ private class BBoxSimilarityValueSourceDocValues : DocValues
public BBoxSimilarityValueSourceDocValues(IndexReader reader, BBoxSimilarityValueSource enclosingInstance)
{
_enclosingInstance = enclosingInstance;
+ rect = _enclosingInstance.strategy.GetSpatialContext().MakeRectangle(0, 0, 0, 0); //reused
- minX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minX/*, true*/);
+ minX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minX/*, true*/);
minY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_minY/*, true*/);
maxX = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxX/*, true*/);
maxY = FieldCache_Fields.DEFAULT.GetDoubles(reader, enclosingInstance.strategy.field_maxY/*, true*/);
@@ -63,7 +65,7 @@ public override float FloatVal(int doc)
// make sure it has minX and area
if (validMinX.Get(doc) && validMaxX.Get(doc))
{
- Rectangle rect = new RectangleImpl(
+ rect.Reset(
minX[doc], maxX[doc],
minY[doc], maxY[doc]);
return (float)_enclosingInstance.similarity.Score(rect, null);
@@ -76,7 +78,7 @@ public override Explanation Explain(int doc)
// make sure it has minX and area
if (validMinX.Get(doc) && validMaxX.Get(doc))
{
- Rectangle rect = new RectangleImpl(
+ rect.Reset(
minX[doc], maxX[doc],
minY[doc], maxY[doc]);
var exp = new Explanation();
@@ -93,7 +93,7 @@ private AbstractField DoubleField(string field, double value)
public override ValueSource MakeValueSource(SpatialArgs args)
{
- return new BBoxSimilarityValueSource(this, new AreaSimilarity(ctx, args.GetShape().GetBoundingBox(), queryPower, targetPower));
+ return new BBoxSimilarityValueSource(this, new AreaSimilarity(args.GetShape().GetBoundingBox(), queryPower, targetPower));
}
public override Query MakeQuery(SpatialArgs args)
@@ -144,7 +144,7 @@ public override DocIdSet GetDocIdSet(Index.IndexReader reader /*, Bits acceptDoc
{
//TODO should put more thought into implications of box vs point
Shape cShape = termLevel == grid.GetMaxLevels() ? scanCell.GetCenter() : scanCell.GetShape();
- if (queryShape.Relate(cShape, grid.GetSpatialContext()) == SpatialRelation.DISJOINT)
+ if (queryShape.Relate(cShape) == SpatialRelation.DISJOINT)
continue;
terms.Docs(bits);
@@ -23,131 +23,131 @@
namespace Lucene.Net.Spatial.Prefix.Tree
{
- /// <summary>
- /// A SpatialPrefixGrid based on Geohashes. Uses {@link GeohashUtils} to do all the geohash work.
- /// </summary>
- public class GeohashPrefixTree : SpatialPrefixTree
- {
- public class Factory : SpatialPrefixTreeFactory
- {
- protected override int GetLevelForDistance(double degrees)
- {
- var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.GetMaxLevelsPossible());
- return grid.GetLevelForDistance(degrees) + 1;//returns 1 greater
- }
-
- protected override SpatialPrefixTree NewSPT()
- {
- return new GeohashPrefixTree(ctx, maxLevels != null ? maxLevels.Value : GeohashPrefixTree.GetMaxLevelsPossible());
- }
- }
-
-
- public GeohashPrefixTree(SpatialContext ctx, int maxLevels)
- : base(ctx, maxLevels)
- {
- Rectangle bounds = ctx.GetWorldBounds();
- if (bounds.GetMinX() != -180)
- throw new ArgumentException("Geohash only supports lat-lon world bounds. Got " + bounds);
- int MAXP = GetMaxLevelsPossible();
- if (maxLevels <= 0 || maxLevels > MAXP)
- throw new ArgumentException("maxLen must be [1-" + MAXP + "] but got " + maxLevels);
-
- }
-
- /// <summary>
- /// Any more than this and there's no point (double lat & lon are the same).
- /// </summary>
- /// <returns></returns>
- public static int GetMaxLevelsPossible()
- {
- return GeohashUtils.MAX_PRECISION;
- }
-
- public override int GetLevelForDistance(double dist)
- {
- int level = GeohashUtils.LookupHashLenForWidthHeight(dist, dist);
- return Math.Max(Math.Min(level, maxLevels), 1);
- }
-
- protected override Node GetNode(Point p, int level)
- {
- return new GhCell(GeohashUtils.EncodeLatLon(p.GetY(), p.GetX(), level), this);//args are lat,lon (y,x)
- }
-
- public override Node GetNode(string token)
- {
- return new GhCell(token, this);
- }
-
- public override Node GetNode(byte[] bytes, int offset, int len)
- {
- throw new System.NotImplementedException();
- }
-
- public override IList<Node> GetNodes(Shape shape, int detailLevel, bool inclParents)
- {
- var s = shape as Point;
- return (s != null) ? base.GetNodesAltPoint(s, detailLevel, inclParents) : base.GetNodes(shape, detailLevel, inclParents);
- }
-
- public class GhCell : Node
- {
- public GhCell(String token, GeohashPrefixTree enclosingInstance)
- : base(enclosingInstance, token)
- {
- }
-
- public override void Reset(string newToken)
- {
- base.Reset(newToken);
- shape = null;
- }
-
- public override IList<Node> GetSubCells()
- {
- String[] hashes = GeohashUtils.GetSubGeohashes(GetGeohash());//sorted
- var cells = new List<Node>(hashes.Length);
-
- var enclosingInstance = (GeohashPrefixTree)spatialPrefixTree;
- foreach (String hash in hashes)
- {
- cells.Add(new GhCell(hash, enclosingInstance));
- }
- return cells;
- }
-
- public override int GetSubCellsSize()
- {
- return 32;//8x4
- }
-
- public override Node GetSubCell(Point p)
- {
- return ((GeohashPrefixTree)spatialPrefixTree).GetNode(p, GetLevel() + 1); //not performant!
- }
-
- private Shape shape;//cache
-
- public override Shape GetShape()
- {
- if (shape == null)
- {
- shape = GeohashUtils.DecodeBoundary(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
- }
- return shape;
- }
-
- public override Point GetCenter()
- {
- return GeohashUtils.Decode(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
- }
-
- private String GetGeohash()
- {
- return GetTokenString();
- }
-
- }//class GhCell
- }
+ /// <summary>
+ /// A SpatialPrefixGrid based on Geohashes. Uses {@link GeohashUtils} to do all the geohash work.
+ /// </summary>
+ public class GeohashPrefixTree : SpatialPrefixTree
+ {
+ public class Factory : SpatialPrefixTreeFactory
+ {
+ protected override int GetLevelForDistance(double degrees)
+ {
+ var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.GetMaxLevelsPossible());
+ return grid.GetLevelForDistance(degrees);
+ }
+
+ protected override SpatialPrefixTree NewSPT()
+ {
+ return new GeohashPrefixTree(ctx, maxLevels != null ? maxLevels.Value : GeohashPrefixTree.GetMaxLevelsPossible());
+ }
+ }
+
+
+ public GeohashPrefixTree(SpatialContext ctx, int maxLevels)
+ : base(ctx, maxLevels)
+ {
+ Rectangle bounds = ctx.GetWorldBounds();
+ if (bounds.GetMinX() != -180)
+ throw new ArgumentException("Geohash only supports lat-lon world bounds. Got " + bounds);
+ int MAXP = GetMaxLevelsPossible();
+ if (maxLevels <= 0 || maxLevels > MAXP)
+ throw new ArgumentException("maxLen must be [1-" + MAXP + "] but got " + maxLevels);
+
+ }
+
+ /// <summary>
+ /// Any more than this and there's no point (double lat & lon are the same).
+ /// </summary>
+ /// <returns></returns>
+ public static int GetMaxLevelsPossible()
+ {
+ return GeohashUtils.MAX_PRECISION;
+ }
+
+ public override int GetLevelForDistance(double dist)
+ {
+ int level = GeohashUtils.LookupHashLenForWidthHeight(dist, dist);
+ return Math.Max(Math.Min(level, maxLevels), 1);
+ }
+
+ protected override Node GetNode(Point p, int level)
+ {
+ return new GhCell(GeohashUtils.EncodeLatLon(p.GetY(), p.GetX(), level), this);//args are lat,lon (y,x)
+ }
+
+ public override Node GetNode(string token)
+ {
+ return new GhCell(token, this);
+ }
+
+ public override Node GetNode(byte[] bytes, int offset, int len)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ public override IList<Node> GetNodes(Shape shape, int detailLevel, bool inclParents)
+ {
+ var s = shape as Point;
+ return (s != null) ? base.GetNodesAltPoint(s, detailLevel, inclParents) : base.GetNodes(shape, detailLevel, inclParents);
+ }
+
+ public class GhCell : Node
+ {
+ public GhCell(String token, GeohashPrefixTree enclosingInstance)
+ : base(enclosingInstance, token)
+ {
+ }
+
+ public override void Reset(string newToken)
+ {
+ base.Reset(newToken);
+ shape = null;
+ }
+
+ public override IList<Node> GetSubCells()
+ {
+ String[] hashes = GeohashUtils.GetSubGeohashes(GetGeohash());//sorted
+ var cells = new List<Node>(hashes.Length);
+
+ var enclosingInstance = (GeohashPrefixTree)spatialPrefixTree;
+ foreach (String hash in hashes)
+ {
+ cells.Add(new GhCell(hash, enclosingInstance));
+ }
+ return cells;
+ }
+
+ public override int GetSubCellsSize()
+ {
+ return 32;//8x4
+ }
+
+ public override Node GetSubCell(Point p)
+ {
+ return ((GeohashPrefixTree)spatialPrefixTree).GetNode(p, GetLevel() + 1); //not performant!
+ }
+
+ private Shape shape;//cache
+
+ public override Shape GetShape()
+ {
+ if (shape == null)
+ {
+ shape = GeohashUtils.DecodeBoundary(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
+ }
+ return shape;
+ }
+
+ public override Point GetCenter()
+ {
+ return GeohashUtils.Decode(GetGeohash(), ((GeohashPrefixTree)spatialPrefixTree).ctx);
+ }
+
+ private String GetGeohash()
+ {
+ return GetTokenString();
+ }
+
+ }//class GhCell
+ }
}
@@ -158,7 +158,7 @@ public IList<Node> GetSubCells(Shape shapeFilter)
var copy = new List<Node>(cells.Count);//copy since cells contractually isn't modifiable
foreach (var cell in cells)
{
- var rel = cell.GetShape().Relate(shapeFilter, spatialPrefixTree.ctx);
+ SpatialRelation rel = cell.GetShape().Relate(shapeFilter);
if (rel == SpatialRelation.DISJOINT)
continue;
cell.shapeRel = rel;
Oops, something went wrong.

0 comments on commit 425dfd8

Please sign in to comment.