Exemplo n.º 1
0
        /// <summary>
        /// This is the non-optional projection check. This does the function above but then only gives a warning, not a yes/no chooser
        ///
        /// IN THEORY THIS SHOULD NEVER TRIGGER SINCE WE'RE SO CAREFUL NOT TO IMPORT ANY BAD PROJECTIONS
        /// </summary>
        /// <param name="gisDS"></param>
        /// <returns></returns>
        public static bool DSSpatialRefMatchesProjectWithMsgbox(GISDataset gisDS, string sTypeSingle, string sTypePlural)
        {
            if (DSSpatialRefMatchesProject(gisDS))
            {
                string msg = string.Format(
                    "{0}{1}{0} Projections must match exactly.",
                    Environment.NewLine, GISDatasetValidation.SpatialRefNoMatchString(gisDS, sTypeSingle, sTypePlural));

                MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static frmImportRaster PrepareToImportRaster(Surface refSurface, Purposes purpose, string Noun, IntPtr parentWindow)
        {
            frmImportRaster frm    = null;
            Raster          source = ProjectManager.BrowseRaster(naru.ui.UIHelpers.WrapMessageWithNoun("Browse and Select a", Noun, "Raster"), parentWindow);

            if (source is Raster)
            {
                if (GISDatasetValidation.DSHasSpatialRef(source, "raster", "rasters"))
                {
                    frm = new frmImportRaster(source, refSurface, purpose, Noun);
                }
            }

            return(frm);
        }
Exemplo n.º 3
0
        private bool ValidateForm()
        {
            // Sanity check to avoid empty names
            txtName.Text = txtName.Text.Trim();

            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("You must provide a name for the point density associated surface.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (!DEM.IsAssocNameUnique(txtName.Text, Assoc))
            {
                MessageBox.Show("The name '" + txtName.Text + "' is already in use by another associated surface within this survey. Please choose a unique name.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtName.Select();
                return(false);
            }

            if (ucPointCloud.SelectedItem is GCDConsoleLib.Vector)
            {
                if (!GISDatasetValidation.DSHasSpatialRef(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
                    !GISDatasetValidation.DSSpatialRefMatchesProjectWithMsgbox(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
                    !GISDatasetValidation.DSHorizUnitsMatchProject(ucPointCloud.SelectedItem, "feature class", "feature classes") ||
                    !GISDatasetValidation.DSGeometryTypeMatches((Vector)ucPointCloud.SelectedItem, GDalGeometryType.SimpleTypes.Point))
                {
                    ucPointCloud.Select();
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("You must select a point cloud Shape File to continue.", "Missing Point Shape File", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public Raster ProcessRaster()
        {
            Cursor = Cursors.WaitCursor;

            Raster gResult = null;

            System.IO.FileInfo fiOutput = ProjectManager.Project.GetAbsolutePath(txtRasterPath.Text);

            if (fiOutput.Exists)
            {
                Exception ex = new Exception("The raster path already exists.");
                ex.Data.Add("Raster path", txtRasterPath.Text);
                throw ex;
            }

            fiOutput.Directory.Create();

            if (ExtImporter.RequiresResampling)
            {
                gResult = RasterOperators.BilinearResample(SourceRaster, fiOutput, ExtImporter.OutExtent, ProjectManager.OnProgressChange);
            }
            else
            {
                if (SourceRaster.Extent.Equals(ExtImporter.OutExtent))
                {
                    // Output extent is same as original raster. Simple dataset copy
                    if (SourceRaster.driver == Raster.RasterDriver.GTiff)
                    {
                        SourceRaster.Copy(fiOutput);
                        gResult = new Raster(fiOutput);
                    }
                    else
                    {
                        gResult = RasterOperators.ExtendedCopy(SourceRaster, fiOutput, ProjectManager.OnProgressChange);
                    }
                }
                else
                {
                    // Output extent differs from original raster. Use extended copy
                    gResult = RasterOperators.ExtendedCopy(SourceRaster, fiOutput, ExtImporter.OutExtent, ProjectManager.OnProgressChange);
                }
            }

            // This method will check to see if pyrmaids are need and then build if necessary.
            PerformRasterPyramids(new System.IO.FileInfo(txtRasterPath.Text));

            if (Purpose == Purposes.FirstDEM || Purpose == Purposes.SubsequentDEM || Purpose == Purposes.ReferenceSurface)
            {
                // Now try the hillshade for DEM Surveys and reference surfaces
                System.IO.FileInfo sHillshadePath = Surface.HillShadeRasterPath(fiOutput);
                RasterOperators.Hillshade(gResult, sHillshadePath, ProjectManager.OnProgressChange);
                ProjectManager.PyramidManager.PerformRasterPyramids(RasterPyramidManager.PyramidRasterTypes.Hillshade, sHillshadePath);
            }


            Cursor = Cursors.Default;

            Projection projRef = GISDatasetValidation.GetProjectProjection();

            if (projRef != null && NeedsForcedProjection)
            {
                gResult.SetProjection(projRef);
            }

            return(gResult);
        }
Exemplo n.º 5
0
        private bool ValidateForm()
        {
            // Sanity check to avoid names with only spaces
            txtName.Text = txtName.Text.Trim();

            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("The raster name cannot be empty.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtName.Select();
                return(false);
            }

            switch (Purpose)
            {
            case Purposes.SubsequentDEM:
                if (!ProjectManager.Project.IsDEMNameUnique(txtName.Text, null))
                {
                    MessageBox.Show(string.Format("There is already another DEM survey in this project with the name '{0}'. Each DEM Survey must have a unique name.", txtName.Text), Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtName.Select();
                    return(false);
                }
                break;

            case Purposes.AssociatedSurface:
                if (!((DEMSurvey)ReferenceSurface).IsAssocNameUnique(txtName.Text, null))
                {
                    MessageBox.Show(string.Format("There is already another associated surface for this DEM with the name '{0}'. The associated surfaces for each DEM must have a unique name.", txtName.Text), Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtName.Select();
                    return(false);
                }
                break;

            case Purposes.ErrorSurface:
            case Purposes.ReferenceErrorSurface:
                if (!ReferenceSurface.IsErrorNameUnique(txtName.Text, null))
                {
                    string parentType = "Reference Surface";
                    if (ReferenceSurface is DEMSurvey)
                    {
                        parentType = "DEM Survey";
                    }

                    MessageBox.Show(string.Format("There is already another error surface for this {0} with the name '{1}'. The error surfaces for each {0} must have a unique name.", parentType, txtName.Text), Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtName.Select();
                    return(false);
                }
                break;

            case Purposes.ReferenceSurface:
                if (!ProjectManager.Project.IsReferenceSurfaceNameUnique(txtName.Text, null))
                {
                    MessageBox.Show(string.Format("There is already another reference surface with the name '{0}'. Each reference surface must have a unique name.", txtName.Text), Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtName.Select();
                    return(false);
                }
                break;
            }


            NeedsForcedProjection = false;

            // Importing rasters into GCD projects requires unit checks
            if (!GISDatasetValidation.DSSpatialRefMatchesProject(SourceRaster))
            {
                string msg = string.Format(
                    "{0}{1}{0}If you believe that these projections are the same (or equivalent) choose \"Yes\" to continue anyway. Otherwise choose \"No\" to abort.",
                    Environment.NewLine, GISDatasetValidation.SpatialRefNoMatchString(SourceRaster, "raster", "rasters"));

                DialogResult result = MessageBox.Show(msg, Properties.Resources.ApplicationNameLong, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

                if (result == DialogResult.No)
                {
                    NeedsForcedProjection = false;
                    return(false);
                }
                else
                {
                    NeedsForcedProjection = true;
                }
            }

            // TODO: This check appears to be VERY similar to the next block of code. Research and simplify if possible.
            if (!GISDatasetValidation.DSHorizUnitsMatchProject(SourceRaster, "raster", "rasters"))
            {
                return(false);
            }

            // Verify that the horizontal units match those of the project.
            if (ProjectManager.Project.Units.HorizUnit != SourceRaster.Proj.HorizontalUnit)
            {
                string msg = string.Format("The horizontal units of the raster ({0}) do not match those of the GCD project ({1}).", SourceRaster.Proj.HorizontalUnit.ToString(), ProjectManager.Project.Units.HorizUnit.ToString());
                if (ProjectManager.Project.DEMSurveys.Count < 1)
                {
                    msg += " You can change the GCD project horizontal units by canceling this form and opening the GCD project properties form.";
                }
                MessageBox.Show(msg, "HorizontalUnits Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            // Verify the optional vertical units (if they are specified) for rasters that should share the project vertical units
            if (Purpose == Purposes.FirstDEM || Purpose == Purposes.SubsequentDEM)
            {
                if (SourceRaster.VerticalUnits != UnitsNet.Units.LengthUnit.Undefined)
                {
                    if (SourceRaster.VerticalUnits != ProjectManager.Project.Units.VertUnit)
                    {
                        MessageBox.Show(string.Format("The raster has different vertical units ({0}) than the GCD project ({1})." + " You must change the vertical units of the raster before it can be used within the GCD.", SourceRaster.VerticalUnits.ToString(), ProjectManager.Project.Units.VertUnit.ToString()), "Vertical Units Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(false);
                    }
                }
            }


            if (string.IsNullOrEmpty(txtRasterPath.Text))
            {
                //if (ExtImporter.Purpose == ExtentImporter.Purposes.Standalone)
                //{
                //    MessageBox.Show("The output raster path cannot be empty. Click the Save button to specify an output raster path.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
                //else
                //{
                MessageBox.Show("The output raster path cannot be empty. Try using a different name.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
                return(false);
            }
            else
            {
                System.IO.FileInfo outputPath = new System.IO.FileInfo(txtRasterPath.Text);
                if (ProjectManager.Project != null)
                {
                    outputPath = ProjectManager.Project.GetAbsolutePath(txtRasterPath.Text);
                }

                if (outputPath.Exists)
                {
                    MessageBox.Show("The project raster path already exists. Try using a different name for the raster.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }
                else
                {
                    string sExtension = System.IO.Path.GetExtension(txtRasterPath.Text);
                    if (string.Compare(sExtension, ".tif", true) != 0)
                    {
                        MessageBox.Show("This tool can only currently produce GeoTIFF rasters. Please provide an output raster path ending with '.tif'", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(false);
                    }
                }
            }

            if (valCellSize.Value <= 0)
            {
                MessageBox.Show("The cell size must be greater than or equal to zero.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if ((valRight.Value - valLeft.Value) < valCellSize.Value)
            {
                MessageBox.Show("The right edge of the extent must be at least one cell width more than the left edge of the extent.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (valTop.Value - valBottom.Value < valCellSize.Value)
            {
                MessageBox.Show("The top edge of the extent must be at least one cell width more than the bottom edge of the extent.", Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }