Beispiel #1
0
        public void ValidateBoundingBox2DLatLonFailTest()
        {
            //not bl and tr
            BoundingBox2DLatLon bbox = new BoundingBox2DLatLon(-0.741023, 3.010479, -0.758809, 3.0567);

            Assert.ThrowsException <ServiceException>(() => bbox.Validate());
        }
Beispiel #2
0
 /// <summary>
 /// Overload constructor with parameters.
 /// </summary>
 public TRexTileRequest(
     Guid projectUid,
     DisplayMode mode,
     List <ColorPalette> palettes,
     DesignDescriptor designDescriptor,
     FilterResult filter1,
     FilterResult filter2,
     BoundingBox2DLatLon boundingBoxLatLon,
     BoundingBox2DGrid boundingBoxGrid,
     ushort width,
     ushort height,
     OverridingTargets overrides,
     LiftSettings liftSettings,
     VolumesType volumeType)
 {
     ProjectUid       = projectUid;
     Mode             = mode;
     Palettes         = palettes;
     DesignDescriptor = designDescriptor;
     Filter1          = filter1;
     Filter2          = filter2;
     BoundBoxLatLon   = boundingBoxLatLon;
     BoundBoxGrid     = boundingBoxGrid;
     Width            = width;
     Height           = height;
     Overrides        = overrides;
     LiftSettings     = liftSettings;
     VolumeType       = volumeType;
 }
Beispiel #3
0
        public void MapBoundingBox2DLatLonToBoundingWorldExtent3D()
        {
            var box   = new BoundingBox2DLatLon(10, 12, 35, 27);
            var box3d = AutoMapperUtility.Automapper.Map <BoundingWorldExtent3D>(box);

            Assert.Equal(box.BottomLeftLon, box3d.MinX);
            Assert.Equal(box.BottomLeftLat, box3d.MinY);
            Assert.Equal(box.TopRightLon, box3d.MaxX);
            Assert.Equal(box.TopRightLat, box3d.MaxY);
        }
Beispiel #4
0
 /// <summary>
 /// Create instance of CompactionTileRequest
 /// </summary>
 public static DxfTileRequest CreateTileRequest(
     IEnumerable <FileData> files,
     BoundingBox2DLatLon boundingBoxLatLon
     )
 {
     return(new DxfTileRequest
     {
         files = files,
         bbox = boundingBoxLatLon
     });
 }
Beispiel #5
0
        public void CanCreateBoundingBox2DLatLonTest()
        {
            var validator            = new DataAnnotationsValidator();
            BoundingBox2DLatLon bbox = new BoundingBox2DLatLon(
                -106.604076 * Coordinates.DEGREES_TO_RADIANS, 35.109149 * Coordinates.DEGREES_TO_RADIANS, -105.234 * Coordinates.DEGREES_TO_RADIANS, 35.39012 * Coordinates.DEGREES_TO_RADIANS);
            ICollection <ValidationResult> results;

            Assert.IsTrue(validator.TryValidate(bbox, out results));

            //too big value
            bbox = new BoundingBox2DLatLon(
                -106.604076 * Coordinates.DEGREES_TO_RADIANS, 35.109149 * Coordinates.DEGREES_TO_RADIANS, -105.234 * Coordinates.DEGREES_TO_RADIANS, 525.5 * Coordinates.DEGREES_TO_RADIANS);
            Assert.IsFalse(validator.TryValidate(bbox, out results));
        }
Beispiel #6
0
 /// <summary>
 /// Overload constructor with parameters.
 /// </summary>
 /// <param name="projectId"></param>
 /// <param name="callId"></param>
 /// <param name="mode"></param>
 /// <param name="palettes"></param>
 /// <param name="liftBuildSettings"></param>
 /// <param name="computeVolType"></param>
 /// <param name="computeVolNoChangeTolerance"></param>
 /// <param name="designDescriptor"></param>
 /// <param name="filter1"></param>
 /// <param name="filterId1"></param>
 /// <param name="filter2"></param>
 /// <param name="filterId2"></param>
 /// <param name="filterLayerMethod"></param>
 /// <param name="boundingBoxLatLon"></param>
 /// <param name="boundingBoxGrid"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="representationalDisplayColor"></param>
 /// <param name="cmvDetailsColorNumber"></param>
 /// <param name="cmvPercentChangeColorNumber"></param>
 /// <param name="setSummaryDataLayersVisibility"></param>
 public TileRequest(
     long projectId,
     Guid?projectUid,
     Guid?callId,
     DisplayMode mode,
     List <ColorPalette> palettes,
     LiftBuildSettings liftBuildSettings,
     VolumesType computeVolType,
     double computeVolNoChangeTolerance,
     DesignDescriptor designDescriptor,
     FilterResult filter1,
     long filterId1,
     FilterResult filter2,
     long filterId2,
     FilterLayerMethod filterLayerMethod,
     BoundingBox2DLatLon boundingBoxLatLon,
     BoundingBox2DGrid boundingBoxGrid,
     ushort width,
     ushort height,
     uint representationalDisplayColor   = 0,
     uint cmvDetailsColorNumber          = 5,
     uint cmvPercentChangeColorNumber    = 6,
     bool setSummaryDataLayersVisibility = true,
     bool explicitFilters = false)
 {
     ProjectId                      = projectId;
     ProjectUid                     = projectUid;
     CallId                         = callId;
     Mode                           = mode;
     Palettes                       = palettes;
     LiftBuildSettings              = liftBuildSettings;
     ComputeVolumesType             = computeVolType;
     ComputeVolNoChangeTolerance    = computeVolNoChangeTolerance;
     DesignDescriptor               = designDescriptor;
     Filter1                        = filter1;
     FilterId1                      = filterId1;
     Filter2                        = filter2;
     FilterId2                      = filterId2;
     FilterLayerMethod              = filterLayerMethod;
     BoundBoxLatLon                 = boundingBoxLatLon;
     BoundBoxGrid                   = boundingBoxGrid;
     Width                          = width;
     Height                         = height;
     RepresentationalDisplayColor   = representationalDisplayColor;
     p_cmvDetailsColorNumber        = cmvDetailsColorNumber;
     p_cmvPercentChangeColorNumber  = cmvPercentChangeColorNumber;
     SetSummaryDataLayersVisibility = setSummaryDataLayersVisibility;
     ExplicitFilters                = explicitFilters;
 }
Beispiel #7
0
        /// <summary>
        /// Creates an instance of the TileRequest class and populate it with data needed for a tile.
        /// </summary>
        /// <returns>An instance of the TileRequest class.</returns>
        public TileRequest CreateTileRequest(DisplayMode mode, ushort width, ushort height,
                                             BoundingBox2DLatLon bbox, ElevationStatisticsResult elevExtents, bool explicitFilters = false)
        {
            var liftSettings = SettingsManager.CompactionLiftBuildSettings(ProjectSettings);

            Filter?.Validate();//Why is this here? Should be done where filter set up???
            var palette        = SettingsManager.CompactionPalette(mode, elevExtents, ProjectSettings, ProjectSettingsColors);
            var computeVolType = (int)(volCalcType ?? VolumeCalcType.None);

            DesignDescriptor design  = DesignDescriptor;
            FilterResult     filter1 = Filter;
            FilterResult     filter2 = null;

            if (mode == DisplayMode.CutFill)
            {
                switch (volCalcType)
                {
                case VolumeCalcType.DesignToGround:
                case VolumeCalcType.GroundToDesign:
                    design  = volumeDesign;
                    filter1 = baseFilter ?? topFilter;
                    break;

                case VolumeCalcType.GroundToGround:
                    filter1 = baseFilter;
                    filter2 = topFilter;
                    break;
                }
            }

            TileRequest tileRequest = new TileRequest(
                ProjectId, ProjectUid, null, mode, palette, liftSettings, (VolumesType)computeVolType,
                0, design, filter1, 0, filter2, 0,
                Filter == null || !Filter.LayerType.HasValue ? FilterLayerMethod.None : Filter.LayerType.Value,
                bbox, null, width, height, 0, CMV_DETAILS_NUMBER_OF_COLORS, CMV_PERCENT_CHANGE_NUMBER_OF_COLORS, false, explicitFilters);

            return(tileRequest);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the requested tile from Raptor
        /// </summary>
        /// <param name="projectSettings">Project settings to use for Raptor</param>
        /// <param name="projectSettingsColors"></param>
        /// <param name="filter">Filter to use for Raptor</param>
        /// <param name="projectId">Legacy project ID</param>
        /// <param name="projectUid">Unique project identifier</param>
        /// <param name="mode">Display mode; type of data requested</param>
        /// <param name="width">Width of the tile</param>
        /// <param name="height">Height of the tile in pixels</param>
        /// <param name="bbox">Bounding box in radians</param>
        /// <param name="cutFillDesign">Design descriptor for cut-fill</param>
        /// <param name="baseFilter">Base filter for  summary volumes</param>
        /// <param name="topFilter">Top filter for  summary volumes</param>
        /// <param name="volumeDesign">Design descriptor for summary volumes design</param>
        /// <param name="volumeCalcType">Type of summary volumes calculation</param>
        /// <param name="customHeaders">Custom request headers</param>
        /// <returns>Tile result</returns>
        public async Task <TileResult> GetProductionDataTile(CompactionProjectSettings projectSettings, CompactionProjectSettingsColors projectSettingsColors, FilterResult filter, long projectId, Guid projectUid, DisplayMode mode, ushort width, ushort height, BoundingBox2DLatLon bbox, DesignDescriptor cutFillDesign, FilterResult baseFilter, FilterResult topFilter, DesignDescriptor volumeDesign, VolumeCalcType?volumeCalcType, IHeaderDictionary customHeaders, string userId, bool explicitFilters = false)
        {
            var getTile = true;
            ElevationStatisticsResult elevationExtents = null;
            TileRequest tileRequest = null;

            try
            {
                elevationExtents = await GetElevationExtents(projectSettings, filter, projectId, projectUid, mode, customHeaders, userId);
            }
            catch (ServiceException se)
            {
                getTile = mode != DisplayMode.Height;
                if (log.IsTraceEnabled())
                {
                    log.LogTrace(
                        $"Failed to get elevation extents for height request with error: {se.GetResult.Code}:{se.GetResult.Message} a transparent tile will be generated");
                }
            }

            if (getTile)
            {
                tileRequest = requestFactory.Create <TileRequestHelper>(r => r
                                                                        .ProjectUid(projectUid)
                                                                        .ProjectId(projectId)
                                                                        .Headers(customHeaders)
                                                                        .ProjectSettings(projectSettings)
                                                                        .ProjectSettingsColors(projectSettingsColors)
                                                                        .Filter(filter)
                                                                        .DesignDescriptor(cutFillDesign))
                              .SetVolumeCalcType(volumeCalcType)
                              .SetVolumeDesign(volumeDesign)
                              .SetBaseFilter(baseFilter)
                              .SetTopFilter(topFilter)
                              .CreateTileRequest(mode, width, height, bbox, elevationExtents, explicitFilters);

                //TileRequest is both v1 and v2 model so cannot change its validation directly.
                //However for v2 we want to return a transparent empty tile for cut-fill if no design specified.
                //So catch the validation exception for this case.
                try
                {
                    tileRequest.Validate();
                }
                catch (ServiceException se)
                {
                    if (tileRequest.Mode == DisplayMode.CutFill &&
                        se.Code == HttpStatusCode.BadRequest &&
                        se.GetResult.Code == ContractExecutionStatesEnum.ValidationError)
                    {
                        if (
                            se is MissingDesignDescriptorException ||
                            se is TwoFiltersRequiredException ||
                            se is SingleFilterRequiredException)
                        {
                            getTile = false;
                        }
                    }
                    //Rethrow any other exception
                    if (getTile)
                    {
                        throw;
                    }
                }
            }

            TileResult tileResult = null;

            if (getTile)
            {
                try
                {
                    tileResult = await RequestExecutorContainerFactory
                                 .Build <CompactionTileExecutor>(logger,
#if RAPTOR
                                                                 raptorClient,
#endif
                                                                 configStore : ConfigStore, trexCompactionDataProxy : TRexCompactionDataProxy, customHeaders : customHeaders,
                                                                 userId : userId, fileImportProxy : FileImportProxy)
                                 .ProcessAsync(tileRequest) as TileResult;
                }
                catch (Exception ex)
                {
                    log.LogWarning($"Exception: {ex.Message} {ex.StackTrace}");
                }
            }

            return(tileResult?.TileData != null
        ? tileResult
        : TileResult.EmptyTile(WebMercatorProjection.TILE_SIZE, WebMercatorProjection.TILE_SIZE));
        }
Beispiel #9
0
 public string GetBoundingBox(BoundingBox2DLatLon bbox)
 {
     return($"{bbox.BottomLeftLat.LatRadiansToDegrees()},{bbox.BottomLeftLon.LonRadiansToDegrees()},{bbox.TopRightLat.LatRadiansToDegrees()},{bbox.TopRightLon.LonRadiansToDegrees()}");
 }
Beispiel #10
0
        public void ValidateBoundingBox2DLatLonSuccessTest()
        {
            BoundingBox2DLatLon bbox = new BoundingBox2DLatLon(-0.758809, 3.010479, -0.741023, 3.0567);

            bbox.Validate();
        }
Beispiel #11
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            List <FileData>     files       = null;
            int                 zoomLevel   = 0;
            Point               topLeftTile = null;
            int                 numTiles    = 0;
            BoundingBox2DLatLon bbox        = null;

            if (item is DxfTileRequest request)
            {
                files = request.files?.ToList();
                bbox  = request.bbox;

                //Calculate zoom level
                zoomLevel = TileServiceUtils.CalculateZoomLevel(request.bbox.TopRightLat - request.bbox.BottomLeftLat,
                                                                request.bbox.TopRightLon - request.bbox.BottomLeftLon);
                log.LogDebug("DxfTileExecutor: BBOX differences {0} {1} {2}", request.bbox.TopRightLat - request.bbox.BottomLeftLat,
                             request.bbox.TopRightLon - request.bbox.BottomLeftLon, zoomLevel);
                numTiles = TileServiceUtils.NumberOfTiles(zoomLevel);
                Point topLeftLatLng = new Point(request.bbox.TopRightLat.LatRadiansToDegrees(),
                                                request.bbox.BottomLeftLon.LonRadiansToDegrees());
                topLeftTile = WebMercatorProjection.LatLngToTile(topLeftLatLng, numTiles);
                log.LogDebug($"DxfTileExecutor: zoomLevel={zoomLevel}, numTiles={numTiles}, xtile={topLeftTile.x}, ytile={topLeftTile.y}");
            }
            else if (item is DxfTile3dRequest request3d)
            {
                files = request3d.files?.ToList();

                zoomLevel   = request3d.zoomLevel;
                numTiles    = TileServiceUtils.NumberOfTiles(zoomLevel);
                topLeftTile = new Point {
                    x = request3d.xTile, y = request3d.yTile
                };
            }
            else
            {
                ThrowRequestTypeCastException <DxfTileRequest>();
            }

            log.LogDebug($"DxfTileExecutor: {files?.Count ?? 0} files");

            //Short circuit overlaying if there no files to overlay as ForAll is an expensive operation
            if (files == null || !files.Any())
            {
                byte[] emptyOverlayData;
                using (var bitmap = new Image <Rgba32>(WebMercatorProjection.TILE_SIZE, WebMercatorProjection.TILE_SIZE))
                {
                    emptyOverlayData = bitmap.BitmapToByteArray();
                }

                return(new TileResult(emptyOverlayData));
            }

            log.LogDebug(string.Join(",", files.Select(f => f.Name).ToList()));

            var          tileList = new List <byte[]>();
            const string DATA_OCEAN_ROOT_FOLDER_ID_KEY = "DATA_OCEAN_ROOT_FOLDER_ID";
            var          dataOceanRootFolder           = configStore.GetValueString(DATA_OCEAN_ROOT_FOLDER_ID_KEY);

            if (string.IsNullOrEmpty(dataOceanRootFolder))
            {
                throw new ArgumentException($"Missing environment variable {DATA_OCEAN_ROOT_FOLDER_ID_KEY}");
            }

            //For GeoTIFF files, use the latest version of a file
            var geoTiffFiles = files.Where(x => x.ImportedFileType == ImportedFileType.GeoTiff).ToList();

            if (geoTiffFiles.Any())
            {
                //Find any with multiple versions and remove old ones from the list
                var latestFiles = geoTiffFiles.GroupBy(g => g.Name).Select(g => g.OrderBy(o => o.SurveyedUtc).Last()).ToList();
                foreach (var geoTiffFile in geoTiffFiles)
                {
                    if (!latestFiles.Contains(geoTiffFile))
                    {
                        files.Remove(geoTiffFile);
                    }
                }
            }

            var fileTasks = files.Select(async file =>
            {
                //foreach (var file in request.files)
                //Check file type to see if it has tiles
                if (file.ImportedFileType == ImportedFileType.Linework ||
                    file.ImportedFileType == ImportedFileType.GeoTiff)
                {
                    var fullPath = DataOceanFileUtil.DataOceanPath(dataOceanRootFolder, file.CustomerUid, file.ProjectUid);
                    var fileName = DataOceanFileUtil.DataOceanFileName(file.Name,
                                                                       file.ImportedFileType == ImportedFileType.SurveyedSurface || file.ImportedFileType == ImportedFileType.GeoTiff,
                                                                       Guid.Parse(file.ImportedFileUid), file.SurveyedUtc);
                    fileName = DataOceanFileUtil.GeneratedFileName(fileName, file.ImportedFileType);

                    if (zoomLevel >= file.MinZoomLevel)
                    {
                        byte[] tileData = null;
                        if (zoomLevel <= file.MaxZoomLevel || file.MaxZoomLevel == 0) //0 means not calculated
                        {
                            tileData = await GetTileAtRequestedZoom(topLeftTile, zoomLevel, fullPath, fileName);
                        }
                        else if (zoomLevel - file.MaxZoomLevel <= 5) //Don't try to scale if the difference is too excessive
                        {
                            tileData = await GetTileAtHigherZoom(topLeftTile, zoomLevel, fullPath, fileName,
                                                                 file.MaxZoomLevel, numTiles);
                        }
                        else
                        {
                            log.LogDebug(
                                "DxfTileExecutor: difference between requested and maximum zooms too large; not even going to try to scale tile");
                        }

                        if (tileData != null && tileData.Length > 0)
                        {
                            tileList.Add(tileData);
                        }
                    }
                }
            });

            await Task.WhenAll(fileTasks);

            log.LogDebug($"DxfTileExecutor: Overlaying {tileList.Count} tiles");
            byte[] overlayData = TileOverlay.OverlayTiles(tileList);

            return(new TileResult(overlayData));
        }