Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string rstNm   = cmbRaster.Text;
            string wksNm   = txtWorkspace.Text;
            string outNm   = txtOutName.Text;
            string outType = cmbType.Text;
            int    blSize  = System.Convert.ToInt32(nudBS.Value);

            if (outWks == null || wksNm == "" || wksNm == null || rstNm == "" || rstNm == null || outNm == "" || outNm == null)
            {
                MessageBox.Show("Raster, Workspace, or Output Name are not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            object noDataVl = null;

            if (rsUtil.isNumeric(txtNoDataVl.Text) && txtNoDataVl.Visible)
            {
                noDataVl = System.Convert.ToDouble(txtNoDataVl.Text);
            }
            rasterUtil.rasterType rType = (rasterUtil.rasterType)Enum.Parse(typeof(rasterUtil.rasterType), outType);
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            rp.addMessage("Saving raster");
            rp.addMessage("This may take a while...");
            rp.stepPGBar(20);
            rp.Show();
            rp.Refresh();

            DateTime dt1 = DateTime.Now;

            try
            {
                IRaster        rs     = rstDic[rstNm];
                IRasterDataset rsDset = rsUtil.saveRasterToDatasetM(rs, outNm, outWks, rType, noDataVl, blSize, blSize);
                DateTime       dt2    = DateTime.Now;
                IRasterLayer   rsLyr  = new RasterLayerClass();
                rsLyr.CreateFromDataset(rsDset);
                rsLyr.Name    = outNm;
                rsLyr.Visible = false;
                mp.AddLayer((ILayer)rsLyr);
                TimeSpan ts      = dt2.Subtract(dt1);
                string   prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                rp.stepPGBar(100);
                rp.enableClose();
                this.Close();
            }
        }
 private void setRasterType()
 {
     string wksPath = wks.PathName;
     if (wksPath.EndsWith(".accdb") || wksPath.EndsWith(".mdb") || wksPath.EndsWith(".sde")) rsType = rasterUtil.rasterType.GDB;
     else rsType = rasterUtil.rasterType.IMAGINE;
     string lastRS = "";
     bool checkNA = false;
     foreach(string s in System.IO.Directory.GetFiles(resultsDir,"arrivaltime*.txt"))
     {
         lastRS = System.IO.Path.GetFileNameWithoutExtension(s);
         string[] sArr = lastRS.Split(new char[]{'_'});
         int perNum = System.Convert.ToInt32(sArr[2]);
         if (perNum > numPer) numPer = perNum;
         int firNum = System.Convert.ToInt32(sArr[1]);
         if(firNum>numFir)numFir= firNum;
         int iterNum = System.Convert.ToInt32(sArr[0].Replace("arrivaltime",""));
         if (iterNum == 0)
         {
             checkNA = true;
         }
         if(iterNum>numIter)numIter=iterNum;
         lastRS = s;
     }
     if (checkNA && numIter > 0)
     {
         iterLst.Add(0);
     }
     iterLst.Add(numIter);
     snapRaster = rsUtil.createIdentityRaster(lastRS);
 }