public List <string> RequestPointsRegionsKeys(Pair topLeftCorner, Pair bottomRightCorner, int zoomLevel, string username, string dataSet) { //todo: cache the header PointsDataSetHeader dataSetHeader = this.userRepository.GetDatasetHeader(username, dataSet); if (dataSetHeader == null) { throw new ApplicationException($"User do not have a dataset with name {dataSet}"); } //set the requested latitude and longitude coordinates of corners in the available limits of the dataset var topLeftIndexes = this.dataPointsRegionSource.GetRegionIndexes( topLeftCorner.Item1 <(dataSetHeader.MaximumLatitude ?? 90m) ? topLeftCorner.Item1 : dataSetHeader.MaximumLatitude ?? 90m, topLeftCorner.Item2> (dataSetHeader.MinimumLongitude ?? -180m) ? topLeftCorner.Item2 : dataSetHeader.MinimumLongitude ?? -180m, zoomLevel); var bottomRightIndexes = this.dataPointsRegionSource.GetRegionIndexes( bottomRightCorner.Item1 > (dataSetHeader.MinimumLatitude ?? -90m) ? bottomRightCorner.Item1 : (dataSetHeader.MinimumLatitude ?? -90m), bottomRightCorner.Item2 < (dataSetHeader.MaximumLongitude ?? 180m) ? bottomRightCorner.Item2 : (dataSetHeader.MaximumLongitude ?? 180m), zoomLevel); return(PointsCacheManager.GetKeys(topLeftIndexes, bottomRightIndexes, zoomLevel, dataSetHeader.ID)); }
private PointsDataSetHeader parseDataSetHeaderDataset(DataRowCollection rows) { if (rows.Count == 0) { return(null); } var resultRow = rows[0]; var header = new PointsDataSetHeader() { Username = (string)resultRow["username"], Name = (string)resultRow["dataset_name"], ID = (int)resultRow["data_set_id"], MaximumLatitude = resultRow["maximum_latitude"] is DBNull ? null : (decimal?)resultRow["maximum_latitude"], MaximumLongitude = resultRow["maximum_longitude"] is DBNull ? null : (decimal?)resultRow["maximum_longitude"], MinimumLatitude = resultRow["minimum_latitude"] is DBNull ? null : (decimal?)resultRow["minimum_latitude"], MinimumLongitude = resultRow["minimum_longitude"] is DBNull ? null : (decimal?)resultRow["minimum_longitude"], MinimumHeight = resultRow["minimum_height"] is DBNull ? null : (decimal?)resultRow["minimum_height"], MaximumHeight = resultRow["maximum_height"] is DBNull ? null : (decimal?)resultRow["maximum_height"], MinimumDeformationRate = resultRow["minimum_def_rate"] is DBNull ? null : (decimal?)resultRow["minimum_def_rate"], MaximumDeformationRate = resultRow["maximum_def_rate"] is DBNull ? null : (decimal?)resultRow["maximum_def_rate"], MinimumStdDev = resultRow["minimum_std_dev"] is DBNull ? null : (decimal?)resultRow["minimum_std_dev"], MaximumStdDev = resultRow["maximum_std_dev"] is DBNull ? null : (decimal?)resultRow["maximum_std_dev"], Status = (DatasetStatus)((int)resultRow["data_set_id"]), PointsSource = (PointsSource)Enum.Parse(typeof(PointsSource), (string)resultRow["source_name"]) }; if (!(resultRow["geoserver_api_url"] is DBNull)) { header.OptionalData = new GeoserverOptionalData() { ServerUrl = resultRow["geoserver_api_url"].ToString() } } ; return(header); }
/// <summary> /// Returns data points regions which are inside a specific area of screen for a zoom level. /// Limits unit of measure with latitude/longitude. /// Points zones source is Cassandra /// </summary> /// <param name="topLeftCorner"></param> /// <param name="bottomRightCorner"></param> /// <param name="username"></param> /// <param name="dataSet"></param> /// <param name="cachedRegions">A list of regions keys which are cached on browser</param> /// <param name="callback"></param> /// <returns></returns> public void RequestDomainPointsRegions(Pair topLeftCorner, Pair bottomRightCorner, int zoomLevel, string username, string dataSet, string[] cachedRegions, Action <IEnumerable <PointBase>, string> callback) { //todo: cache the header PointsDataSetHeader datasetHeader = this.userRepository.GetDatasetHeader(username, dataSet); if (datasetHeader == null) { throw new ApplicationException($"User do not have a dataset with name {dataSet}"); } //set the requested latitude and longitude coordinates of corners in the available limits of the dataset var topLeftIndexes = this.dataPointsRegionSource.GetRegionIndexes( topLeftCorner.Item1 <(datasetHeader.MaximumLatitude ?? 90m) ? topLeftCorner.Item1 : datasetHeader.MaximumLatitude ?? 90m, topLeftCorner.Item2> (datasetHeader.MinimumLongitude ?? -180m) ? topLeftCorner.Item2 : datasetHeader.MinimumLongitude ?? -180m, zoomLevel); var bottomRightIndexes = this.dataPointsRegionSource.GetRegionIndexes( bottomRightCorner.Item1 > (datasetHeader.MinimumLatitude ?? -90m) ? bottomRightCorner.Item1 : (datasetHeader.MinimumLatitude ?? -90m), bottomRightCorner.Item2 < (datasetHeader.MaximumLongitude ?? 180m) ? bottomRightCorner.Item2 : (datasetHeader.MaximumLongitude ?? 180m), zoomLevel); var serverCachedRegions = PointsCacheManager.Get(topLeftIndexes, bottomRightIndexes, zoomLevel, datasetHeader.ID, cachedRegions, out List <Coordinates> requiredRegions); if (requiredRegions != null) { Parallel.ForEach(requiredRegions, coordinate => { try { var result = this.dataPointsRepository.GetRegion(datasetHeader.ID, coordinate.Item1, coordinate.Item2, zoomLevel); string regionKey = null; if (result != null) { regionKey = PointsCacheManager.Write(coordinate.Item1, coordinate.Item2, coordinate.Item3, datasetHeader.ID, result.Points); } callback(result == null ? new List <PointBase>() : result.Points, regionKey); } catch (Exception exception) { CoreContainers.LogsRepository.LogError(exception, Core.Database.Logs.LogTrigger.Domain); //if a error ocurs, the created entry must be deleted from the cache PointsCacheManager.Remove(coordinate.Item1, coordinate.Item2, coordinate.Item3, datasetHeader.ID); } }); } foreach (var pointsZonePair in serverCachedRegions) { callback(pointsZonePair.Item1, pointsZonePair.Item2); } }