Ejemplo n.º 1
0
        /// <summary>
        /// Reads the raster mapping stored in the metafile stream.
        /// </summary>
        /// <returns>The raster mapping.</returns>
        protected override RasterMapper ReadMappingInternal()
        {
            List <RasterCoordinate> coordinates = new List <RasterCoordinate>(4);

            foreach (XElement vertexElement in _document.Element("Dimap_Document").Element("Dataset_Frame").Elements("Vertex"))
            {
                RasterCoordinate coordinate = new RasterCoordinate(
                    Int32.Parse(vertexElement.Element("FRAME_ROW").Value, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                    Int32.Parse(vertexElement.Element("FRAME_COL").Value, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                    Double.Parse(vertexElement.Element("FRAME_LAT").Value, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat),
                    Double.Parse(vertexElement.Element("FRAME_LON").Value, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat)
                    );

                coordinates.Add(coordinate);
            }

            return(RasterMapper.FromCoordinates(RasterMapMode.ValueIsArea, coordinates));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the mapping from model space to raster space.
        /// </summary>
        /// <returns>The mapping from model space to raster space.</returns>
        protected RasterMapper ComputeRasterToModelSpaceMapping()
        {
            if (!_currentGeoKeys.ContainsKey(GeoKey.RasterType))
            {
                return(null);
            }

            RasterMapMode mode = Convert.ToInt16(_currentGeoKeys[GeoKey.RasterType]) == 1 ? RasterMapMode.ValueIsArea : RasterMapMode.ValueIsCoordinate;

            Double[] modelTiePointsArray      = null;
            Double[] modelPixelScaleArray     = null;
            Double[] modelTransformationArray = null;

            // gather information from tags
            if (_imageFileDirectories[_currentImageIndex].ContainsKey(TiffTag.ModelTiepointTag))
            {
                modelTiePointsArray = _imageFileDirectories[_currentImageIndex][TiffTag.ModelTiepointTag].Select(value => Convert.ToDouble(value)).ToArray();
            }
            if (_imageFileDirectories[_currentImageIndex].ContainsKey(TiffTag.ModelPixelScaleTag))
            {
                modelPixelScaleArray = _imageFileDirectories[_currentImageIndex][TiffTag.ModelPixelScaleTag].Select(value => Convert.ToDouble(value)).ToArray();
            }
            if (_imageFileDirectories[_currentImageIndex].ContainsKey(TiffTag.ModelTransformationTag))
            {
                modelTransformationArray = _imageFileDirectories[_currentImageIndex][TiffTag.ModelTransformationTag].Select(value => Convert.ToDouble(value)).ToArray();
            }

            // for GeoTIFF 0.2, IntergraphMatrixTag (33920) may contain the transformation values
            if (modelTransformationArray == null && _imageFileDirectories[_currentImageIndex].ContainsKey(TiffTag.IntergraphMatrixTag))
            {
                modelTransformationArray = _imageFileDirectories[_currentImageIndex][TiffTag.IntergraphMatrixTag].Select(value => Convert.ToDouble(value)).ToArray();
            }

            // compute with model tie points
            if (modelTiePointsArray != null && (modelTiePointsArray.Length > 6 || (modelTiePointsArray.Length == 6 && modelPixelScaleArray.Length == 3)))
            {
                if (modelTiePointsArray.Length > 6) // transformation is specified by tie points
                {
                    RasterCoordinate[] coordinates = new RasterCoordinate[modelTiePointsArray.Length / 6];

                    for (Int32 i = 0; i < modelTiePointsArray.Length; i += 6)
                    {
                        coordinates[i / 6] = new RasterCoordinate(Convert.ToInt32(modelTiePointsArray[i]), Convert.ToInt32(modelTiePointsArray[i + 1]), new Coordinate(modelTiePointsArray[i + 3], modelTiePointsArray[i + 4], modelTiePointsArray[i + 5]));
                    }

                    return(RasterMapper.FromCoordinates(mode, coordinates));
                }
                else // transformation is specified by single tie point and scale
                {
                    Coordinate rasterSpaceCoordinate = new Coordinate(modelTiePointsArray[0], modelTiePointsArray[1], modelTiePointsArray[2]);
                    Coordinate modelSpaceCoordinate  = new Coordinate(modelTiePointsArray[3], modelTiePointsArray[4], modelTiePointsArray[5]);
                    Double     scaleX = modelPixelScaleArray[0];
                    Double     scaleY = -modelPixelScaleArray[1];
                    Double     scaleZ = modelPixelScaleArray[2];

                    return(RasterMapper.FromTransformation(mode,
                                                           modelSpaceCoordinate.X - rasterSpaceCoordinate.X * scaleX,
                                                           modelSpaceCoordinate.Y + rasterSpaceCoordinate.Y * scaleY,
                                                           modelSpaceCoordinate.Z - rasterSpaceCoordinate.Z * scaleZ,
                                                           scaleX, scaleY, scaleZ));
                }
            }

            // compute with transformation values
            if (modelTransformationArray != null)
            {
                Matrix transformation = new Matrix(4, 4);
                for (Int32 i = 0; i < 4; i++)
                {
                    for (Int32 j = 0; j < 4; j++)
                    {
                        transformation[i, j] = modelTransformationArray[i * 4 + j];
                    }
                }
                return(RasterMapper.FromTransformation(mode, transformation));
            }

            // nothing is available
            return(null);
        }