예제 #1
0
        /// <summary>
        /// Prepares the result of the operation.
        /// </summary>
        /// <returns>The resulting object.</returns>
        protected override ISpectralGeometry PrepareResult()
        {
            SetResultProperties(Source.Raster.Format, Source.Raster.Dimensions, Source.Raster.Mapper, Source.Presentation, Source.Imaging);

            // raster
            IRaster raster;

            if (State == OperationState.Initialized)
            {
                raster = Factory.GetFactory <IRasterFactory>().CreateRaster(new SpectralTransformationService(this, _resultFormat, _resultDimensions), _resultMapper);
            }
            else
            {
                raster = Factory.GetFactory <IRasterFactory>().CreateRaster(_resultFormat, _resultDimensions.NumberOfBands, _resultDimensions.NumberOfRows, _resultDimensions.NumberOfColumns, _resultDimensions.RadiometricResolution, _resultMapper);
            }

            // geometry
            IGeometry geometry;

            if (_resultGeometry != null)
            {
                geometry = _resultGeometry;
            }
            else if (Source.Raster.Dimensions.Equals(_resultDimensions) && (Source.Raster.Mapper != null && _resultMapper != null && Source.Raster.Mapper.Equals(_resultMapper)))
            {
                geometry = Source;
            }
            else
            {
                if (_resultMapper == null)
                {
                    geometry = Source.Factory.CreatePolygon(new Coordinate(0, 0),
                                                            new Coordinate(_resultDimensions.NumberOfRows, 0),
                                                            new Coordinate(_resultDimensions.NumberOfRows, _resultDimensions.NumberOfColumns),
                                                            new Coordinate(0, _resultDimensions.NumberOfColumns));
                }
                else if (_resultMapper.Mode == RasterMapMode.ValueIsArea)
                {
                    geometry = Source.Factory.CreatePolygon(_resultMapper.MapCoordinate(0, 0),
                                                            _resultMapper.MapCoordinate(_resultDimensions.NumberOfRows - 1, 0),
                                                            _resultMapper.MapCoordinate(_resultDimensions.NumberOfRows - 1, _resultDimensions.NumberOfColumns - 1),
                                                            _resultMapper.MapCoordinate(0, _resultDimensions.NumberOfColumns - 1));
                }
                else
                {
                    geometry = Source.Factory.CreatePolygon(_resultMapper.MapCoordinate(0, 0),
                                                            _resultMapper.MapCoordinate(_resultDimensions.NumberOfRows, 0),
                                                            _resultMapper.MapCoordinate(_resultDimensions.NumberOfRows, _resultDimensions.NumberOfColumns),
                                                            _resultMapper.MapCoordinate(0, _resultDimensions.NumberOfColumns));
                }
            }

            // result
            return(Factory.CreateSpectralGeometry(geometry, raster, _resultPresentation, _resultImaging));
        }
예제 #2
0
        /// <summary>
        /// Prepares the result of the operation.
        /// </summary>
        /// <returns>The resulting geometry.</returns>
        protected override ISpectralGeometry PrepareResult()
        {
            // compute the mapper
            RasterMapper mapper  = null;
            IPolygon     polygon = null;

            if (Source.Raster.IsMapped)
            {
                mapper = RasterMapper.FromMapper(Source.Raster.Mapper,
                                                 (Coordinate)(Source.Raster.Mapper.MapCoordinate(SourceRowOffset, SourceColumnOffset) - Source.Raster.Mapper.MapCoordinate(0, 0)),
                                                 new CoordinateVector(SourceRowCount / _targetNumberOfRows, SourceColumnCount / _targetNumberOfColumns));

                if (mapper.Mode == RasterMapMode.ValueIsArea)
                {
                    polygon = Source.Factory.CreatePolygon(mapper.MapCoordinate(0, 0),
                                                           mapper.MapCoordinate(_targetNumberOfRows - 1, 0),
                                                           mapper.MapCoordinate(_targetNumberOfRows - 1, _targetNumberOfColumns - 1),
                                                           mapper.MapCoordinate(0, _targetNumberOfColumns - 1));
                }
                else
                {
                    polygon = Source.Factory.CreatePolygon(mapper.MapCoordinate(0, 0),
                                                           mapper.MapCoordinate(_targetNumberOfRows, 0),
                                                           mapper.MapCoordinate(_targetNumberOfRows, _targetNumberOfColumns),
                                                           mapper.MapCoordinate(0, _targetNumberOfColumns));
                }
            }
            else
            {
                polygon = Source.Factory.CreatePolygon(new Coordinate(0, 0),
                                                       new Coordinate(_targetNumberOfRows, 0),
                                                       new Coordinate(_targetNumberOfRows, _targetNumberOfColumns),
                                                       new Coordinate(0, _targetNumberOfColumns));
            }

            SetResultProperties(Source.Raster.Format, Source.Raster.NumberOfBands, _targetNumberOfRows, _targetNumberOfColumns, Source.Raster.RadiometricResolution, mapper);

            return(base.PrepareResult());
        }
예제 #3
0
        public void RasterMapperMapCoordinateTest()
        {
            // value is coordinate

            RasterMapper mapper = RasterMapper.FromTransformation(RasterMapMode.ValueIsCoordinate, 300, 1000, 0, 10, 3, 0);

            for (Int32 i = -100; i < 100; i += 3)
            {
                for (Int32 j = -100; j < 100; j += 3)
                {
                    Coordinate coordinate = mapper.MapCoordinate(j, i);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate((Double)j, (Double)i);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate(j, i, RasterMapMode.ValueIsCoordinate);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate(j, i, RasterMapMode.ValueIsArea);

                    Assert.AreEqual(295 + i * 10, coordinate.X);
                    Assert.AreEqual(998.5 + j * 3, coordinate.Y);
                }
            }


            // value is area

            mapper = RasterMapper.FromTransformation(RasterMapMode.ValueIsArea, 300, 1000, 0, 10, 3, 1);

            for (Int32 i = -100; i < 100; i += 3)
            {
                for (Int32 j = -100; j < 100; j += 3)
                {
                    Coordinate coordinate = mapper.MapCoordinate(j, i);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate((Double)j, (Double)i);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate(j, i, RasterMapMode.ValueIsCoordinate);

                    Assert.AreEqual(305 + i * 10, coordinate.X);
                    Assert.AreEqual(1001.5 + j * 3, coordinate.Y);

                    coordinate = mapper.MapCoordinate(j, i, RasterMapMode.ValueIsArea);

                    Assert.AreEqual(300 + i * 10, coordinate.X);
                    Assert.AreEqual(1000 + j * 3, coordinate.Y);
                }
            }
        }
예제 #4
0
        public void RasterMapperFromCoordinatesTest()
        {
            RasterMapper sourceMapper = RasterMapper.FromTransformation(RasterMapMode.ValueIsCoordinate, new Coordinate(300, 1000, 0), new CoordinateVector(10, 3));

            RasterMapper mapper = RasterMapper.FromCoordinates(RasterMapMode.ValueIsCoordinate,
                                                               new RasterCoordinate(0, 0, sourceMapper.MapCoordinate(0, 0)),
                                                               new RasterCoordinate(100, 0, sourceMapper.MapCoordinate(100, 0)),
                                                               new RasterCoordinate(100, 100, sourceMapper.MapCoordinate(100, 100)),
                                                               new RasterCoordinate(0, 100, sourceMapper.MapCoordinate(0, 100))
                                                               );

            Assert.AreEqual(RasterMapMode.ValueIsCoordinate, mapper.Mode);
            Assert.AreEqual(sourceMapper.ColumnVector, mapper.ColumnVector);
            Assert.AreEqual(sourceMapper.RowVector, mapper.RowVector);
            Assert.AreEqual(sourceMapper.Translation.X, mapper.Translation.X, 0.000001);
            Assert.AreEqual(sourceMapper.Translation.Y, mapper.Translation.Y, 0.000001);
            Assert.AreEqual(sourceMapper.Translation.Z, mapper.Translation.Z, 0.000001);

            // exceptions

            Assert.Throws <ArgumentNullException>(() => RasterMapper.FromCoordinates(RasterMapMode.ValueIsCoordinate, null));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromCoordinates(RasterMapMode.ValueIsCoordinate, new RasterCoordinate(0, 0, sourceMapper.MapCoordinate(0, 0)), new RasterCoordinate(0, 100, sourceMapper.MapCoordinate(0, 100))));
            Assert.Throws <ArgumentException>(() => RasterMapper.FromCoordinates(RasterMapMode.ValueIsCoordinate, new RasterCoordinate(0, 0, sourceMapper.MapCoordinate(0, 0)), new RasterCoordinate(100, 0, sourceMapper.MapCoordinate(100, 0))));
        }