Example #1
0
        /// <summary>
        /// This function is used to validate the bitmap at specified level, x and y.
        /// </summary>
        /// <param name="testFolderName">Plate file folder.</param>
        /// <param name="tileLocator">Tile Locator.</param>
        /// <param name="level">Level of tile.</param>
        /// <param name="x">X coordinate of the tile.</param>
        /// <param name="y">Y coordinate of the tile.</param>
        private void ValidatePyramid(string testFolderName, MockClasses.MockMultipleDemTileLocator tileLocator, int level, int x, int y)
        {
            Stream tileStream = PlateFileHelper.GetDEMTileFromMultiplePlates(level, x, y, testFolderName);

            short[] expected = tileLocator.Deserialize(level, x, y);
            short[] actual   = GetDemTileData(tileStream);
            Assert.IsTrue(CompareShortArray(expected, actual));
        }
Example #2
0
        /// <summary>
        /// Gets Dem for the specified tile id.
        /// </summary>
        /// <param name="id">Tile details id.</param>
        /// <param name="level">Level of the image.</param>
        /// <param name="x">X axis image.</param>
        /// <param name="y">Y axis image.</param>
        /// <returns>Dem for the specified image.</returns>
        public Stream GetDem(string id, int level, int x, int y)
        {
            Stream outputStream = null;

            try
            {
                string        pyramidFolderPath   = Path.Combine(this.PyramidLocation, id, Constants.PyramidFolder);
                string        demPlatesFolderPath = Path.Combine(this.PyramidLocation, id, Constants.DEMPlatesFolder);
                DirectoryInfo pyramidFolder       = new DirectoryInfo(pyramidFolderPath);
                DirectoryInfo platesFolder        = new DirectoryInfo(demPlatesFolderPath);

                if (pyramidFolder.Exists)
                {
                    string pyramidPath = Path.Combine(this.PyramidLocation, id, Constants.DemTilePath);

                    string filename = string.Format(CultureInfo.InvariantCulture, pyramidPath, level, x, y, Constants.DemExtension);
                    if (File.Exists(filename))
                    {
                        byte[] data = null;
                        using (Stream s = File.OpenRead(filename))
                        {
                            int length = (int)s.Length;
                            data = new byte[length];
                            s.Read(data, 0, length);
                            outputStream = new MemoryStream(data);
                        }
                    }
                }
                else if (platesFolder.Exists)
                {
                    // Get from multiple plates
                    outputStream = PlateFileHelper.GetDEMTileFromMultiplePlates(level, x, y, platesFolder.FullName);
                }
                else
                {
                    // If Pyramid folder is not available, then try to read from plate file.
                    FileInfo plateFile = pyramidFolder.Parent.GetFiles(Constants.PlateFileSearchPattern).FirstOrDefault();
                    if (plateFile != null && plateFile.Exists)
                    {
                        PlateFile plateFileInstance = new PlateFile(plateFile.FullName, level);
                        outputStream = plateFileInstance.GetFileStream(level, x, y);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (IOException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (ObjectDisposedException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }

            return(outputStream);
        }