예제 #1
0
        /// <summary>
        /// Compare the values of the metadata properties to those of the raster argument
        /// </summary>
        /// <param name="raster">A instance of class Raster</param>
        /// <returns>An Enum containing the comparison Result</returns>
        /// <remarks></remarks>
        public CompareMetadataResult CompareMetadata(StochasticTimeRaster raster, ref string compareMsg)
        {
            CompareMetadataResult retVal = CompareMetadataResult.Same;

            compareMsg = "";

            // Test number of cols.
            if (this.Width != raster.Width)
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in Number of Columns ({1} vs {0})", this.Width, raster.Width);
                return(CompareMetadataResult.RowColumnMismatch);
            }

            // Test number of rows.
            if (this.Height != raster.Height)
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in Number of Rows ({1} vs {0})", this.Height, raster.Height);
                return(CompareMetadataResult.RowColumnMismatch);
            }

            // Test XLL Corner. See if NOT negligable difference - arbitrarily 1/10 of cell size.
            // Can't use equality, because of float error
            if (Math.Abs(this.XllCorner - raster.XllCorner) > (this.CellSize / 10.0))
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in XllCorner ({1} vs {0})", this.XllCorner, raster.XllCorner);
                retVal     = CompareMetadataResult.UnimportantDifferences;
            }

            // Test YLL Corner.  See if NOT negligable difference - arbitrarily 1/10 of cell size.
            // Can't use equality, because of float error
            if (Math.Abs(this.YllCorner - raster.YllCorner) > (this.CellSize / 10.0))
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in YllCorner ({1} vs {0})", this.YllCorner, raster.YllCorner);
                retVal     = CompareMetadataResult.UnimportantDifferences;
            }

            // Test ProjectionString
            if (this.Projection != raster.Projection)
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in Projection String");
                retVal     = CompareMetadataResult.UnimportantDifferences;
            }

            // Test Cell Size. Cant use equality because of precision errors ( eg. 30D vs 30.000000000004D)
            if (Math.Abs(this.CellSize - raster.CellSize) > 0.0001)
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in Cell Size ({1} vs {0})", this.CellSize, raster.CellSize);
                retVal     = CompareMetadataResult.UnimportantDifferences;
            }

            // Test Cell Units
            if (this.CellSizeUnits != raster.CellSizeUnits)
            {
                compareMsg = string.Format(CultureInfo.InvariantCulture, "Mismatch in Cell Size Units ({1} vs {0})", this.CellSizeUnits, raster.CellSizeUnits);
                retVal     = CompareMetadataResult.UnimportantDifferences;
            }

            return(retVal);
        }
예제 #2
0
        public StochasticTimeRaster GetRaster(int transitionGroupId, int iteration)
        {
            if (!this.m_HasItems)
            {
                return(null);
            }

            SortedKeyMap1 <InitialTSTSpatial> m = this.m_Map.GetItem(transitionGroupId);

            if (m == null)
            {
                return(null);
            }

            InitialTSTSpatial v = m.GetItem(iteration);

            if (v == null)
            {
                return(null);
            }

            string FullFileName = Spatial.GetSpatialInputFileName(this.m_DataSheet, v.FileName, false);

            if (!this.m_Rasters.ContainsKey(FullFileName))
            {
                string CmpMsg                   = null;
                StochasticTimeRaster  r         = new StochasticTimeRaster(FullFileName, RasterDataType.DTInteger);
                CompareMetadataResult cmpResult = this.m_InputRasters.CompareMetadata(r, ref CmpMsg);

                if (cmpResult == CompareMetadataResult.RowColumnMismatch)
                {
                    string Message = string.Format(CultureInfo.InvariantCulture,
                                                   MessageStrings.ERROR_SPATIAL_FILE_MISMATCHED_METADATA,
                                                   v.FileName, CmpMsg);

                    throw new STSimException(Message);
                }
                else if (cmpResult == CompareMetadataResult.UnimportantDifferences)
                {
                    string Message = string.Format(CultureInfo.InvariantCulture,
                                                   MessageStrings.STATUS_SPATIAL_FILE_MISMATCHED_METADATA_INFO,
                                                   v.FileName, CmpMsg);

                    this.Scenario.RecordStatus(StatusType.Information, Message);
                }

                this.m_Rasters.Add(FullFileName, r);
            }

            return(this.m_Rasters[FullFileName]);
        }