/// <summary> /// Get the list of devices in a specific radius /// </summary> /// <param name="pointLocation">Geolocation</param> /// <param name="radius">Radius in km</param> /// <param name="includeDisabled">Include devices where Enabled = false</param> /// <returns></returns> public async Task <IEnumerable <DeviceModel> > GetDevicesNearby(Geolocation pointLocation, double radius, bool includeDisabled) { IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync(p => (includeDisabled || p.Enabled) && p.IoTDevice, p => new DeviceDAO() { Id = p.Id, Geolocation = p.Geolocation } ); List <DeviceDAO> output = new List <DeviceDAO>(); GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(pointLocation); if (devices != null) { foreach (DeviceDAO deviceObj in devices) { if (deviceObj.Geolocation != null) { if (RadiusHelper.IsWithinRadius(deviceObj.Geolocation, daoGeocodeCenterPoint, radius)) { output.Add(deviceObj); } } } } return(_mapper.Map <IEnumerable <DeviceModel> >(output)); }
/// <summary> /// Get the list of devices in a specific radius /// </summary> /// <param name="deviceGeolocationObj">DeviceGeolocationModel</param> /// <returns>List of device ids</returns> public async Task <IEnumerable <Guid> > GetDevicesInRadius(DeviceGeolocationModel deviceGeolocationObj) { IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync( p => p.Enabled && ((!string.IsNullOrEmpty(deviceGeolocationObj.DeviceType) && p.DeviceType.ToLower() == deviceGeolocationObj.DeviceType.ToLower()) || (string.IsNullOrEmpty(deviceGeolocationObj.DeviceType))), p => new DeviceDAO() { Id = p.Id, Geolocation = p.Geolocation } ); List <Guid> output = new List <Guid>(); GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(deviceGeolocationObj.ResponseGeolocationPointLocation); if (devices != null) { foreach (DeviceDAO deviceObj in devices) { if (deviceObj.Geolocation != null) { if (RadiusHelper.IsWithinRadius(deviceObj.Geolocation, daoGeocodeCenterPoint, deviceGeolocationObj.Radius)) { output.Add(new Guid(deviceObj.Id)); } } } } return(output); }
/// <summary> /// Get a list of Event Clusters in a specific geolocation radius /// </summary> /// <param name="eventClusterGeolocationObj">EventClusterGeolocationModel</param> /// <returns>List of Event Clusters Ids</returns> public async Task <IEnumerable <Guid> > GetClustersInRadius(EventClusterGeolocationModel eventClusterGeolocationObj) { if (eventClusterGeolocationObj == null || eventClusterGeolocationObj.ResponseGeolocationPointLocation == null) { return(new List <Guid>()); } IEnumerable <EventClusterDAO> eventClusters = await _repoEventClusters.GetItemsAsync( p => p.ClosureDate.Value == null, p => new EventClusterDAO() { Id = p.Id, EventType = p.EventType, Device = new EventClusterDeviceDAOObject() { Geolocation = p.Device.Geolocation } } ); List <Guid> output = new List <Guid>(); GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(eventClusterGeolocationObj.ResponseGeolocationPointLocation); foreach (EventClusterDAO eventClusterObj in eventClusters) { if (RadiusHelper.IsWithinRadius(eventClusterObj.Device.Geolocation, daoGeocodeCenterPoint, eventClusterGeolocationObj.Radius)) { output.Add(new Guid(eventClusterObj.Id)); } } return(output); }
/// <summary> /// Get a list of responses that are within the radius of a point. The size of the radius is the primary radius of the action plan /// </summary> /// <param name="responseGeolocationObj">ResponseGeolocationModel</param> /// <returns>List of Response Model</returns> public async Task <IEnumerable <ResponseModel> > GetResponsesFromPointRadius(ResponseGeolocationModel responseGeolocationObj) { if (responseGeolocationObj == null || responseGeolocationObj.EventClusterGeolocationPointLocation == null) { return(new List <ResponseModel>()); } IEnumerable <ResponseDAO> responseObjs = await _repoResponses.GetItemsAsync(p => p.EndDate.Value == null); if (responseObjs == null) { return(null); } List <ResponseDAO> output = new List <ResponseDAO>(); GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(responseGeolocationObj.EventClusterGeolocationPointLocation); foreach (var response in responseObjs) { if (RadiusHelper.IsWithinRadius(daoGeocodeCenterPoint, response.Geolocation, response.ActionPlan.PrimaryRadius)) { output.Add(response); } } return(_mapper.Map <IEnumerable <ResponseModel> >(output)); }
/// <summary> /// Test if a point testPoint is within a radius around a point center /// </summary> /// <param name="testPoint">Point to test</param> /// <param name="center">Center of the radius</param> /// <param name="radius">Radius</param> /// <returns>True if the point is within the radius</returns> public static bool IsWithinRadius(Geolocation testPoint, GeolocationDAOObject center, double radius) { return(IsWithinRadius(testPoint.Longitude, center.Longitude, testPoint.Latitude, center.Latitude, radius)); }