private IRaster rescaleCov() { IRasterBand rsBand = ((IRasterBandCollection)covRs).Item(0); IRasterStatistics rsStats = rsBand.Statistics; double min = rsStats.Minimum; double max = rsStats.Maximum; double range = (max - min); double step = range / CoverLevels; IRemapFilter flt = new RemapFilterClass(); double cnt = 0; double i = 0; for (i = min; i < max; i += step) { double nMax = i + step; if (nMax == max) { nMax = max + 1; } flt.AddClass(i, nMax, cnt); cnt++; } IRaster rs2 = rsUtil.returnRaster(rsUtil.calcRemapFunction(covRs, flt)); return(rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs2, 100000, esriRasterArithmeticOperation.esriRasterMultiply))); }
private IFunctionRasterDataset transform() { IRasterBandCollection rsBc = new RasterClass(); for (int i = 0; i < coef.Length; i++) { double[] c = coef[i]; double intercept = c[0]; double slope = c[1]; IFunctionRasterDataset tRs = rsUtil.getBand(transformRaster, i); IFunctionRasterDataset pRs = rsUtil.calcArithmaticFunction(tRs, slope, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset fRs = rsUtil.calcArithmaticFunction(pRs, intercept, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset bRs = rsUtil.convertToDifFormatFunction(fRs, rsType); rsBc.AppendBand(((IRasterBandCollection)bRs).Item(0)); } OutRaster = rsUtil.compositeBandFunction(rsBc); return(OutRaster); }
private void btnExecute_Click(object sender, EventArgs e) { string inRst1Nm = cmbInRaster1.Text; string inRst2Nm = cmbInRaster2.Text; string opNm = cmbProcess.Text; string outNmRst = txtOutName.Text; if (inRst1Nm == "" || inRst1Nm == null) { MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (inRst2Nm == "" || inRst2Nm == null) { MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (opNm == "" || opNm == null) { MessageBox.Show("You must select a process from the dropdown menu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (outNmRst == "" || outNmRst == null) { MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } object rs1, rs2; if (rstDic.ContainsKey(inRst1Nm)) { rs1 = rstDic[inRst1Nm]; } else if (rsUtil.isNumeric(inRst1Nm)) { rs1 = inRst1Nm; } else { MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (rstDic.ContainsKey(inRst2Nm)) { rs2 = rstDic[inRst2Nm]; } else if (rsUtil.isNumeric(inRst2Nm)) { rs2 = inRst2Nm; } else { MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } esriRasterArithmeticOperation op = oprDic[opNm]; this.Visible = false; esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false); DateTime dt = DateTime.Now; rp.addMessage("Creating Raster. This may take a while..."); rp.stepPGBar(10); rp.TopMost = true; try { IRaster outRs = rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs1, rs2, op)); outraster = outRs; outrastername = outNmRst; if (mp != null && aM) { rp.addMessage("Calculating Statistics..."); rp.Show(); rp.Refresh(); //rsUtil.calcStatsAndHist(((IRaster2)outRs).RasterDataset); IRasterLayer rsLyr = new RasterLayerClass(); rsLyr.CreateFromRaster(outraster); rsLyr.Name = outrastername; rsLyr.Visible = false; mp.AddLayer((ILayer)rsLyr); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { rp.addMessage(ex.ToString()); Console.WriteLine(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 Arithmetic Analysis" + t); rp.enableClose(); this.Close(); } }
private IFunctionRasterDataset calCov() { double N = (SumRws * SumClms * 2); IFunctionRasterDataset mvRst = getShiftedRaster(InRaster); IFunctionRasterDataset pRs = rsUtil.calcArithmaticFunction(InRaster, mvRst, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset pRs2T = rsUtil.calcArithmaticFunction(InRaster, mvRst, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset pRs2 = rsUtil.calcArithmaticFunction(pRs2T, 2, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset mRsT = rsUtil.calcFocalStatisticsFunction(pRs, SumClms, SumRws, rasterUtil.focalType.SUM); IFunctionRasterDataset mRsT2 = rsUtil.calcArithmaticFunction(mRsT, 2, esriRasterArithmeticOperation.esriRasterPower); IFunctionRasterDataset mRs = rsUtil.calcArithmaticFunction(mRsT2, N, esriRasterArithmeticOperation.esriRasterDivide); IFunctionRasterDataset mRs2 = rsUtil.calcFocalStatisticsFunction(pRs2, SumClms, SumRws, rasterUtil.focalType.SUM); IFunctionRasterDataset dif = rsUtil.calcArithmaticFunction(mRs2, mRs, esriRasterArithmeticOperation.esriRasterMinus); return(rsUtil.calcArithmaticFunction(dif, N, esriRasterArithmeticOperation.esriRasterDivide)); }
public string sumSedimentValues() { string outCSV = graphDir + "\\SedimentByArivalTime.csv"; using (System.IO.StreamWriter swr = new System.IO.StreamWriter(outCSV)) { string ln = "Alternative,Fires,Period,Sed10,Sed50,Sed10_A,Sed50_A,ArivalTime,CellCount"; swr.WriteLine(ln); if (iterLst.Count < 2) { Console.WriteLine("copying files over"); copyNaToResults(ref iterLst); } int iterCnt = 0; string itop = ""; foreach (int iter in iterLst) { if (iterCnt == 0) { itop = "No Action"; } else { itop = "Optimum"; } iterCnt++; createPeriodRasters(iter); for (int f = 1; f <= numFir; f++) { for (int i = 1; i <= numPer; i++) { string strln = "Building raster for iteration " + iter.ToString() + " fire " + f.ToString() + " period " + i.ToString(); if (rpForm != null) { rpForm.addMessage(strln); rpForm.stepPGBar(5); rpForm.Refresh(); } else { Console.WriteLine(strln); } //treatment rasters IFunctionRasterDataset perRs = periodRasterLst[i - 1]; IFunctionRasterDataset noActionPeriod = rsUtil.calcEqualFunction(perRs, 0); IFunctionRasterDataset t10 = rsUtil.calcArithmaticFunction(perRs, rst1Fine10, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset f10 = rsUtil.calcArithmaticFunction(noActionPeriod, rsfine10, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset t50 = rsUtil.calcArithmaticFunction(perRs, rst1Fine50, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset f50 = rsUtil.calcArithmaticFunction(noActionPeriod, rsfine50, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset sum10 = rsUtil.calcArithmaticFunction(t10, f10, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset sum50 = rsUtil.calcArithmaticFunction(t50, f50, esriRasterArithmeticOperation.esriRasterPlus); //flamelength rasters string flameRasterPath = resultsDir + "\\nodeflamelength" + iter.ToString() + "_" + f.ToString() + "_" + i.ToString() + ".txt"; IFunctionRasterDataset flmLng = rsUtil.createIdentityRaster(flameRasterPath); IFunctionRasterDataset flmBool = createBooleanFlame(flmLng); //combined raster IFunctionRasterDataset final10 = rsUtil.conditionalRasterFunction(flmBool, rshsf10, sum10); IFunctionRasterDataset final50 = rsUtil.conditionalRasterFunction(flmBool, rshsf50, sum50); //arrival zones string ArivalRasterPath = resultsDir + "\\arrivaltime" + iter.ToString() + "_" + f.ToString() + "_" + i.ToString() + ".txt"; IFunctionRasterDataset ariv = rsUtil.createIdentityRaster(ArivalRasterPath); IFunctionRasterDataset arivZones = createArivaltimeZones(ariv); strln = "Summarizing arrival zones for iteration " + iter.ToString() + " fire " + f.ToString() + " period " + i.ToString(); if (rpForm != null) { rpForm.addMessage(strln); rpForm.stepPGBar(5); rpForm.Refresh(); } else { Console.WriteLine(strln); } ln = getSummaryValue(itop, f, i, final10, final50, arivZones); swr.Write(ln); if (createinter) { strln = "Saving all intermediate rasters..."; if (rpForm != null) { rpForm.addMessage(strln); rpForm.stepPGBar(5); rpForm.Refresh(); } else { Console.WriteLine(strln); } rsUtil.saveRasterToDataset(rsUtil.createRaster(noActionPeriod), "noAct_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(t10), "t10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(f10), "na10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(t50), "t50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(f50), "na50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(sum10), "s10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(sum50), "s50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(flmBool), "flm_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(final10), "fl10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(final50), "fl50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(arivZones), "az" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); } if (createcore) { if (!createinter) { strln = "Saving core rasters..."; if (rpForm != null) { rpForm.addMessage(strln); rpForm.stepPGBar(5); rpForm.Refresh(); } else { Console.WriteLine(strln); } rsUtil.saveRasterToDataset(rsUtil.createRaster(final10), "fl10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(final50), "fl50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); rsUtil.saveRasterToDataset(rsUtil.createRaster(arivZones), "az" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE); } } if (!createcore && !createinter) { try { if (sedRaster != null) { rsUtil.deleteRasterDataset(((IRasterDataset)sedRaster).CompleteName); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } } } } swr.Close(); } outcsvpath = outCSV; //removelocks(); return(outCSV); }
private void buildPathRasters() { getSpatialAnalystLicense(); if (FunctionAccumulatedPathAllocation == null) { buildPathAllocation(); } //calculate costs IFunctionRasterDataset onRdCs = null; IFunctionRasterDataset offRdCs = null; if (OnRoadMachineRateRaster == null) { float dollarPerTonConv = (OnRoadMachineRate / onRoadPayLoad) * 0.001f;// * 1000; onRdCs = rsUtil.calcArithmaticFunction(FunctionAccumulatedPathAllocation, dollarPerTonConv, esriRasterArithmeticOperation.esriRasterMultiply); } else { IFunctionRasterDataset dollarPerTonConv = rsUtil.calcArithmaticFunction(OnRoadMachineRateRaster, onRoadPayLoad * 1000f, esriRasterArithmeticOperation.esriRasterDivide); onRdCs = rsUtil.calcArithmaticFunction(FunctionAccumulatedPathAllocation, dollarPerTonConv, esriRasterArithmeticOperation.esriRasterMultiply); } if (OffRoadMachineRateRaster == null) { float offDollarPerTonConv = (OffRoadMachineRate / OffRoadPayLoad); offRdCs = rsUtil.calcArithmaticFunction(FunctionAccumulatedFromPathDistance, offDollarPerTonConv, esriRasterArithmeticOperation.esriRasterMultiply); } else { IFunctionRasterDataset offDollarPerTonConv = rsUtil.calcArithmaticFunction(OffRoadMachineRateRaster, OffRoadPayLoad, esriRasterArithmeticOperation.esriRasterDivide); offRdCs = rsUtil.calcArithmaticFunction(FunctionAccumulatedFromPathDistance, offDollarPerTonConv, esriRasterArithmeticOperation.esriRasterMultiply); } IFunctionRasterDataset t0 = rsUtil.calcArithmaticFunction(onRdCs, offRdCs, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset t1 = rsUtil.calcArithmaticFunction(t0, 2, esriRasterArithmeticOperation.esriRasterMultiply); IFunctionRasterDataset t2 = null; IFunctionRasterDataset transCost = null; if (OperationsCostRaster == null) { t2 = rsUtil.calcArithmaticFunction(t1, OperationsCost, esriRasterArithmeticOperation.esriRasterPlus); } else { t2 = rsUtil.calcArithmaticFunction(t1, OperationsCostRaster, esriRasterArithmeticOperation.esriRasterPlus); } if (OtherCostRaster == null) { transCost = rsUtil.calcArithmaticFunction(t2, OtherCost, esriRasterArithmeticOperation.esriRasterPlus); } else { transCost = rsUtil.calcArithmaticFunction(t2, OtherCostRaster, esriRasterArithmeticOperation.esriRasterPlus); } outDTR = transCost; }