private List<IFieldable> AddPoint(Item item) { List<IFieldable> pointFields = new List<IFieldable>(); var setting = spatialConfigurations.LocationSettings.Where(i => i.TemplateId.Equals(item.TemplateID)).FirstOrDefault(); if (setting == null) return pointFields; SpatialContext ctx = SpatialContext.GEO; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11); var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName); double lng = 0; double lat = 0; bool parsedLat = false; bool parsedLong = false; if (!string.IsNullOrEmpty(item[setting.LatitudeField])) { parsedLat = Double.TryParse(item[setting.LatitudeField], out lat); } if (!string.IsNullOrEmpty(item[setting.LongitudeField])) { parsedLong = Double.TryParse(item[setting.LongitudeField], out lng); } if (!parsedLat && !parsedLong) return pointFields; pointFields = AddPoint( lng, lat); return pointFields; }
//Tests should call this first. private void init(int maxLength) { this.maxLength = maxLength; this.ctx = SpatialContext.GEO; var grid = new GeohashPrefixTree(ctx, maxLength); this.strategy = new RecursivePrefixTreeStrategy(grid, GetType().Name); }
public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable) { var indexableItem = indexable as SitecoreIndexableItem; if (indexableItem == null) return null; var item = (Sitecore.Data.Items.Item)indexableItem; if (item == null) return null; var latLon = item[SourceFieldName]; if (latLon == "" || latLon == "NULL") return null; // Convert from georss point to normal X, Y format latLon = latLon.Replace(" ", ", "); var spatialContext = SpatialContext.GEO; var geohashTree = new GeohashPrefixTree(spatialContext, 10); var strategy = new RecursivePrefixTreeStrategy(geohashTree, FieldName); var shape = spatialContext.ReadShape(latLon); var grid = strategy.GetGrid(); int levelForDistance = grid.GetLevelForDistance(strategy.DistErrPct); IList<Node> list = grid.GetNodes(shape, levelForDistance, true); return list.Select(node => node.GetTokenString()); }
private static readonly double LUCENE_4464_distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;//DEFAULT 2.5% public NtsPolygonTest() { //var args = new HashMap<String, String> {{"spatialContextFactory", "com.spatial4j.core.context.jts.JtsSpatialContextFactory"}}; //SpatialContextFactory.MakeSpatialContext(args, getClass().getClassLoader()); ctx = new NtsSpatialContext(true); var grid = new GeohashPrefixTree(ctx, 11);//< 1 meter == 11 maxLevels this.strategy = new RecursivePrefixTreeStrategy(grid, GetType().Name); ((RecursivePrefixTreeStrategy)this.strategy).DistErrPct = LUCENE_4464_distErrPct;//1% radius (small!) }
protected internal override int GetLevelForDistance(double degrees) { // LUCENENET specific - added guard clause if (m_ctx is null) { throw new InvalidOperationException($"{nameof(m_ctx)} must be set prior to calling GetLevelForDistance(double)."); } var grid = new GeohashPrefixTree(m_ctx, GeohashPrefixTree.MaxLevelsPossible); return(grid.GetLevelForDistance(degrees)); }
protected void Init() { //Typical geospatial context // These can also be constructed from SpatialContextFactory this.ctx = SpatialContext.GEO; int maxLevels = 11;//results in sub-meter precision for geohash //TODO demo lookup by detail distance // This can also be constructed from SpatialPrefixTreeFactory SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField"); this.directory = new RAMDirectory(); }
private static readonly double LUCENE_4464_distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;//DEFAULT 2.5% public NtsPolygonTest() { try { IDictionary<string, string> args = new Dictionary<string, string>(); args.Put("spatialContextFactory", typeof(NtsSpatialContextFactory).AssemblyQualifiedName); ctx = SpatialContextFactory.MakeSpatialContext(args /*, getClass().getClassLoader()*/); } catch (TypeLoadException e) //LUCENENET TODO: Does this match NoClassDefFoundError ?? { AssumeTrue("This test requires Spatial4n.Core.NTS: " + e, false); } GeohashPrefixTree grid = new GeohashPrefixTree(ctx, 11);//< 1 meter == 11 maxLevels this.strategy = new RecursivePrefixTreeStrategy(grid, GetType().Name); ((RecursivePrefixTreeStrategy)this.strategy).DistErrPct = (LUCENE_4464_distErrPct);//1% radius (small!) }
public void CreateSpatialFilterAndWeight(PointRadiusCriterion geoFilter, Filter currentFilter, Weight currentWeight) { var spatialContext = SpatialContext.GEO; var geohashTree = new GeohashPrefixTree(spatialContext, 10); var strategy = new RecursivePrefixTreeStrategy(geohashTree, geoFilter.FieldName); var point = spatialContext.MakePoint(geoFilter.Longitude, geoFilter.Latitude); var spatialArgs = new SpatialArgs(SpatialOperation.Intersects, spatialContext.MakeCircle(point, DistanceUtils.Dist2Degrees(geoFilter.RadiusKm, DistanceUtils.EARTH_MEAN_RADIUS_KM))); var circle = spatialContext.MakeCircle(point, DistanceUtils.Dist2Degrees(geoFilter.RadiusKm, DistanceUtils.EARTH_MEAN_RADIUS_KM)); var circleCells = strategy.GetGrid().GetWorldNode().GetSubCells(circle); var luceneFilters = new List<Filter>(); if (currentFilter != null) luceneFilters.Add(currentFilter); var tempSpatial = strategy.MakeFilter(spatialArgs); luceneFilters.Add(tempSpatial); if (geoFilter.Sort != PointRadiusCriterion.SortOption.None) { var valueSource = strategy.MakeDistanceValueSource(point); var funcQ = new FunctionQuery(valueSource); // this is a bit odd... but boosting the score negatively orders results if (geoFilter.Sort == PointRadiusCriterion.SortOption.Ascending) { funcQ.Boost = -1; } spatialWeight = funcQ.CreateWeight(this); spatialWeight.GetSumOfSquaredWeights(); luceneFilters.Add(new QueryWrapperFilter(currentWeight.Query)); } spatialFilter = new ChainedFilter(luceneFilters.ToArray(), 1); }
public IEnumerable<Param> ParamsProvider() { var ctorArgs = new List<Param>(); SpatialContext ctx = SpatialContext.GEO; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 12); SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash"); ctorArgs.Add(new Param(strategy)); grid = new QuadPrefixTree(ctx, 25); strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad"); ctorArgs.Add(new Param(strategy)); grid = new GeohashPrefixTree(ctx, 12); strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash"); ctorArgs.Add(new Param(strategy)); strategy = new PointVectorStrategy(ctx, "pointvector"); ctorArgs.Add(new Param(strategy)); return ctorArgs; }
//@ParametersFactory public static IList<Object[]> Parameters() { List<Object[]> ctorArgs = new List<object[]>(); SpatialContext ctx = SpatialContext.GEO; SpatialPrefixTree grid; SpatialStrategy strategy; grid = new QuadPrefixTree(ctx, 25); strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad"); ctorArgs.Add(new Object[] { new Param(strategy) }); grid = new GeohashPrefixTree(ctx, 12); strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash"); ctorArgs.Add(new Object[] { new Param(strategy) }); strategy = new PointVectorStrategy(ctx, "pointvector"); ctorArgs.Add(new Object[] { new Param(strategy) }); strategy = new SerializedDVStrategy(ctx, "serialized"); ctorArgs.Add(new Object[] { new Param(strategy) }); return ctorArgs; }
internal GhCell(GeohashPrefixTree outerInstance, byte[] bytes, int off, int len) : base(outerInstance, bytes, off, len) { }
internal GhCell(GeohashPrefixTree outerInstance, string token) : base(outerInstance, token) { }
protected override SpatialPrefixTree NewSPT() { return(new GeohashPrefixTree(ctx, maxLevels != null ? maxLevels.Value : GeohashPrefixTree.GetMaxLevelsPossible())); }
public GhCell(String token, GeohashPrefixTree enclosingInstance) : base(enclosingInstance, token) { }
protected internal override int GetLevelForDistance(double degrees) { var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.MaxLevelsPossible); return grid.GetLevelForDistance(degrees); }
internal GhCell(GeohashPrefixTree _enclosing, string token) : base(token) { this._enclosing = _enclosing; }
internal GhCell(GeohashPrefixTree _enclosing, byte[] bytes, int off, int len) : base(bytes, off, len) { this._enclosing = _enclosing; }
protected internal override int GetLevelForDistance(double degrees) { var grid = new GeohashPrefixTree(ctx, MaxLevelsPossible); return(grid.GetLevelForDistance(degrees)); }
protected override int GetLevelForDistance(double degrees) { var grid = new GeohashPrefixTree(ctx, GeohashPrefixTree.GetMaxLevelsPossible()); return grid.GetLevelForDistance(degrees) + 1;//returns 1 greater }