/// <summary>
        /// Prepares the result of the operation.
        /// </summary>
        /// <returns>The resulting object.</returns>
        protected override ISpectralGeometry PrepareResult()
        {
            RasterPresentation presentation = null;

            if (_bandIndices.SequenceEqual(Enumerable.Range(0, Source.Raster.NumberOfBands)))
            {
                presentation = Source.Presentation;
            }
            else if (_bandIndices.Length == 3)
            {
                presentation = RasterPresentation.CreateFalseColorPresentation(0, 1, 2);
            }
            else
            {
                presentation = RasterPresentation.CreateGrayscalePresentation();
            }

            RasterImaging imaging = null;

            if (Source.Imaging != null)
            {
                imaging = RasterImaging.Filter(Source.Imaging, _bandIndices);
            }

            SetResultProperties(Source.Raster.Format, _bandIndices.Length, Source.Raster.NumberOfRows, Source.Raster.NumberOfColumns, Source.Raster.RadiometricResolution, Source.Raster.Mapper, presentation, imaging);

            return(base.PrepareResult());
        }
Example #2
0
        /// <summary>
        /// Apply the read operation for a geometry.
        /// </summary>
        /// <returns>The geometry read from the stream.</returns>
        protected override IGeometry ApplyReadGeometry()
        {
            if (_filePaths.Count == 0)
            {
                return(null);
            }

            // read imaging data
            RasterImaging imaging = _metafileReader == null ? null : _metafileReader.ReadImaging();

            // read files
            List <ISpectralPolygon> polygons = new List <ISpectralPolygon>();

            Dictionary <GeometryStreamParameter, Object> parameters = new Dictionary <GeometryStreamParameter, Object>(Parameters);

            parameters[SpectralGeometryStreamParameters.IncludeMetadata] = false;

            foreach (String filePath in _filePaths)
            {
                try
                {
                    using (GeoTiffReader reader = new GeoTiffReader(filePath, parameters))
                    {
                        polygons.Add(reader.Read() as ISpectralPolygon);
                    }
                }
                catch { }
            }

            _filePaths.Clear();

            // if no polygons are available
            if (polygons.Count == 0)
            {
                return(null);
            }

            // remove rasters with different size
            for (Int32 index = polygons.Count - 1; index >= 0; index--)
            {
                if (polygons[index].Raster.NumberOfRows != polygons[0].Raster.NumberOfRows || polygons[index].Raster.NumberOfColumns != polygons[0].Raster.NumberOfColumns)
                {
                    polygons.RemoveAt(index);
                    if (imaging != null)
                    {
                        imaging.RemoveBand(index);
                    }
                }
            }

            // merge content
            return(polygons[0].Factory.CreateSpectralPolygon(polygons, imaging));
        }
Example #3
0
        /// <summary>
        /// Sets the properties of the result.
        /// </summary>
        /// <param name="format">The raster format.</param>
        /// <param name="numberOfBands">The number of bands.</param>
        /// <param name="numberOfRows">The number of rows.</param>
        /// <param name="numberOfColumns">The number of columns.</param>
        /// <param name="radiometricResolution">The radiometric resolution.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="presentation">The raster presentation.</param>
        /// <param name="imaging">The raster imaging.</param>
        protected void SetResultProperties(RasterFormat format, Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, Int32 radiometricResolution, RasterMapper mapper, RasterPresentation presentation, RasterImaging imaging)
        {
            if (_resultPropertiesSet)
            {
                return;
            }

            _resultFormat       = format;
            _resultDimensions   = new RasterDimensions(numberOfBands, numberOfRows, numberOfColumns, radiometricResolution);
            _resultMapper       = mapper;
            _resultPresentation = presentation;
            _resultImaging      = imaging;

            _resultPropertiesSet = true;
        }
Example #4
0
        /// <summary>
        /// Sets the properties of the result.
        /// </summary>
        /// <param name="numberOfBands">The number of bands.</param>
        /// <param name="numberOfRows">The number of rows.</param>
        /// <param name="numberOfColumns">The number of columns.</param>
        /// <param name="radiometricResolution">The radiometric resolution.</param>
        protected void SetResultProperties(Int32 numberOfBands, Int32 numberOfRows, Int32 numberOfColumns, Int32 radiometricResolution)
        {
            if (_resultPropertiesSet)
            {
                return;
            }

            _resultFormat       = Source.Raster.Format;
            _resultDimensions   = new RasterDimensions(numberOfBands, numberOfRows, numberOfColumns, radiometricResolution);
            _resultMapper       = Source.Raster.Mapper;
            _resultPresentation = Source.Presentation;
            _resultImaging      = Source.Imaging;

            _resultPropertiesSet = true;
        }
Example #5
0
        /// <summary>
        /// Sets the properties of the result.
        /// </summary>
        /// <param name="format">The raster format.</param>
        /// <param name="dimensions">The raster dimensions.</param>
        /// <param name="mapper">The mapper.</param>
        /// <param name="presentation">The raster presentation.</param>
        /// <param name="imaging">The raster imaging.</param>
        protected void SetResultProperties(RasterFormat format, RasterDimensions dimensions, RasterMapper mapper, RasterPresentation presentation, RasterImaging imaging)
        {
            if (_resultPropertiesSet)
            {
                return;
            }

            _resultFormat       = format;
            _resultDimensions   = dimensions ?? Source.Raster.Dimensions;
            _resultMapper       = mapper;
            _resultPresentation = presentation;
            _resultImaging      = imaging;

            _resultPropertiesSet = true;
        }
Example #6
0
        /// <summary>
        /// Sets the properties of the result.
        /// </summary>
        /// <param name="format">The raster format.</param>
        /// <param name="dimensions">The raster dimensions.</param>
        protected void SetResultProperties(RasterFormat format, RasterDimensions dimensions)
        {
            if (_resultPropertiesSet)
            {
                return;
            }

            _resultFormat       = format;
            _resultDimensions   = dimensions ?? Source.Raster.Dimensions;
            _resultMapper       = Source.Raster.Mapper;
            _resultPresentation = Source.Presentation;
            _resultImaging      = Source.Imaging;

            _resultPropertiesSet = true;
        }
Example #7
0
        /// <summary>
        /// Sets the properties of the result.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="format">The raster format.</param>
        /// <param name="numberOfBands">The number of bands.</param>
        /// <param name="radiometricResolution">The radiometric resolution.</param>
        /// <param name="presentation">The raster presentation.</param>
        protected void SetResultProperties(ISpectralGeometry geometry, RasterFormat format, Int32 numberOfBands, Int32 radiometricResolution, RasterPresentation presentation)
        {
            if (_resultPropertiesSet)
            {
                return;
            }

            _resultGeometry     = geometry;
            _resultFormat       = format;
            _resultDimensions   = new RasterDimensions(numberOfBands, Source.Raster.NumberOfRows, Source.Raster.NumberOfColumns, radiometricResolution);
            _resultMapper       = Source.Raster.Mapper;
            _resultPresentation = presentation;
            _resultImaging      = Source.Imaging;

            _resultPropertiesSet = true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SpectralPolygon" /> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="shell">The shell.</param>
        /// <param name="holes">The holes.</param>
        /// <param name="raster">The raster.</param>
        /// <param name="interpretation">The interpretation data.</param>
        /// <param name="imaging">The imaging data.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The raster is null.
        /// or
        /// The shell is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The shell is empty.</exception>
        public SpectralPolygon(ISpectralGeometryFactory factory, IEnumerable <Coordinate> shell, IEnumerable <IEnumerable <Coordinate> > holes, IRaster raster, RasterPresentation presentation, RasterImaging imaging, IDictionary <String, Object> metadata)
        {
            if (raster == null)
            {
                throw new ArgumentNullException("raster", "The raster is null.");
            }

            _factory = factory ?? new SpectralGeometryFactory(new GeometryFactory(), new RasterFactory());

            Raster       = raster;
            Presentation = presentation;
            Imaging      = imaging;

            _polygon = _factory.GetFactory <IGeometryFactory>().CreatePolygon(shell, holes, metadata);

            _polygon.GeometryChanged += new EventHandler(Polygon_GeometryChanged);
        }
        /// <summary>
        /// Reads the imaging information stored in the metafile stream.
        /// </summary>
        /// <returns>The imaging data.</returns>
        protected override RasterImaging ReadImagingInternal()
        {
            ReadContent();

            // read the device data
            ImagingDevice device = ReadDeviceInternal();

            // time
            DateTime imagingDateTime = DateTime.Parse(_metadata["DATE_ACQUIRED"] + " " + _metadata["SCENE_CENTER_TIME"], CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal);

            // view
            Double incidenceAngle = Double.NaN;
            Double viewingAngle   = _metadata.ContainsKey("ROLL_ANGLE") ? Double.Parse(_metadata["ROLL_ANGLE"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat) : Double.NaN; // only Landsat 8 contains the roll angle property
            Double sunAzimuth     = Double.Parse(_metadata["SUN_AZIMUTH"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);
            Double sunElevation   = Double.Parse(_metadata["SUN_ELEVATION"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);

            // image location
            GeoCoordinate[] imageLocation = new GeoCoordinate[]
            {
                new GeoCoordinate(Double.Parse(_metadata["CORNER_UL_LAT_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                                  Double.Parse(_metadata["CORNER_UL_LON_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat)),
                new GeoCoordinate(Double.Parse(_metadata["CORNER_UR_LAT_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                                  Double.Parse(_metadata["CORNER_UR_LON_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat)),
                new GeoCoordinate(Double.Parse(_metadata["CORNER_LL_LAT_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                                  Double.Parse(_metadata["CORNER_LL_LON_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat)),
                new GeoCoordinate(Double.Parse(_metadata["CORNER_LR_LAT_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                                  Double.Parse(_metadata["CORNER_LR_LON_PRODUCT"], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat))
            };

            // band parameters
            List <RasterImagingBand> bandData = new List <RasterImagingBand>();

            Int32 numberOfBands = 0;

            Double[] solarIrradiance = null;

            switch (device.MissionNumber)
            {
            case 7:
                numberOfBands = 8;
                // solar irradiance is constant for Landsat 7, see: http://landsathandbook.gsfc.nasa.gov/pdfs/Landsat_Calibration_Summary_RSE.pdf
                solarIrradiance = new Double[] { 1997, 1812, 1533, 1039, 230.8, Double.NaN, 84.9, 1362 };
                break;

            case 8:
                numberOfBands = 11;
                // solar irradiance is not provided for Landsat 8, see: http://landsat.usgs.gov/ESUN.php
                solarIrradiance = Enumerable.Repeat(Double.NaN, 11).ToArray();
                break;
            }

            for (Int32 bandNumber = 1; bandNumber <= numberOfBands; bandNumber++)
            {
                String indexString = bandNumber.ToString();
                if (device.MissionNumber == 7 && bandNumber == 6) // Landsat 7 band 6 has high gain and low gain modes
                {
                    indexString += "_VCID_1";
                }

                Double maximumRadiance = Double.Parse(_metadata["RADIANCE_MAXIMUM_BAND_" + indexString], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);
                Double minimumRadiance = Double.Parse(_metadata["RADIANCE_MINIMUM_BAND_" + indexString], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);
                Double qCalMax         = Double.Parse(_metadata["QUANTIZE_CAL_MAX_BAND_" + indexString], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);
                Double qCalMin         = Double.Parse(_metadata["QUANTIZE_CAL_MIN_BAND_" + indexString], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat);


                Double physicalGain = (maximumRadiance - minimumRadiance) / (qCalMax - qCalMin);
                Double physicalBias = minimumRadiance;

                // match the device band data
                ImagingDeviceBand deviceBand = null;

                if (device != null)
                {
                    deviceBand = device.Bands.FirstOrDefault(band => band.Description.Contains("BAND " + bandNumber));
                }

                if (deviceBand != null)
                {
                    bandData.Add(new RasterImagingBand(deviceBand.Description, physicalGain, physicalBias, solarIrradiance[bandNumber - 1], deviceBand.SpectralDomain, deviceBand.SpectralRange));
                }
                else // if no match is found
                {
                    bandData.Add(new RasterImagingBand("BAND " + bandNumber, physicalGain, physicalBias, solarIrradiance[bandNumber - 1], SpectralDomain.Undefined, null));
                }
            }

            RasterImaging imaging = new RasterImaging(device, imagingDateTime, GeoCoordinate.Undefined, imageLocation, incidenceAngle, viewingAngle, sunAzimuth, sunElevation, bandData);

            foreach (String key in _metadata.Keys)
            {
                if (_imagingPropertyKeys.Contains(key))
                {
                    imaging[key] = _metadata[key];
                }
            }

            return(imaging);
        }