public bool IsValidGroupZone(List <int> listZoneId, int brandId, int type) { bool result = false; var groupZones = _unitOfWork.Repository <GroupZone>().GetAll().Where(x => x.BrandId == brandId).Select(x => x.Geom).ToList(); List <Geometry> geoms; if (type == (int)GroupZoneType.Ward) { geoms = _unitOfWork.Repository <Ward>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList(); } else if (type == (int)GroupZoneType.District) { geoms = _unitOfWork.Repository <District>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList(); } else { geoms = _unitOfWork.Repository <SystemZone>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList(); } Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null; if (IsDuplicateWardInGroupZone(groupZones, geoms) && IsIntersectWard(geoms)) { result = true; } return(result); }
public async Task <IActionResult> Register([FromBody] UserDto userDto) { try { // save ApplicationUser user = new ApplicationUser(); user.UserName = userDto.UserName; //user.PhoneNumber = userDto.UserName; user.Email = userDto.Email; user.Location = GeoJsonHelper.GetJsonPoint(userDto.Location.Latitude, userDto.Location.Longitude); IdentityResult result = await UserManager.CreateAsync(user, userDto.Password); if (result.Succeeded) { return(Ok()); } else { return(Ok(result.Errors)); } } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <WardWithDistrict> GetWardIdByLocation(string coordinateString) { Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); geom.SRID = 4326; geom = geom.Buffer(-0.0000261); WardWithDistrict result = null; try { var ward = await _unitOfWork.Repository <Ward>().GetAll().Where(x => x.Geom.Contains(geom)).FirstOrDefaultAsync(); if (ward != null && CheckSystemzone(geom)) { result = new WardWithDistrict() { Id = ward.Id, Name = ward.Name, DistrictName = ward.District?.Name }; } return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Ward Id by Location error", e.InnerException?.Message); } }
public async Task <CustomFeatureCollection> GetWardForMap(string coordinateString) { try { var result = new CustomFeatureCollection(); Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); geom.SRID = 4326; var wards = await _unitOfWork.Repository <Ward>().GetAll().Where(x => geom.Contains(x.Geom)).ToListAsync(); foreach (var item in wards) { Feature ft = new Feature { Geometry = item.Geom }; ft.Properties.F3 = item.Id; ft.Properties.F2 = item.Name; result.Features.Add(ft); } return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get boundary wards Error!!!", e.InnerException?.Message); } }
public async Task <ListStreetSegmentResponse> GetStreetSegmentInRadius(string coor) { Geometry geom = null; var radius = _unitOfWork.Repository <Config>().GetAll().Where(x => x.Active && x.Name.Equals("BuildingRadius")).Select(x => x.Value).FirstOrDefault();// unit: meter StreetSegmentRadius try { geom = GeoJsonHelper.ParseStringToGeoMetry(coor); // s = c0/360; c0 = 40075.017 var list = await _unitOfWork.Repository <StreetSegment>().GetAll().Where(x => (x.Geom.Distance(geom) * 40075.017 * 1000 / 360) <= radius).Select(x => new StreetSegmentResponse { Name = x.Name, Geom = x.Geom, CreateDate = x.CreateDate, ModifyDate = x.ModifyDate, WardId = x.WardId, Id = x.Id }).ToListAsync(); return(new ListStreetSegmentResponse { ListStreetSegment = list }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Street Segment by Building Location Error!!!", e.InnerException?.Message); } }
public async Task <Geometry> CheckSystemZoneClose(int wardId) { var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.WardId == wardId).Select(x => x.Geom).ToListAsync(); var reuslt = GeoJsonHelper.CombineGeoCollection(systemzones); return(reuslt); }
public async Task <bool> CheckStoreInSystemzoneAsync(Guid accountId, string coordinateString) { var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.AccountId == accountId).ToListAsync(); Geometry geom = GeoJsonHelper.ParseStringToPoint(coordinateString); var intersects = systemzones.Any(x => x.Geom.Intersects(geom)); return(intersects); }
public async Task <CheckBuidlingResponse> CheckBuildingInCampus(string coordinateString, Guid id) { Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); CheckBuidlingResponse result = new CheckBuidlingResponse(); bool isValid = true; try { var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.AccountId == id).ToListAsync(); var isInSystemzone = systemzones.Any(x => x.Geom.Contains(geom)); var isValidBuilding = !_unitOfWork.Repository <Building>().GetAll().Any(x => x.Geom.Intersects(geom)); isValid = isValidBuilding && isInSystemzone; if (isValid) { result.IsValid = true; var campus = await _unitOfWork.Repository <Campus>().GetAll() .Where(x => x.Geom.Contains(geom)) .Select(x => new CheckBuidlingResponse { Id = x.Id, Name = x.Name }) .FirstOrDefaultAsync(); if (campus != null) { result.Name = campus.Name; result.Id = campus.Id; } else { var isIntersect = _unitOfWork.Repository <Campus>().GetAll() .Any(x => x.Geom.Intersects(geom)); if (isIntersect) { return(null); } else { result.Id = -1; } } } else { return(null); } return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Check Building in Campus error", e.InnerException?.Message); } }
public async Task <bool> CheckSystemzoneFillWard(int wardId) { var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.WardId == wardId).Select(x => x.Geom).ToListAsync(); var wardGeom = await _unitOfWork.Repository <Ward>().GetAll().Where(x => x.Id == wardId).Select(x => x.Geom).SingleOrDefaultAsync(); var systemzonesGeom = GeoJsonHelper.CombineGeoCollection(systemzones); double percent = systemzonesGeom.Area / wardGeom.Area; if (percent > 0.98 && percent < 1.02) { return(true); } return(false); }
public async Task <StoreResponse> GetStoreOrder(int brandId, string coordinateString, DateTime timeOrder, int dateOrder) { var timeInMinute = (timeOrder.Hour * 60) + timeOrder.Minute; var timeSlot = (int)timeInMinute / (60 * 6); // 6 is 1 timeslot var tradezoneVer = await _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => x.IsActive == true && x.BrandId == brandId).FirstOrDefaultAsync(); if (!tradezoneVer.TimeSlot.ElementAt(timeSlot).Equals('1')) { return(null); } var dateInVersion = Convert.ToString(tradezoneVer.DateFilter, 2).PadLeft(7, '0'); if (!dateInVersion.ElementAt(dateOrder).Equals('1')) { return(null); } if (!(tradezoneVer is null)) { var location = GeoJsonHelper.ParseStringToPoint(coordinateString); var tradezone = tradezoneVer.TradeZones; var result = tradezone.Where(x => x.Geom.Intersects(location)).FirstOrDefault(); if (result != null) { return(new StoreResponse { Name = result.StoreTradeZones.ElementAt(0).Store.Name, Address = result.StoreTradeZones.ElementAt(0).Store.Address, BrandName = result.StoreTradeZones.ElementAt(0).Store.Brand?.Name, CreateDate = result.StoreTradeZones.ElementAt(0).Store.CreateDate, Geom = result.StoreTradeZones.ElementAt(0).Store.Geom, Id = result.StoreTradeZones.ElementAt(0).Store.Id, BrandId = result.StoreTradeZones.ElementAt(0).Store.BrandId, ImageUrl = result.StoreTradeZones.ElementAt(0).Store.ImageUrl, Type = result.StoreTradeZones.ElementAt(0).Store.Brand?.Segment?.Name, Status = result.StoreTradeZones.ElementAt(0).Store.Status, AbilityToServe = result.StoreTradeZones.ElementAt(0).Store.AbilityToServe, TimeSlot = result.StoreTradeZones.ElementAt(0).Store.TimeSlot }); } else { return(null); } }
public bool CheckCampus(string coordinateString) { Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); bool isValid = true; try { isValid = !_unitOfWork.Repository <Campus>().GetAll().Any(x => x.Geom.Intersects(geom)); if (isValid) { isValid = !_unitOfWork.Repository <Building>().GetAll().Any(x => x.Geom.Intersects(geom.Boundary)); } return(isValid); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Check New Campus error", e.InnerException?.Message); } }
public async Task <CustomFeatureCollection> GetStoreForMap(string coordinateString, int role) { try { Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); CustomFeatureCollection result = new CustomFeatureCollection(); geom.SRID = 4326; dynamic stores; if (role == 0 || role == 2) { stores = await _unitOfWork.Repository <Store>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status != (int?)Status.Deleted && x.Status != (int?)Status.Reject && x.Status != (int?)Status.WaitingUpdate && x.FloorAreaId == null). Select(x => new { x.Geom, SegmentName = x.Brand.Segment.Name, x.Id, x.Status, x.Name }).AsNoTracking() .ToListAsync(); } else { stores = await _unitOfWork.Repository <Store>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status == (int?)Status.Surveyed || x.Status == (int?)Status.WaitingUpdate) .Select(x => new { x.Geom, SegmentName = x.Brand.Segment.Name, x.Id, x.Status, x.Name }).AsNoTracking() .ToListAsync(); } foreach (var item in stores) { Feature ft = new Feature { Geometry = item.Geom }; ft.Properties.F1 = item.SegmentName; ft.Properties.F2 = item.Name; ft.Properties.F4 = item.Id; ft.Properties.F3 = item.Status; result.Features.Add(ft); } return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Store Error!!!", e.InnerException?.Message); } }
public async Task <CustomFeatureCollection> GetBuildingForMap(string coordinateString, int role) { try { Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString); CustomFeatureCollection result = new CustomFeatureCollection(); geom.SRID = 4326; dynamic buildings; // List<Building> buildings = null; if (role == 0 || role == 2) { buildings = await _unitOfWork.Repository <Building>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status != (int?)Status.Deleted && x.Status != (int?)Status.WaitingUpdate && x.Status != (int?)Status.Reject).Select(x => new { x.Name, Type = x.Type.Name, x.Status, x.Id, x.Geom }).AsNoTracking().ToListAsync(); } else { buildings = await _unitOfWork.Repository <Building>().GetAll().Where(x => geom.Contains(x.Geom) && (x.Status == (int?)Status.Surveyed || x.Status == (int?)Status.WaitingUpdate)).Select(x => new { x.Name, Type = x.Type.Name, x.Status, x.Id, x.Geom }).AsNoTracking().ToListAsync(); } foreach (var item in buildings) { Feature ft = new Feature { Geometry = item.Geom, }; ft.Properties.F1 = item.Type; ft.Properties.F2 = item.Name; ft.Properties.F3 = item.Status; ft.Properties.F4 = item.Id; ft.Properties.F5 = item.Geom.Centroid.AsText(); result.Features.Add(ft); } return(result); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get building Error!!!", e.InnerException?.Message); } }
public async Task <GroupZoneResponse> PostGroupZone(GroupZoneRequest model, int brandId) { try { List <Geometry> geoms; if (model.Type == (int)GroupZoneType.Ward) { geoms = await _unitOfWork.Repository <Ward>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } else if (model.Type == (int)GroupZoneType.District) { geoms = await _unitOfWork.Repository <District>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } else { geoms = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null; var insertItem = new GroupZone() { BrandId = brandId, Geom = groupZoneGeom, Name = model.Name, }; await _unitOfWork.Repository <GroupZone>().InsertAsync(insertItem); await _unitOfWork.CommitAsync(); return(new GroupZoneResponse() { Id = insertItem.Id, Geom = insertItem.Geom, BrandId = insertItem.BrandId, Name = insertItem.Name }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Insert Groupzone Error!!!", e.InnerException?.Message); } }
public async Task <List <BuildingDetailResponse> > GetBuildingByStoreLocation(string coor, float radius) { Geometry geom = null; // unit: meter try { geom = GeoJsonHelper.ParseStringToPoint(coor); // s = c0/360; c0 = 40075.017 return(await _unitOfWork.Repository <Building>().GetAll().Where(x => (x.Geom.Distance(geom) * 40075.017 * 1000 / 360) <= radius && x.Status == (int)Status.Surveyed).Select(x => new BuildingDetailResponse { Id = x.Id, Name = x.Name, Geom = x.Geom, NumberOfFloor = x.NumberOfFloor, Active = x.Active, CampusId = x.CampusId, CreateDate = x.CreateDate, ImageUrl = x.ImageUrl, Type = x.Type.Name, Address = x.Address, Status = x.Status, ReferenceId = x.ReferenceId, BuildingStreetSegments = new List <BuidingStreetSegmentResponse>(x.BuildingStreetSegments.Select(b => new BuidingStreetSegmentResponse { BuildingId = b.BuidingId, StreetSegmentId = b.StreetSegmentId })), ReferencrName = x.ReferenceId != null ? x.Reference.Name : null, Floors = new List <FloorResopnse>(x.Floors.Select(f => new FloorResopnse { Id = f.Id, BuildingId = f.BuildingId, FloorNumber = f.FloorNumber, Name = f.Name, FloorAreas = new List <FloorAreaResopnse>(f.FloorAreas.Select(a => new FloorAreaResopnse { Id = a.Id, FloorId = a.FloorId, Name = a.Name, Stores = new List <StoreResponse>(a.Stores.Select(s => new StoreResponse { Name = s.Name, Address = s.Address, FloorAreaName = s.FloorArea != null ? s.FloorArea.Name : null, BrandName = s.Brand != null ? s.Brand.Name : null, CreateDate = s.CreateDate, Geom = s.Geom, Id = s.Id, FloorAreaId = s.FloorAreaId, BrandId = s.BrandId, ImageUrl = s.ImageUrl, Type = s.Brand.Segment.Name, Status = s.Status, ReferenceId = s.ReferenceId, AbilityToServe = s.AbilityToServe, TimeSlot = s.TimeSlot })) })) })) }).ToListAsync()); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Building by Store Location Error!!!", e.InnerException?.Message); } }
public async Task <StoreResponse> PostStore(Guid accountId, PostStoresRequest model) { var myGeom = GeoJsonHelper.ParseStringToPoint(model.CoordinateString); Store insert = new Store { Name = model.Name, TimeSlot = model.TimeSlot, CreateDate = DateTime.UtcNow.AddHours(7), BrandId = model.BrandId, Geom = myGeom, Address = model.Address, Status = (int?)Status.NeedApproval, AbilityToServe = model.AbilityToServe, ImageUrl = model.ImageUrl }; if (model.FloorAreaId > 0) { insert.FloorAreaId = model.FloorAreaId; } try { await _unitOfWork.Repository <Store>().InsertAsync(insert); await _unitOfWork.CommitAsync(); List <StoreStreetSegmentResponse> storeStreetSegmentResponses = new List <StoreStreetSegmentResponse>(); if (model.StreetSegmentIds != null) { foreach (var item in model.StreetSegmentIds) { StoreStreetSegment storeStreetSegment = new StoreStreetSegment { StoreId = insert.Id, StreetSegmentId = item }; await _unitOfWork.Repository <StoreStreetSegment>().InsertAsync(storeStreetSegment); await _unitOfWork.CommitAsync(); storeStreetSegmentResponses.Add(new StoreStreetSegmentResponse { StoreId = storeStreetSegment.StoreId, StreetSegmentId = storeStreetSegment.StreetSegmentId }); } } await _unitOfWork.Repository <History>().InsertAsync(new History { AccountId = accountId, Action = (int)ActionEnum.ActionSurvey.InsertStore, CreateDate = DateTime.UtcNow.AddHours(7), StoreId = insert.Id, }); await _unitOfWork.CommitAsync(); return(new StoreResponse { Name = insert.Name, Address = insert.Address, FloorAreaName = insert.FloorArea?.Name, BrandName = insert.Brand?.Name, CreateDate = insert.CreateDate, Geom = insert.Geom, Id = insert.Id, FloorAreaId = insert.FloorAreaId, StoreStreetSegments = storeStreetSegmentResponses, BrandId = insert.BrandId, ImageUrl = insert.ImageUrl, Status = insert.Status, TimeSlot = insert.TimeSlot, }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Insert Store Error!!!", e.InnerException?.Message); } }
/// <summary> /// This will convert geometry and project it from sourceEpsg to EPSG 4326 /// </summary> /// <param name="geometry"></param> /// <param name="pStart"></param> /// <returns></returns> public static string ToGeoJson(this System.Data.Entity.Spatial.DbGeometry geometry, ProjectionInfo pStart) { geometry = geometry.MakeValid(); return(GeoJsonHelper.ToGeoJson(geometry, pStart, Definitions.WorldProjection)); }
public void CheckViolation() { var redis = _redisClientsManager.GetClient(); var assets = redis.GetAllKeys(); foreach (var item in assets) { bool isEnd = false; bool isStart = false; var currentAsset = redis.Get <AssetRedis>(item); ViolationLog log = new ViolationLog() { AssetId = currentAsset.Id, Description = "Test", Severity = 1, TypeViolation = 1 }; Geometry locationGeometry = null; if (currentAsset.Location.Contains(",")) { locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location); } else { locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location); } var tradeZones = _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => x.BrandId == currentAsset.BrandId && x.IsActive == true).Select(x => x.TradeZones).SingleOrDefault(); var tradezone = tradeZones.Where(x => x.StoreTradeZones.Any(x => x.StoreId == currentAsset.StoreId)).FirstOrDefault(); if (!(tradezone is null)) { log.Geom = locationGeometry.Difference(tradezone.Geom); string[] points = currentAsset.Location.Split(", "); for (int i = 0; i < points.Length; i++) { var point = GeoJsonHelper.ParseStringToPoint(points.ElementAt(i)); if (!tradezone.Geom.Intersects(point)) { if (!isStart) { log.StartTime = currentAsset.StartTime.AddSeconds(3 * i); isStart = true; } else { isEnd = true; log.EndTime = currentAsset.StartTime.AddSeconds(3 * i); } } } if (isStart) { if (!isEnd) { log.EndTime = log.StartTime; } _unitOfWork.Repository <ViolationLog>().Insert(log); _unitOfWork.Commit(); } } } }
public static string ToGeoJson(this System.Data.Entity.Spatial.DbGeometry geometry) { return(GeoJsonHelper.ToGeoJson(geometry)); }