コード例 #1
0
 public static IShape MakeShapeFromString(SpatialStrategy strategy, string name, string shapeStr)
 {
     if (shapeStr != null && shapeStr.Length > 0)
     {
         try
         {
             return(strategy.SpatialContext.ReadShapeFromWkt(shapeStr));
         }
         catch (Exception e)
         {//InvalidShapeException TODO
             Console.Error.WriteLine("Shape " + name + " wasn't parseable: " + e + "  (skipping it)");
             return(null);
         }
     }
     return(null);
 }
コード例 #2
0
ファイル: SpatialField.cs プロジェクト: ybdev/ravendb
        public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
                               double distanceErrorPct = 0.025, SpatialUnits?unitOverride = null)
        {
            SpatialOperation spatialOperation;
            var shape = ReadShape(shapeWKT, unitOverride);

            switch (relation)
            {
            case SpatialRelation.Within:
                spatialOperation = SpatialOperation.IsWithin;
                break;

            case SpatialRelation.Contains:
                spatialOperation = SpatialOperation.Contains;
                break;

            case SpatialRelation.Disjoint:
                spatialOperation = SpatialOperation.IsDisjointTo;
                break;

            case SpatialRelation.Intersects:
                spatialOperation = SpatialOperation.Intersects;
                break;

            case SpatialRelation.Nearby:
                // only sort by this, do not filter
                return(new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())));

            default:
                throw new ArgumentOutOfRangeException("relation");
            }
            var args = new SpatialArgs(spatialOperation, shape)
            {
                DistErrPct = distanceErrorPct
            };

            if (existingQuery is MatchAllDocsQuery)
            {
                return(new CustomScoreQuery(spatialStrategy.MakeQuery(args), new ValueSourceQuery(spatialStrategy.MakeRecipDistanceValueSource(shape))));
            }
            return(spatialStrategy.MakeQuery(args));
        }
コード例 #3
0
        public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
                                      double distanceErrorPct = 0.025)
        {
            SpatialOperation spatialOperation;
            Shape            shape = ShapeReadWriter.ReadShape(shapeWKT);

            switch (relation)
            {
            case SpatialRelation.Within:
                spatialOperation = SpatialOperation.IsWithin;
                break;

            case SpatialRelation.Contains:
                spatialOperation = SpatialOperation.Contains;
                break;

            case SpatialRelation.Disjoint:
                spatialOperation = SpatialOperation.IsDisjointTo;
                break;

            case SpatialRelation.Intersects:
                spatialOperation = SpatialOperation.Intersects;
                break;

            case SpatialRelation.Nearby:
                var nearbyArgs = new SpatialArgs(SpatialOperation.IsWithin, shape);
                nearbyArgs.SetDistPrecision(distanceErrorPct);
                // only sort by this, do not filter
                return(new FunctionQuery(spatialStrategy.MakeValueSource(nearbyArgs)));

            default:
                throw new ArgumentOutOfRangeException("relation");
            }
            var args = new SpatialArgs(spatialOperation, shape);

            args.SetDistPrecision(distanceErrorPct);

            return(spatialStrategy.MakeQuery(args));
        }
コード例 #4
0
        static void Main(string[] args)
        {
            int maxLength = GeohashPrefixTree.GetMaxLevelsPossible();

            strategy = new RecursivePrefixTreeStrategy(
                new GeohashPrefixTree(context, maxLength));

            var dir    = new RAMDirectory();
            var writer = new IndexWriter(dir, new SimpleAnalyzer(), true,
                                         IndexWriter.MaxFieldLength.UNLIMITED);

            AddPoint(writer, "London", -81.233040, 42.983390);
            AddPoint(writer, "East New York", -73.882360, 40.666770);
            AddPoint(writer, "Manhattan", -73.966250, 40.783430);
            AddPoint(writer, "New York City", -74.005970, 40.714270);
            AddPoint(writer, "Oslo", 10.746090, 59.912730);
            AddPoint(writer, "Bergen", 5.324150, 60.392990);
            AddPoint(writer, "Washington, D. C.", -77.036370, 38.895110);

            writer.Close();

            // Origin point - Oslo Spektrum
            const double lat    = 59.9138688;
            const double lng    = 10.752245399999993;
            const double radius = 600;
            var          query  = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin,
                                                                     context.MakeCircle(lng, lat, radius)), fieldInfo);

            var searcher = new IndexSearcher(dir);
            var results  = searcher.Search(query, null, 100);

            foreach (var topDoc in results.ScoreDocs)
            {
                var name = searcher.Doc(topDoc.doc).Get("Name");
                Console.WriteLine(name);
            }
            searcher.Close();
            dir.Close();
        }
コード例 #5
0
        public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
                                      double distanceErrorPct = 0.025)
        {
            SpatialOperation spatialOperation;
            var shape = ReadShape(shapeWKT);

            switch (relation)
            {
            case SpatialRelation.Within:
                spatialOperation = SpatialOperation.IsWithin;
                break;

            case SpatialRelation.Contains:
                spatialOperation = SpatialOperation.Contains;
                break;

            case SpatialRelation.Disjoint:
                spatialOperation = SpatialOperation.IsDisjointTo;
                break;

            case SpatialRelation.Intersects:
                spatialOperation = SpatialOperation.Intersects;
                break;

            case SpatialRelation.Nearby:
                // only sort by this, do not filter
                return(new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter())));

            default:
                throw new ArgumentOutOfRangeException("relation");
            }
            var args = new SpatialArgs(spatialOperation, shape)
            {
                DistErrPct = distanceErrorPct
            };

            return(spatialStrategy.MakeQuery(args));
        }
コード例 #6
0
        public static IEnumerable <Document> CreateSearchDocuments(IList <Deal> deals, SpatialStrategy strategy)
        {
            var docs = new List <Document>(deals.Count());
            var ctx  = strategy.GetSpatialContext();

            foreach (var deal in deals)
            {
                foreach (var location in deal.Locations)
                {
                    var doc = new Document();
                    doc.Add(new Field(TitleFieldName, deal.Title, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field(SupplierFieldName, deal.Supplier, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    doc.Add(new Field(LocationNameFieldName, location.Name, Field.Store.YES, Field.Index.NOT_ANALYZED));

                    foreach (var f in strategy.CreateIndexableFields(ctx.MakePoint(location.Latitude, location.Longitude)))
                    {
                        doc.Add(f);
                    }

                    docs.Add(doc);
                }
            }

            return(docs);
        }
コード例 #7
0
 public Param(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
コード例 #8
0
ファイル: SpatialField.cs プロジェクト: ybdev/ravendb
 public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, SpatialIndexQuery spatialQuery)
 {
     return(MakeQuery(existingQuery, spatialStrategy, spatialQuery.QueryShape, spatialQuery.SpatialRelation, spatialQuery.DistanceErrorPercentage, spatialQuery.RadiusUnitOverride));
 }
コード例 #9
0
 /// <summary>
 /// Sets Spatial Searching for Points
 /// </summary>
 /// <param name="locationField"></param>
 internal void SetPointVectorStrategy(string locationField)
 {
     spatialContext  = SpatialContext.GEO;
     spatialStrategy = new PointVectorStrategy(spatialContext, locationField);
 }
コード例 #10
0
 static SpatialIndex()
 {
     maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
     fieldInfo = new SimpleSpatialFieldInfo(Constants.SpatialFieldName);
     strategy  = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(RavenSpatialContext, maxLength));
 }
コード例 #11
0
        private void Indexer_DocumentWriting(LuceneEngine.DocumentWritingEventArgs e, SpatialContext ctx, SpatialStrategy strategy)
        {
            double lat = double.Parse(e.ValueSet.Values["lat"].First().ToString());
            double lng = double.Parse(e.ValueSet.Values["lng"].First().ToString());

            GetXYFromCoords(lat, lng, out var x, out var y);
            Shape geoPoint = ctx.MakePoint(x, y);

            foreach (AbstractField field in strategy.CreateIndexableFields(geoPoint))
            {
                e.Document.Add(field);
            }
        }