示例#1
0
 /// <summary>
 /// Inserts a new spot into the db.
 /// </summary>
 /// <param name="spot">The spot to add.</param>
 /// <returns>true if the spot is valid and successfully added.</returns>
 public bool Insert(Spot spot)
 {
     if (spot.Validate())
     {
         spot.SpotID = ObjectId.GenerateNewId();
         SafeModeResult result = Spots.Insert(spot);
         return true;
     }
     else return false;
 }
示例#2
0
        public JsonResult GetBySponsor(ObjectId id)
        {
            var spots = Context.SponsorSpots.GetSpotsBySponsors(id);

            Clipper clipper = new Clipper();
            var polygons = new List<List<IntPoint>>();
            var scale = 100000000.0;

            foreach (var spot in spots)
            {
                var polygon = new List<IntPoint>();

                foreach (var coord in spot.SpotShape)
                {
                    polygon.Add(new IntPoint(coord.Longitude * scale, coord.Latitude * scale));
                }
                polygons.Add(polygon);
            }

            var solution = new List<List<IntPoint>>();

            clipper.AddPaths(polygons, PolyType.ptSubject, true);
            clipper.Execute(ClipType.ctUnion, solution,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            var results = new List<Spot>();

            foreach (var shape in solution)
            {
                var resultShape = new Spot();
                foreach (var item in shape)
                {
                    resultShape.SpotShape.Add(new Coordinate { Latitude = item.Y / scale, Longitude = item.X / scale });
                }
                results.Add(resultShape);
            }

            return Json(new { success = true, results = results }, JsonRequestBehavior.AllowGet);
        }
示例#3
0
        public JsonResult UploadSpots(ObjectId id, HttpPostedFileBase shapeFile)
        {
            bool success = true;

            try
            {
                dynamic file = LoadFile(shapeFile);

                if (file != null)
                {
                    // remove old parcels
                    Context.Spots.DeleteByPhaseID(id);

                    // add the new parcels
                    List<Spot> spots = new List<Spot>();

                    foreach (var feature in file.features)
                    {
                        Spot spot = new Spot()
                        {
                            PhaseID = id
                        };

                        foreach (var coord in feature.geometry.coordinates[0])
                        {
                            spot.SpotShape.Add(new Coordinate { Latitude = coord[0], Longitude = coord[1] });
                        }

                        spots.Add(spot);
                    }

                    success = Context.Spots.InsertBatch(spots);
                }
            }
            catch { success = false; }

            return Json(new { success = success });
        }
示例#4
0
 public bool SaveSpot(Spot spot)
 {
     var result = Spots.Save(spot, new MongoInsertOptions { WriteConcern = WriteConcern.Acknowledged });
     return true;
 }