// GET: Enquiries/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userId = User.Identity.GetUserId <int>(); Enquiry enquiry = db.Enquiries.Find(id); if (enquiry == null) { return(HttpNotFound()); } if (userId == enquiry.ApplicationUserId || userManager.IsInRole(userId, "Admin") || userManager.IsInRole(userId, "EnquiryManager")) { //let user view the details //get all boundaries for displaying on map SpatialHelper spatial = new SpatialHelper(); ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); return(View(enquiry)); } else { // send user back to the index return(RedirectToAction("Index", "Enquiries")); } }
public void GetGeoJsonFromGeometryTest() { var wkt = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry = DbGeometry.FromText(wkt); SpatialHelper spatialHelper = new SpatialHelper(); var result = spatialHelper.GetGeoJsonFromGeometry(dBGeometry); string expectedResult = "{\"Geometry\":{\"WellKnownText\":\"Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))\"}}"; Assert.AreEqual(result, expectedResult); }
public void SpatialFilterByDistance() { DataAssert.SameSequence( DataAssert.Data.SearchQuery <Listing>() .Where(w => AzureSearchMethods.Distance(w.Place, filterPoint) < 10000).OrderBy(q => q.CreatedAt).ToList(), DataAssert.Data.Memory <Listing>() .Where(w => w.Place != null && SpatialHelper.GetDistance(w.Place, filterPoint, DistanceUnit.Kilometers) < 10000) .OrderBy(q => q.CreatedAt) .ToList() ); }
public void SpatialOrderByDistance() { DataAssert.SameSequence( DataAssert.Data.SearchQuery <Listing>() .Where(q => q.Place != null) .OrderBy(w => AzureSearchMethods.Distance(w.Place, filterPoint)).Take(10).ToList(), DataAssert.Data.Memory <Listing>() .Where(q => q.Place != null) .OrderBy(w => SpatialHelper.GetDistance(w.Place, filterPoint, DistanceUnit.Kilometers)) .Take(10) .ToList() ); }
public void GetGeoJsonListFromArrayTest() { var wkt = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry = DbGeometry.FromText(wkt); var wkt2 = "Polygon((0 0 , 2 0, 2 2, 0 2, 0 0))"; DbGeometry dBGeometry2 = DbGeometry.FromText(wkt2); var geomArray = new DbGeometry[] { dBGeometry, dBGeometry2 }; SpatialHelper spatialHelper = new SpatialHelper(); var result = spatialHelper.GetGeoJsonListFromArray(geomArray); List <string> expectedResult = new List <string>(); expectedResult.Add("{\"Geometry\":{\"WellKnownText\":\"Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))\"}}"); expectedResult.Add("{\"Geometry\":{\"WellKnownText\":\"Polygon((0 0 , 2 0, 2 2, 0 2, 0 0))\"}}"); CollectionAssert.AreEqual(expectedResult, result); }
// GET: Enquiries/Create public ActionResult Create() { UserCreateEditEnquiryViewModel newEnquiry = new UserCreateEditEnquiryViewModel(); newEnquiry.InvoiceEmail = User.Identity.GetUserDefaultInvoicingEmail(); newEnquiry.NoOfYears = 10; newEnquiry.DataUsedFor = "Ecological report"; ViewBag.SearchTypeId = new SelectList(db.SearchTypes, "SearchTypeId", "Name"); //get all boundaries for displaying on map SpatialHelper spatial = new SpatialHelper(); ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); return(View(newEnquiry)); }
public void SpatialOrderByDescendingDistance() { var expect = DataAssert.Data.SearchQuery <Listing>() .Where(q => q.Place != null) .OrderByDescending(w => AzureSearchMethods.Distance(w.Place, filterPoint)).Take(10).ToList(); var actual = DataAssert.Data.Memory <Listing>() .Where(q => q.Place != null) .OrderByDescending(w => SpatialHelper.GetDistance(w.Place, filterPoint, double.MaxValue, DistanceUnit.Kilometers)) .Take(10) .ToList(); DataAssert.SameSequence( expect, actual ); }
protected override void OnUpdate() { var unitCount = _UnitQuery.CalculateEntityCount(); var bucketCount = MapSize.x * MapSize.y; var buckets = new NativeMultiHashMap <uint, Entity>((int)bucketCount, Allocator.TempJob); World.GetOrCreateSystem <UnitMovementSystem>().SetBucketBuffer(buckets); var bucketsPW = buckets.AsParallelWriter(); Entities.ForEach((Entity entity, in LocalToWorld trans, in UnitData data) => { var postion2D = new float2(trans.Position.x, trans.Position.z); var bucketIndex = SpatialHelper.PositionToCellIndex(postion2D, MapSize, BucketSize, default); bucketsPW.Add(bucketIndex, entity); }).WithName("PROP_BOCKETS").ScheduleParallel();
static void Main(string[] args) { DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey); DocumentCollection collection = client.ReadDocumentCollectionAsync(documentCollectionLink).Result; Point point = new Point(-87.636836, 41.884615); int minDistance = 100; int maxDistance = 5000; int maxPoints = 500; IEnumerable <dynamic> points = SpatialHelper.Near(client, collection.DocumentsLink, propertyName, point, minDistance, maxDistance, maxPoints); long count = 0; foreach (dynamic p in points) { Console.WriteLine(@"Point ID: {0}", p.id); ++count; } Console.WriteLine(@"Found {0} points", count); }
// GET: Enquiries/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userId = User.Identity.GetUserId <int>(); Enquiry enquiry = db.Enquiries.Find(id); if (enquiry == null) { return(HttpNotFound()); } if (userId == enquiry.ApplicationUserId || userManager.IsInRole(userId, "Admin") || userManager.IsInRole(userId, "EnquiryManager")) { //do not allow deleting of enquiry if there is an accepted quote if (enquiry.Quotes.Where(q => q.AcceptedDate != null).Count() > 0) { TempData["ErrorMessage"] = "Cannot delete an enquiry that has an accepted quote, please contact us if there is an issue"; // send user back to the index return(RedirectToAction("Index", "Enquiries")); } //let user view the details //get all boundaries for displaying on map SpatialHelper spatial = new SpatialHelper(); ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); return(View(enquiry)); } else { // send user back to the index return(RedirectToAction("Index", "Enquiries")); } }
/// <summary> /// Gets a <see cref="Rectangle"/> that represents the world area that this <see cref="ISpatial"/> occupies. /// </summary> /// <returns>A <see cref="Rectangle"/> that represents the world area that this <see cref="ISpatial"/> /// occupies.</returns> public Rectangle ToRectangle() { return(SpatialHelper.ToRectangle(this)); }
public void GetGeoJsonCollectionFromBoundaryCollectionTestBoundaryTypeAll() { //first boundary coverage area only Boundary boundary1 = new Boundary(); var wkt1 = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry1 = DbGeometry.FromText(wkt1); boundary1.Area = dBGeometry1; boundary1.BoundaryId = 1; boundary1.Name = "boundary1"; boundary1.displayOnMap = false; boundary1.isCoverageArea = true; //second boundary display only Boundary boundary2 = new Boundary(); var wkt2 = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry2 = DbGeometry.FromText(wkt2); boundary2.Area = dBGeometry2; boundary2.BoundaryId = 2; boundary2.Name = "boundary2"; boundary2.displayOnMap = true; boundary2.isCoverageArea = false; //third boundary neither Boundary boundary3 = new Boundary(); var wkt3 = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry3 = DbGeometry.FromText(wkt3); boundary3.Area = dBGeometry3; boundary3.BoundaryId = 3; boundary3.Name = "boundary3"; boundary3.displayOnMap = false; boundary3.isCoverageArea = false; //fourth boundary both Boundary boundary4 = new Boundary(); var wkt4 = "Polygon((0 0 , 1 0, 1 1, 0 1, 0 0))"; DbGeometry dBGeometry4 = DbGeometry.FromText(wkt4); boundary4.Area = dBGeometry4; boundary4.BoundaryId = 4; boundary4.Name = "boundary4"; boundary4.displayOnMap = true; boundary4.isCoverageArea = true; ICollection <Boundary> boundaries = new List <Boundary> { boundary1, boundary2, boundary3, boundary4 }; SpatialHelper spatialHelper = new SpatialHelper(); var result = spatialHelper.GetGeoJsonCollectionFromBoundaryCollection (boundaries, SpatialHelper.BoundaryType.ALL); //TODO set up expected result var expectedResult = ""; Assert.AreEqual(expectedResult, result); }
private List <Annotations> GoGenerateImages(List <IGrouping <string, Annotations> > imagesWithNoCars, List <IGrouping <string, Annotations> > imagesWithLotsOfCars) { var allAnnotations = new List <Annotations>(); var outputAnnotationsDir = Path.GetDirectoryName(_outputAnnotationsFile); var imagesWithNoCarsRandomizedOrder = ListRandomizer.Shuffle(imagesWithNoCars, 42); var imagesWithLotsOfCarsRandomizedorder = ListRandomizer.Shuffle(imagesWithLotsOfCars, 4242); int minOfBoth = Math.Min(imagesWithNoCarsRandomizedOrder.Count, imagesWithLotsOfCarsRandomizedorder.Count); int maxOfBoth = Math.Max(imagesWithNoCarsRandomizedOrder.Count, imagesWithLotsOfCarsRandomizedorder.Count); for (int i = 0; i < maxOfBoth; i++) { var iNoCars = i % imagesWithNoCarsRandomizedOrder.Count; var iLotsOfCars = i % imagesWithLotsOfCarsRandomizedorder.Count; var noCarImageTags = imagesWithNoCarsRandomizedOrder[iNoCars]; var lotsOfCarImageTags = imagesWithLotsOfCarsRandomizedorder[iLotsOfCars]; var imagePathNoCars = Path.Combine(_dirOfAnnotationsFile, noCarImageTags.Key); var imagePathNoCarsResolved = PathHelper.EscapePathCorrectly(Path.GetFullPath(imagePathNoCars)); var imagePathLotsOfCars = Path.Combine(_dirOfAnnotationsFile, lotsOfCarImageTags.Key); var imagePathLotsOfCarsResolved = PathHelper.EscapePathCorrectly(Path.GetFullPath(imagePathLotsOfCars)); using (var imageNoCars = Image.Load(imagePathNoCarsResolved)) { using (var imageWithCars = Image.Load(imagePathLotsOfCarsResolved)) { foreach (var carImageTags in lotsOfCarImageTags) { var rectangle = SpatialHelper.BoxToRectangle(carImageTags.X1.Value, carImageTags.Y1.Value, carImageTags.X2.Value, carImageTags.Y2.Value); var cloneOfImageWithCars = imageWithCars.Clone(); cloneOfImageWithCars.Mutate(t => t.Crop(rectangle)); imageNoCars.Mutate(t => t.DrawImage(cloneOfImageWithCars, new Point(rectangle.X, rectangle.Y), GraphicsOptions.Default)); } } var outFileName = $"Generated_{i}.jpg"; var outPath = Path.Combine(_outputDirImages, outFileName); using (var outStream = new FileStream(outPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { Console.WriteLine($"\tStoring: {outFileName}"); imageNoCars.SaveAsJpeg(outStream); } foreach (var existingTag in lotsOfCarImageTags) { var newTag = new Annotations() { Tag = existingTag.Tag, ImagePath = PathHelper.EscapePathCorrectly(Path.GetRelativePath(outputAnnotationsDir, outPath)), X1 = existingTag.X1, X2 = existingTag.X2, Y1 = existingTag.Y1, Y2 = existingTag.Y2 }; allAnnotations.Add(newTag); } } } return(allAnnotations); }
public ActionResult Edit([Bind(Include = "Code, EnquiryId,Name,InvoiceEmail,SearchAreaWkt,SearchTypeId" + ",NoOfYears,EstimatedCost,JobNumber,Agency,AgencyContact,DataUsedFor,Citations,GisKml,Express,EnquiryDate" + ",Comment,AddedToRersDate, DataCleanedDate, ReportCompleteDate, DocumentsCleanedDate, EnquiryDeliveredDate" + ", AdminComment, RowVersion")] UserCreateEditEnquiryViewModel model) { SpatialHelper spatial = new SpatialHelper(); ViewBag.SearchTypeId = new SelectList(db.SearchTypes, "SearchTypeId", "Name", model.SearchTypeId); //get all boundaries for displaying on map ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); if (ModelState.IsValid) { DbGeometry geom = DbGeometry.FromText(model.SearchAreaWkt, 27700); var user = User.Identity.GetAppUser(); var userId = User.Identity.GetIntUserId(); Enquiry enquiry = new Enquiry { Code = model.Code, EnquiryId = model.EnquiryId, ApplicationUserId = userId, Name = model.Name, InvoiceEmail = model.InvoiceEmail, SearchArea = geom, SearchTypeId = model.SearchTypeId, NoOfYears = model.NoOfYears, EstimatedCost = model.EstimatedCost, JobNumber = model.JobNumber, Agency = model.Agency, AgencyContact = model.AgencyContact, DataUsedFor = model.DataUsedFor, Citations = model.Citations, GisKml = model.GisKml, Express = model.Express, Comment = model.Comment, AddedToRersDate = model.AddedToRersDate, DataCleanedDate = model.DataCleanedDate, ReportCompleteDate = model.ReportCompleteDate, DocumentsCleanedDate = model.DocumentsCleanedDate, EnquiryDeliveredDate = model.EnquiryDeliveredDate, AdminComment = model.AdminComment, RowVersion = model.RowVersion }; try { db.Entry(enquiry).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException) { ViewBag.Message = "Sorry, couldn't update due to a concurrency issue <br />Please try again"; return(View(model)); } catch (DbEntityValidationException ex) { foreach (var result in ex.EntityValidationErrors) { foreach (var error in result.ValidationErrors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } } return(View(model)); } } return(View(model)); }
// GET: Enquiries/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userId = User.Identity.GetUserId <int>(); Enquiry enquiry = db.Enquiries.Include(e => e.Invoice) .Include(q => q.Quotes).FirstOrDefault(e => e.EnquiryId == id); if (enquiry == null) { return(HttpNotFound()); } if (userId == enquiry.ApplicationUserId || userManager.IsInRole(userId, "Admin") || userManager.IsInRole(userId, "EnquiryManager")) { //do not allow editing of enquiry if there are quotes if (enquiry.Quotes.Count > 0) { if (enquiry.Quotes.Where(q => q.AcceptedDate != null).Count() > 0) { TempData["ErrorMessage"] = "Cannot edit an enquiry that has an accepted quote, please contact us if there is an issue"; } else { TempData["ErrorMessage"] = "Cannot edit an enquiry that has been quoted, please delete all quotes for this enquiry and try again"; } // send user back to the index return(RedirectToAction("Index", "Enquiries")); } FormatHelper formatHelper = new FormatHelper(); var wkt = enquiry.SearchArea.WellKnownValue.WellKnownText; UserCreateEditEnquiryViewModel userCreateEditEnquiryViewModel = new UserCreateEditEnquiryViewModel { Code = enquiry.Code, EnquiryId = enquiry.EnquiryId, Name = enquiry.Name, InvoiceEmail = enquiry.InvoiceEmail, SearchAreaWkt = wkt, SearchTypeId = enquiry.SearchTypeId, NoOfYears = enquiry.NoOfYears, EstimatedCost = enquiry.EstimatedCost, JobNumber = enquiry.JobNumber, Agency = enquiry.Agency, AgencyContact = enquiry.AgencyContact, DataUsedFor = enquiry.DataUsedFor, Citations = enquiry.Citations, GisKml = enquiry.GisKml, Express = enquiry.Express, Comment = enquiry.Comment, AddedToRersDate = enquiry.AddedToRersDate, DataCleanedDate = enquiry.DataCleanedDate, ReportCompleteDate = enquiry.ReportCompleteDate, DocumentsCleanedDate = enquiry.DocumentsCleanedDate, EnquiryDeliveredDate = enquiry.EnquiryDeliveredDate, AdminComment = enquiry.AdminComment, RowVersion = enquiry.RowVersion }; ViewBag.SearchTypeId = new SelectList(db.SearchTypes, "SearchTypeId", "Name", userCreateEditEnquiryViewModel.SearchTypeId); //get all boundaries for displaying on map SpatialHelper spatial = new SpatialHelper(); ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); return(View(userCreateEditEnquiryViewModel)); } else { // send user back to the index return(RedirectToAction("Index", "Enquiries")); } }
public ActionResult Create([Bind(Include = "Code, EnquiryId,Name,InvoiceEmail,SearchAreaWkt,SearchTypeId,NoOfYears,EstimatedCost,JobNumber,Agency,AgencyContact,DataUsedFor,Citations,GisKml,Express,EnquiryDate,Comment")] UserCreateEditEnquiryViewModel model) { if (ModelState.IsValid) { DbGeometry geom = DbGeometry.FromText(model.SearchAreaWkt, 27700); //(EPSG:27700) is OSGB, (EPSG:3857) google maps geometric, wgs84 (EPSG:4326) google geographic var defaultInvoiceEmail = User.Identity.GetUserDefaultInvoicingEmail(); var user = User.Identity.GetAppUser(); var userId = User.Identity.GetIntUserId(); if (model.InvoiceEmail != null) { defaultInvoiceEmail = model.InvoiceEmail; } Enquiry enquiry = new Enquiry { Code = model.Code, ApplicationUserId = userId, Name = model.Name, InvoiceEmail = defaultInvoiceEmail, SearchArea = geom, SearchTypeId = model.SearchTypeId, EstimatedCost = model.EstimatedCost, NoOfYears = model.NoOfYears, JobNumber = model.JobNumber, Agency = model.Agency, AgencyContact = model.AgencyContact, DataUsedFor = model.DataUsedFor, Citations = model.Citations, GisKml = model.GisKml, Express = model.Express, Comment = model.Comment, }; db.Enquiries.Add(enquiry); try { db.SaveChanges(); FormatHelper formatHelper = new FormatHelper(); var enquiryCode = formatHelper.GetEnquiryCodePrefix(enquiry.EnquiryId); enquiry.Code = enquiryCode; db.Entry(enquiry).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException ex) { foreach (var result in ex.EntityValidationErrors) { foreach (var error in result.ValidationErrors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } } return(View(model)); } } ViewBag.DefaultInvoiceEmail = User.Identity.GetUserDefaultInvoicingEmail(); ViewBag.SearchTypeId = new SelectList(db.SearchTypes, "SearchTypeId", "Name", model.SearchTypeId); //get all boundaries for displaying on map SpatialHelper spatial = new SpatialHelper(); ViewBag.Boundaries = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.DISPLAY); ViewBag.Coverage = spatial.GetGeoJsonCollectionFromBoundaryCollection(db.Boundaries.ToList(), SpatialHelper.BoundaryType.COVERAGE); return(View(model)); }