Example #1
0
        static void Mosaic(IRasterCatalog rasterCatalog)
        {
            try
            {
                //Mosaics all rasters in the raster catalog to an output raster dataset
                IMosaicRaster mosaicRaster = new MosaicRasterClass();
                mosaicRaster.RasterCatalog = rasterCatalog;

                //Set mosaicking options, you may not need to set these for your data
                mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

                //Open output workspace
                IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
                IWorkspace        workspace        = workspaceFactory.OpenFromFile(outputFolder, 0);

                //Save out to a target raster dataset
                //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect.
                ISaveAs saveas = (ISaveAs)mosaicRaster;
                saveas.SaveAs(outputName, workspace, "TIFF");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 合并栅格目录中的所有栅格
        /// </summary>
        /// <param name="pRasterCatalog"></param>
        /// <param name="outputFolder"></param>
        /// <param name="pOutputName"></param>
        public void Mosaic(IRasterCatalog pRasterCatalog, IWorkspace pWorkspace, string pOutputName)
        {
            IMosaicRaster pMosaicRaster = new MosaicRasterClass();

            pMosaicRaster.RasterCatalog = pRasterCatalog;


            pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
            pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

            ISaveAs pSaveas = (ISaveAs)pMosaicRaster;

            pSaveas.SaveAs(pOutputName, pWorkspace, "IMAGINE Image");
        }
Example #3
0
        /// <summary>
        /// 合并栅格目录中的所有栅格
        /// </summary>
        /// <param name="pRasterCatalog"></param>
        /// <param name="outputFolder"></param>
        /// <param name="pOutputName"></param>
        public void Mosaic(IRasterCatalog pRasterCatalog, IWorkspace pWorkspace, string pOutputName)
        {
            IMosaicRaster pMosaicRaster = new MosaicRasterClass();
            pMosaicRaster.RasterCatalog = pRasterCatalog;

            pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
            pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

            ISaveAs pSaveas = (ISaveAs)pMosaicRaster;
            pSaveas.SaveAs(pOutputName, pWorkspace, "IMAGINE Image");
        }
        static void Mosaic(IRasterCatalog rasterCatalog)
        {
            try
            {
                //Mosaics all rasters in the raster catalog to an output raster dataset
                IMosaicRaster mosaicRaster = new MosaicRasterClass();
                mosaicRaster.RasterCatalog = rasterCatalog;

                //Set mosaicking options, you may not need to set these for your data
                mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

                //Open output workspace
                IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
                IWorkspace workspace = workspaceFactory.OpenFromFile(outputFolder, 0);

                //Save out to a target raster dataset
                //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect.
                ISaveAs saveas = (ISaveAs)mosaicRaster;
                saveas.SaveAs(outputName, workspace, "TIFF");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
Example #5
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            try
            {
                IRasterCollection pRasterCollection = new MosaicRasterClass();
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    IRasterLayer prasterlayer = new RasterLayerClass();
                    prasterlayer.CreateFromFilePath(listBox1.Items[i].ToString());
                    pRasterCollection.Append(prasterlayer.Raster);
                }
                IMosaicRaster pMosaicRaster = pRasterCollection as IMosaicRaster;
                switch (cmbox_operatortype.SelectedIndex)
                {
                case 0:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_FIRST;
                    break;

                case 1:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;
                    break;

                case 2:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_MIN;
                    break;

                case 3:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_MAX;
                    break;

                case 4:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_MEAN;
                    break;

                case 5:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_BLEND;
                    break;

                default:
                    pMosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;
                    break;
                }
                switch (comboBox_colormap.SelectedIndex)
                {
                case 0:
                    pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_FIRST;
                    break;

                case 1:
                    pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_LAST;
                    break;

                case 2:
                    pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                    break;

                case 3:
                    pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_REJECT;
                    break;

                default:
                    pMosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_FIRST;
                    break;
                }
                if (string.IsNullOrEmpty(textBoxX_output.Text) == true)
                {
                    return;
                }
                //如果直接保存为img影像文件
                IWorkspaceFactory pWKSF      = new RasterWorkspaceFactoryClass();
                IWorkspace        pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(textBoxX_output.Text), 0);
                ISaveAs           pSaveAs    = pMosaicRaster as ISaveAs;
                IDataset          pDataset   = pSaveAs.SaveAs(System.IO.Path.GetFileNameWithoutExtension(textBoxX_output.Text) + ".tif", pWorkspace, "TIFF");//以TIF格式保存
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }