/// <summary>
        /// Reprojects image
        /// </summary>
        public static TestingResult Reproject(MapWinGIS.Image image, out MapWinGIS.Image imageNew, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            MapWinGIS.GeoProjection projImage = new MapWinGIS.GeoProjection();
            projImage.ImportFromProj4(image.GetProjection());

            string sourcePrj    = image.GetProjection();
            string targetPrj    = projection.ExportToProj4();
            string origFilename = image.Filename;

            MapWinGIS.ICallback callback = image.GlobalCallback;
            imageNew = null;

            LayerSource obj    = new LayerSource(image);
            LayerSource objNew = null;

            if (CoordinateTransformation.SeekSubstituteFile(obj, projection, out objNew))
            {
                imageNew = objNew.Image;
                return(TestingResult.Substituted);
            }

            string newFilename = CoordinateTransformation.FilenameWithProjectionSuffix(origFilename, projImage, projection);

            newFilename = CoordinateTransformation.GetSafeNewName(newFilename);

            // setting callback
            if (report != null)
            {
                if (!report.Visible)
                {
                    report.InitProgress(projection);
                }

                report.ShowFilename(image.Filename);
            }

            MapWinGIS.GeoProcess.SpatialReference.ProjectImage(sourcePrj, targetPrj, origFilename, newFilename, report);

            if (report != null)
            {
                report.ClearFilename();
            }

            imageNew = new MapWinGIS.Image();
            if (imageNew.Open(newFilename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, callback))
            {
                return(TestingResult.Ok);
            }
            else
            {
                imageNew = null;
                return(TestingResult.Error);
            }
        }
        /// <summary>
        /// Reprojects a grid
        /// </summary>
        /// <param name="grid">Grid object to reproject</param>
        /// <param name="inPlace">Whether reprojected file should replace the initial one</param>
        /// <returns>True on success and false otherwise</returns>
        public static TestingResult Reproject(MapWinGIS.Grid grid, out MapWinGIS.Grid gridNew, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            string sourcePrj    = grid.Header.GeoProjection.ExportToProj4();
            string targetPrj    = projection.ExportToProj4();
            string origFilename = grid.Filename;

            MapWinGIS.ICallback callback = grid.GlobalCallback;
            gridNew = null;

            LayerSource obj    = new LayerSource(grid);
            LayerSource objNew = null;

            if (CoordinateTransformation.SeekSubstituteFile(obj, projection, out objNew))
            {
                gridNew = objNew.Grid;
                return(TestingResult.Substituted);
            }

            string newFilename = CoordinateTransformation.FilenameWithProjectionSuffix(origFilename, grid.Header.GeoProjection, projection);

            newFilename = CoordinateTransformation.GetSafeNewName(newFilename);

            // setting callback
            if (report != null)
            {
                if (!report.Visible)
                {
                    report.InitProgress(projection);
                }

                report.ShowFilename(grid.Filename);
            }

            bool result = MapWinGIS.GeoProcess.SpatialReference.ProjectGrid(ref sourcePrj, ref targetPrj, ref origFilename, ref newFilename, true, report);

            if (report != null)
            {
                report.ClearFilename();
            }

            if (!result)
            {
                return(TestingResult.Error);
            }

            // TODO: no need to open it if only a name is supposed to be returned
            gridNew = new MapWinGIS.Grid();
            gridNew.Open(newFilename, MapWinGIS.GridDataType.UnknownDataType, false, MapWinGIS.GridFileType.UseExtension, callback);
            gridNew.AssignNewProjection(projection.ExportToProj4());

            return(TestingResult.Ok);
        }
        /// <summary>
        /// Reprojects a shapefile
        /// </summary>
        /// <param name="grid">Shapefile object to reproject</param>
        /// <param name="inPlace">Whether reprojected file should replace the initial one</param>
        /// <returns>True on success and false otherwise</returns>
        public static TestingResult Reproject(MapWinGIS.Shapefile sfSource, out MapWinGIS.Shapefile sfNew, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            sfNew = null;

            string origFilename = sfSource.Filename;

            MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
            int count = 0;

            LayerSource obj    = new LayerSource(sfSource);
            LayerSource objNew = null;

            if (CoordinateTransformation.SeekSubstituteFile(obj, projection, out objNew))
            {
                sfNew = objNew.Shapefile;
                return(TestingResult.Substituted);
            }

            string newFilename = CoordinateTransformation.FilenameWithProjectionSuffix(origFilename, sfSource.GeoProjection, projection);

            newFilename = CoordinateTransformation.GetSafeNewName(newFilename);

            // settings callback
            MapWinGIS.ICallback callback = sfSource.GlobalCallback;
            if (report != null)
            {
                sfSource.GlobalCallback = report;

                if (!report.Visible)
                {
                    report.InitProgress(projection);
                }

                report.ShowFilename(sfSource.Filename);
            }

            // doing the job
            sf = sfSource.Reproject(projection, ref count);

            // restoring callback
            if (report != null)
            {
                sfSource.GlobalCallback = callback;
                report.ClearFilename();
            }

            if (sf != null && count == sfSource.NumShapes)
            {
                sf.GlobalCallback = sfSource.GlobalCallback;
                bool result = sf.SaveAs(newFilename, null);        // it doesn't close the editing mode
                if (!result)
                {
                    System.Diagnostics.Debug.Print("Error while saving reprojected shapefile: " + sf.get_ErrorMsg(sf.LastErrorCode));
                }
                sfNew = sf;
                return(TestingResult.Ok);
            }

            //sf.Close();
            return(TestingResult.Error);
        }