Пример #1
0
        private void AddPoint(IndexWriter writer, String name, double lat, double lng)
        {
            Document doc = new Document();

            doc.Add(new Field("name", name, Field.Store.YES, Field.Index.ANALYZED));

            // convert the lat / long to lucene fields
            doc.Add(new Field(LatField, NumericUtils.DoubleToPrefixCoded(lat), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(LngField, NumericUtils.DoubleToPrefixCoded(lng), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add a default meta field to make searching all documents easy
            doc.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = _ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = _ctps[i];
                var boxId = ctp.GetTierBoxId(lat, lng);
                doc.Add(new Field(ctp.GetTierFieldName(),
                                  NumericUtils.DoubleToPrefixCoded(boxId),
                                  Field.Store.YES,
                                  Field.Index.NOT_ANALYZED_NO_NORMS));
            }
            writer.AddDocument(doc);
        }
Пример #2
0
        public void AddPoint(int id, string name, double lat, double lng, IndexWriter currentWriter)
        {
            EnsureDistanceMatrixReady();
            var      writer = currentWriter != null ? currentWriter : MakeWriter(true, IndexWriter.MaxFieldLength.UNLIMITED);
            Document doc    = new Document();

            doc.Add(new Field("name", name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("PostID", Convert.ToString(id), Field.Store.YES, Field.Index.UN_TOKENIZED));

            // convert the lat / long to lucene fields
            doc.Add(new Field(LatField, NumericUtils.DoubleToPrefixCoded(lat), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(LngField, NumericUtils.DoubleToPrefixCoded(lng), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // add a default meta field to make searching all documents easy
            doc.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = _ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = _ctps[i];
                var boxId = ctp.GetTierBoxId(lat, lng);
                doc.Add(new Field(ctp.GetTierFieldName(),
                                  NumericUtils.DoubleToPrefixCoded(boxId),
                                  Field.Store.YES,
                                  Field.Index.NOT_ANALYZED_NO_NORMS));
            }
            writer.AddDocument(doc);

            if (currentWriter == null)             // if we're not using the passed along writer, which is supposed to be terminated by the caller, then end our new writer
            {
                FinishWriter(writer);
            }
        }
        public void Set(string name, object value, Document document, Field.Store store, Field.Index index, float?boost)
        {
            var service  = (Service)value;
            var location = service.Location;
            var lat      = new Field("Location_Latitude", NumericUtils.DoubleToPrefixCoded(location.Y), Field.Store.YES, Field.Index.NOT_ANALYZED);
            var lng      = new Field("Location_Longitude", NumericUtils.DoubleToPrefixCoded(location.X), Field.Store.YES, Field.Index.NOT_ANALYZED);

            document.Add(lat);
            document.Add(lng);

            document.Add(new Field("metafile", "doc", Field.Store.YES, Field.Index.ANALYZED));

            int ctpsize = Ctps.Count;

            for (int i = 0; i < ctpsize; i++)
            {
                CartesianTierPlotter ctp = Ctps[i];
                var boxId = ctp.GetTierBoxId(location.Y, location.X);
                document.Add(new Field(ctp.GetTierFieldName(), NumericUtils.DoubleToPrefixCoded(boxId), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
            }
        }
        public Shape GetBoxShape(double latitude, double longitude, double miles)
        {
            if (miles < MilesFloor)
            {
                miles = MilesFloor;
            }
            //Rectangle box = DistanceUtils.GetInstance().GetBoundary(latitude, longitude, miles);
            LLRect box1 = LLRect.CreateBox(new FloatLatLng(latitude, longitude), miles, miles);
            LatLng ll   = box1.GetLowerLeft();
            LatLng ur   = box1.GetUpperRight();

            double latY   = ur.GetLat();
            double latX   = ll.GetLat();
            double longY  = ur.GetLng();
            double longX  = ll.GetLng();
            double longX2 = 0.0;

            if (ur.GetLng() < 0.0 && ll.GetLng() > 0.0)
            {
                longX2 = ll.GetLng();
                longX  = -180.0;
            }
            if (ur.GetLng() > 0.0 && ll.GetLng() < 0.0)
            {
                longX2 = ll.GetLng();
                longX  = 0.0;
            }

            var ctp     = new CartesianTierPlotter(2, _projector, _tierPrefix);
            int bestFit = ctp.BestFit(miles);

            ctp = new CartesianTierPlotter(bestFit, _projector, _tierPrefix);

            var shape = new Shape(ctp.GetTierFieldName());

            // generate shape
            // iterate from startX->endX
            // iterate from startY -> endY
            // shape.add(currentLat.currentLong);

            shape = GetShapeLoop(shape, ctp, latX, longX, latY, longY);
            if (longX2 != 0.0)
            {
                if (longX2 != 0.0)
                {
                    if (longX == 0.0)
                    {
                        longX = longX2;
                        longY = 0.0;
                        shape = GetShapeLoop(shape, ctp, latX, longX, latY, longY);
                    }
                    else
                    {
                        longX = longX2;
                        longY = -180.0;
                        shape = GetShapeLoop(shape, ctp, latY, longY, latX, longX);
                    }
                }
            }

            return(shape);
        }