public IRaster mosaicRastersFunction(IWorkspace wks, string mosaicName, IRaster[] rasters, esriMosaicMethod mosaicmethod, rstMosaicOperatorType mosaictype, bool buildfootprint, bool buildboudary, bool seamlines, bool buildOverview)
 {
     IRaster rs1 = rasters[0];
     IEnvelope env = getCombinedExtents(rasters);
     int ht = System.Convert.ToInt32(env.Height);
     int wd = System.Convert.ToInt32(env.Width);
     int rec = System.Convert.ToInt32(ht * wd);
     IRasterProps rs1Props = (IRasterProps)rs1;
     IRasterBandCollection rsBc = (IRasterBandCollection)rs1;
     IGeoDataset rs1_2 = (IGeoDataset)rs1;
     ISpatialReference sr = rs1_2.SpatialReference;
     string mNm = getSafeOutputName(wks,mosaicName);
     IMosaicDataset msDset = createMosaicDataset(wks, sr, mNm, rs1Props.PixelType, rsBc.Count);
     msDset.MosaicFunction.MaxMosaicImageCount = rasters.Length;
     msDset.MosaicFunction.MosaicMethod = mosaicmethod;
     msDset.MosaicFunction.MosaicOperatorType = mosaictype;
     IFunctionRasterDataset fDset = (IFunctionRasterDataset)msDset;
     IPropertySet pSet = (fDset).Properties;
     pSet.SetProperty("MaxImageHeight", ht);
     pSet.SetProperty("MaxImageWidth", wd);
     pSet.SetProperty("MaxRecordCount", rec);
     pSet.SetProperty("DefaultResamplingMethod", 0);
     pSet.SetProperty("MaxMosaicImageCount", rasters.Length);
     pSet.SetProperty("MaxDownloadImageCount", rasters.Length);
     pSet.SetProperty("IsPreprocessedData", "True");
     pSet.SetProperty("MosaicOperator", 4);
     pSet.SetProperty("MosaicMethod", 0);
     fDset.Properties = pSet;
     IMosaicDatasetOperation msDsetOp = (IMosaicDatasetOperation)msDset;
     addRastersToMosaicDataset(msDset, rasters);
     ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass();
     msDsetOp.CalculateCellSizeRanges(computeArgs, null);
     if (buildfootprint)
     {
         IBuildFootprintsParameters fpArgs = new BuildFootprintsParametersClass();
         fpArgs.Method = esriBuildFootprintsMethods.esriBuildFootprintsByGeometry;
         msDsetOp.BuildFootprints(fpArgs, null);
     }
     if(buildboudary)
     {
         IBuildBoundaryParameters bndArgs = new BuildBoundaryParametersClass();
         bndArgs.AppendToExistingBoundary=true;
         msDsetOp.BuildBoundary(bndArgs,null);
     }
     if(seamlines)
     {
         IBuildSeamlinesParameters smArgs = new BuildSeamlinesParametersClass();
         smArgs.ModifySeamlines = true;
         msDsetOp.BuildSeamlines(smArgs, null);
     }
     if (buildOverview)
     {
         IDefineOverviewsParameters ofPar = new DefineOverviewsParametersClass();
         ofPar.ForceOverviewTiles = true;
         ((IOverviewTileParameters)ofPar).OverviewFactor = 3;
         msDsetOp.DefineOverviews(ofPar, null);
         IGenerateOverviewsParameters ovArgs = new GenerateOverviewsParametersClass();
         ovArgs.GenerateMissingImages = true;
         ovArgs.GenerateStaleImages = true;
         msDsetOp.GenerateOverviews(ovArgs, null);
     }
     fDset.Init((IRasterFunction)msDset.MosaicFunction, msDset.MosaicFunctionArguments);
     IRaster rs = createRaster((IRasterDataset)fDset);
     return rs;
 }
Example #2
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string                rstNm   = txtOutNm.Text;
            esriMosaicMethod      mMethod = (esriMosaicMethod)Enum.Parse(typeof(esriMosaicMethod), cmbMethod.Text);
            rstMosaicOperatorType mType   = (rstMosaicOperatorType)Enum.Parse(typeof(rstMosaicOperatorType), cmbType.Text);

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outWks == null)
            {
                MessageBox.Show("You must specify an output workspace", "No Workspace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <string> rsLst  = new List <string>();
            IEnvelope     cmbEnv = new EnvelopeClass();

            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                string    nm = rstDic[lsbRaster.Items[i].ToString()];
                string    bnd;
                IDataset  dSet  = (IDataset)rsUtil.openRasterDataset(nm, out bnd);
                IEnvelope rsEnv = ((IGeoDataset)dSet).Extent;
                cmbEnv.Union(rsEnv);
                string fPath = dSet.Workspace.PathName + dSet.BrowseName;
                //MessageBox.Show("Raster name = " + fPath);
                rsLst.Add(fPath);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dSet);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Building Mosaic Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.Show();
            rp.TopMost = true;
            if (chbOverview.Checked)
            {
                rp.addMessage("Building overviews will take additional time...");
            }
            try
            {
                outraster = rsUtil.mosaicRastersFunction(outWks, rstNm, rsLst.ToArray(), cmbEnv, mMethod, mType, chbFootprint.Checked, chbBoundary.Checked, chbSeamlines.Checked, chbOverview.Checked);
                rp.addMessage("Adding mosaic dataset to the map");
                if (mp != null && addToMap)
                {
                    rp.Show();
                    rp.Refresh();
                    IMosaicLayer rstLyr = new MosaicLayerClass();
                    rstLyr.CreateFromMosaicDataset((IMosaicDataset)((IRaster2)outraster).RasterDataset);
                    mp.AddLayer((ILayer)rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Mosaic Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
 public IRaster mergeRasterFunction(IRaster[] inRasters,rstMosaicOperatorType mergeMethod,string rstNm)
 {
     string dbStr = mosaicDir + "\\rsCatDb.gdb";
     IWorkspace wks = null;
     if (!System.IO.Directory.Exists(dbStr))
     {
         wks = geoUtil.CreateWorkSpace(mosaicDir, "rsCatDb.gdb");
     }
     else
     {
         wks = geoUtil.OpenRasterWorkspace(dbStr);
     }
     rstNm = getSafeOutputName(wks,rstNm);
     IRaster rs = mosaicRastersFunction(wks, rstNm, inRasters,esriMosaicMethod.esriMosaicNone,mergeMethod,false,false,false,false);
     return rs;
 }