public void Bind(object pArgument) { if (pArgument is glcmFunctionArguments) { glcmFunctionArguments args = (glcmFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inWindow = args.WindowType; iter = args.GenericIterator; clms = args.Columns; rws = args.Rows; radius = args.Radius; glcmMetrics = args.GLCMMETRICS; horizontal = args.Horizontal; myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: glcmFunctonArguments"); } }
public void Bind(object pArgument) { if (pArgument is FocalFunctionArguments) { FocalFunctionArguments args = (FocalFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inop = args.Operation; inWindow = args.WindowType; lsiter = args.Fastiter; windowN = args.WindowCount; //Console.WriteLine(lsiter.Count()); clms = args.Columns; rws = args.Rows; radius = args.Radius; myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments"); } }
public bool checkCellSize() { bool cS = true; IPnt zPnt = zRs.RasterInfo.CellSize; IPnt vPnt = vRs.RasterInfo.CellSize; double zX = zPnt.X; double zY = zPnt.Y; double vX = vPnt.X; double vY = vPnt.Y; double ns = vX; if (Math.Abs(vX - vY) > 0.0001) { if (vY < vX) { ns = vY; } InValueRaster = rsUtil.reSampleRasterFunction(vRs, ns); if (rd != null) { rd.addMessage("Value dataset cells Width and Height are not the same! Resizing the valueRaster cell width and height to " + ns.ToString() + "!"); } } if (Math.Abs(zX - ns) > 0.0001) { InZoneRaster = rsUtil.reSampleRasterFunction(zRs, ns); if (rd != null) { rd.addMessage("Zone and value dataset cells are not the same size! Resizing the zoneRaster cell width and height to match the value raster (" + vRs.RasterInfo.CellSize.X.ToString() + ":" + zRs.RasterInfo.CellSize.X.ToString() + ")!"); } } return(cS); }
private void populateComboBox() { if (mp != null) { foreach (KeyValuePair <string, IFeatureClass> kvp in ftrDic) { IFeatureClass ftrCls = kvp.Value; string nm = kvp.Key; if (ftrCls.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint || ftrCls.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint) { cmbSampleFeatureClass.Items.Add(nm); } if (ftrCls.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) { cmbRaster.Items.Add(nm); } } foreach (KeyValuePair <string, IFunctionRasterDataset> kvp in rstDic) { IFunctionRasterDataset rsDet = kvp.Value; string nm = kvp.Key; cmbRaster.Items.Add(nm); } } }
public void Bind(object pArgument) { if (pArgument is glcmFunctionArguments) { glcmFunctionArguments args = (glcmFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inWindow = args.WindowType; iter = args.GenericIterator; clms = args.Columns; rws = args.Rows; radius = args.Radius; glcmMetrics = args.GLCMMETRICS; horizontal = args.Horizontal; myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: glcmFunctonArguments"); } }
/// <summary> /// Each BuilderItem contains a Function Raster Dataset which is used to create the thumbnail. /// The thumbnail is created by Nearest Neighbor resampling of the Function Raster Dataset. /// The resampled raster is exported as a byte array and saved Into the IMemoryBlobStreamVariant. /// The blob is then inserted into the Thumbnail field. /// </summary> /// <param name="mybuilderItem">Item containing the Function Dataset to be added to the Mosaic Dataset</param> private void Resampling(IBuilderItem mybuilderItem) { try { IFunctionRasterDataset pFuncRasterDataset = mybuilderItem.Dataset; // Get the FunctionRasterDataset from mybuilderItem IRasterDataset pRasterDataset; pRasterDataset = (IRasterDataset)pFuncRasterDataset; // Cast the FunctionRasterDataset to Raster Dataset IPropertySet thePropSet = pFuncRasterDataset.Properties; // Get the properties of the raster Dataset IRaster praster = pRasterDataset.CreateDefaultRaster(); // Create default raster from the above raster dataset praster.ResampleMethod = rstResamplingTypes.RSP_NearestNeighbor; // The raster is resampled by RSP_NearestNeighbor IRasterProps pRasterProps = (IRasterProps)praster; // Raster properties are used to update the height, width of the raster pRasterProps.Height = 256; pRasterProps.Width = 256; IRasterExporter pConverter = new RasterExporterClass(); // IRasterExporter object is used to convert the raster to byte array. byte[] pBytesArr; pBytesArr = pConverter.ExportToBytes(praster, "TIFF"); // Convert the resampled Raster to a Byte array IMemoryBlobStream memBlobStream = new MemoryBlobStream(); // Create new IMemoryBlobStream IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)memBlobStream; // Assign to IMemoryBlobStreamVariant object anObject = pBytesArr; varBlobStream.ImportFromVariant(anObject); // IMemoryBlobStreamVariant object is assigned the byte array thePropSet.SetProperty("ThumbNail", memBlobStream); // and saved to the property "ThumbNail" } catch (Exception ex) { System.Exception myExc = new System.Exception( "Error: Failed to Re-Sampled the raster.Thumbnails will not be created." + ex.Message, ex); throw myExc; } return; }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.Filter = "Net CDF|*.nc"; od.Multiselect = true; if (od.ShowDialog() == DialogResult.OK) { FrmNecCdfAttributeSelection frmAt = new FrmNecCdfAttributeSelection(od.FileNames[0], rsUtil); frmAt.ShowDialog(); foreach (string fn in od.FileNames) { //System.Windows.Forms.MessageBox.Show(fn); string outName = System.IO.Path.GetFileNameWithoutExtension(fn); if (!rstDic.ContainsKey(outName)) { //string vls = frmAt.variable + ", " + frmAt.xdim + ", " + frmAt.ydim + ", " + frmAt.bands; IFunctionRasterDataset rsA = rsUtil.returnFunctionRasterDatasetNetCDF(fn, frmAt.variable, frmAt.xdim, frmAt.ydim, frmAt.bands); //System.Windows.Forms.MessageBox.Show(((IRasterBandCollection)rsA).Count.ToString() + "; " + vls); rstDic.Add(outName, rsA); //cmbInRaster1.Items.Add(outName); lsbRaster.Items.Add(outName); } else { IFunctionRasterDataset rsA = rsUtil.returnFunctionRasterDatasetNetCDF(fn, frmAt.variable, frmAt.xdim, frmAt.ydim, frmAt.bands); rstDic[outName] = rsA; //System.Windows.Forms.MessageBox.Show(((IRasterBandCollection)rsA).Count.ToString()); } } frmAt.Close(); frmAt.Dispose(); } }
public normalization(IFunctionRasterDataset ReferenceRaster, IFunctionRasterDataset TransformRaster, int PercentChange = 20, rasterUtil rasterUtility = null) { referenceRaster = ReferenceRaster; IRasterBandCollection rsBc = (IRasterBandCollection)referenceRaster; rsType = referenceRaster.RasterInfo.PixelType; cellCount = new int[rsBc.Count]; minArray = new double[rsBc.Count]; maxArray = new double[rsBc.Count]; sumX2Array = new double[rsBc.Count]; sumXArray = new double[rsBc.Count]; sumXYArray = new double[rsBc.Count]; sumYArray = new double[rsBc.Count]; sumY2Array = new double[rsBc.Count]; coef = new double[rsBc.Count][]; blockCellCount = new int[rsBc.Count]; difDic = new Dictionary <int, int> [rsBc.Count]; for (int i = 0; i < rsBc.Count; i++) { difDic[i] = new Dictionary <int, int>(); } transformRaster = TransformRaster; pChange = System.Convert.ToDouble(PercentChange) / 200d; rsUtil = rasterUtility; }
private void populateComboBox() { if (mp != null) { IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer); ILayer lyr = rstLyrs.Next(); while (lyr != null) { string lyrNm = lyr.Name; IRasterLayer rstLyr = (IRasterLayer)lyr; IFunctionRasterDataset rst = rsUtil.createIdentityRaster(((IRaster2)rstLyr.Raster).RasterDataset); if (!rstDic.ContainsKey(lyrNm)) { rstDic.Add(lyrNm, rst); cmbInRaster1.Items.Add(lyrNm); } lyr = rstLyrs.Next(); } } foreach (string s in Enum.GetNames(typeof(rasterUtil.localType))) { cmbFunction.Items.Add(s); } cmbFunction.SelectedItem = rasterUtil.localType.MEAN.ToString(); }
public void Bind(object pArgument) { if (pArgument is FocalFunctionArguments) { FocalFunctionArguments args = (FocalFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inop = args.Operation; inWindow = args.WindowType; lsiter = args.Fastiter; windowN = args.WindowCount; //Console.WriteLine(lsiter.Count()); clms = args.Columns; rws = args.Rows; radius = args.Radius; myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments"); } }
public void Bind(object pArgument) { if (pArgument is combineFunctionArguments) { combineFunctionArguments args = (combineFunctionArguments)pArgument; inrs = args.InRasterDataset; outRs = args.OutRaster; myFunctionHelper.Bind(outRs); //myFunctionHelperCoef.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; object tnd = myRasterInfo.NoData; if(tnd==null) { } else { noDataVl = ((System.Array)myRasterInfo.NoData).GetValue(0); } } else { throw new System.Exception("Incorrect arguments object. Expected: combineFunctonArguments"); } }
private IFunctionRasterDataset calcCorr() { //Cov 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 cov = rsUtil.calcArithmaticFunction(mRs2, mRs, esriRasterArithmeticOperation.esriRasterMinus); //IRaster cov2 = RasterUtility.calcEqualFunction(cov1, 0); //IRaster cov = RasterUtility.calcArithmaticFunction(cov2, cov1, esriRasterArithmeticOperation.esriRasterPlus); //Var IFunctionRasterDataset x2 = rsUtil.calcArithmaticFunction(InRaster, 2, esriRasterArithmeticOperation.esriRasterPower); IFunctionRasterDataset mvRst2 = getShiftedRaster(x2); pRs2 = rsUtil.calcArithmaticFunction(x2, mvRst2, esriRasterArithmeticOperation.esriRasterPlus); mRs2 = rsUtil.calcFocalStatisticsFunction(pRs2, SumClms, SumRws, rasterUtil.focalType.SUM); IFunctionRasterDataset var = rsUtil.calcArithmaticFunction(mRs2, mRs, esriRasterArithmeticOperation.esriRasterMinus); //IRaster var2 = RasterUtility.calcEqualFunction(var1, 0); //IRaster var = RasterUtility.calcArithmaticFunction(var2, var1, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset cor = rsUtil.calcArithmaticFunction(cov, var, esriRasterArithmeticOperation.esriRasterDivide); return(RasterUtility.setnullToValueFunction(cor, 1)); }
public void Bind(object pArgument) { if (pArgument is combineFunctionArguments) { combineFunctionArguments args = (combineFunctionArguments)pArgument; inrs = args.InRasterDataset; outRs = args.OutRaster; myFunctionHelper.Bind(outRs); //myFunctionHelperCoef.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; object tnd = myRasterInfo.NoData; if (tnd == null) { } else { noDataVl = ((System.Array)myRasterInfo.NoData).GetValue(0); } } else { throw new System.Exception("Incorrect arguments object. Expected: combineFunctonArguments"); } }
//public IFeatureClass createPolygons3() //{ // createFeatureClass(); //} public IFeatureClass createPolygons2() { createFeatureClass(); IRasterProps rsProp = (IRasterProps)inputRaster; int bndCnt = ((IRasterBandCollection)inputRaster).Count; IPnt rsPnt = rsProp.MeanCellSize(); double cellArea = rsPnt.X * rsPnt.Y; double tCells = minArea / cellArea; IFunctionRasterDataset sDset = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells); FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function; IRaster2 rs2 = (IRaster2)rsUtil.createRaster(sDset); IRasterCursor rsCur = rs2.CreateCursorEx(null); IRasterDomainExtractor dExt = new RasterDomainExtractorClass(); do { IPixelBlock pb = rsCur.PixelBlock; IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset); IRaster rs = rsUtil.createRaster(pbDset); int numClusters = rFunc.NumClusters; for (int c = 0; c < numClusters; c++) { IFunctionRasterDataset fd = rsUtil.calcEqualFunction(pbDset, c); IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0); IPolygon polys = dExt.ExtractDomain(rsUtil.createRaster(fd2), true); } } while (rsCur.Next() == true); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); return(outftr); }
public TransRouting(IWorkspace outworkspace, IFunctionRasterDataset DEM, SpeedUnits spUnits = SpeedUnits.KPH) { Dem = DEM; sp = DEM.RasterInfo.SpatialReference; OutWorkspace = outworkspace; Units = spUnits; getConversionFactor(); }
private IFunctionRasterDataset calcContrast() { IFunctionRasterDataset mvRst = getShiftedRaster(InRaster); IFunctionRasterDataset difRs = rsUtil.calcArithmaticFunction(InRaster, mvRst, esriRasterArithmeticOperation.esriRasterMinus); IFunctionRasterDataset dif2 = rsUtil.calcArithmaticFunction(difRs, 2, esriRasterArithmeticOperation.esriRasterPower); return(rsUtil.calcFocalStatisticsFunction(dif2, SumClms, SumRws, rasterUtil.focalType.MEAN)); }
public void addRasterToComboBox(string rstName, IFunctionRasterDataset rst) { if (!cmbInRaster1.Items.Contains(rstName)) { cmbInRaster1.Items.Add(rstName); rstDic[rstName] = rst; } }
private IFunctionRasterDataset calcAgFunction(IFunctionRasterDataset rr, string outName, int numCells) { IFunctionRasterDataset sumRs = rsUtil.calcAggregationFunction(rr, numCells, rasterUtil.focalType.SUM); IWorkspace sWks = geoUtil.OpenRasterWorkspace(sedDir); IRasterDataset rsD = rsUtil.saveRasterToDataset(rsUtil.createRaster(sumRs), outName, sWks, rasterUtil.rasterType.IMAGINE); return(rsUtil.createIdentityRaster(rsD)); }
private IFunctionRasterDataset calcMean() { IFunctionRasterDataset mvRst = getShiftedRaster(InRaster); IFunctionRasterDataset pRs = rsUtil.calcArithmaticFunction(InRaster, mvRst, esriRasterArithmeticOperation.esriRasterPlus); IFunctionRasterDataset mRs = rsUtil.calcFocalStatisticsFunction(pRs, SumClms, SumRws, rasterUtil.focalType.MEAN); return(rsUtil.calcArithmaticFunction(mRs, 2, esriRasterArithmeticOperation.esriRasterDivide)); }
public void convertFeatureToRaster(IFeatureClass InFeatureClass, string fldName) { ftrCls = InFeatureClass; ftrField = fldName; IDataset dSet = (IDataset)InFeatureClass; string outRsNm = dSet.BrowseName; wks = dSet.Workspace; if (vRs != null) { if (!checkProjectionsFtr()) { if (rd != null) { rd.addMessage("Re-projecting feature class to match value raster's projection"); } InFeatureClass = reprojectInFeatureClass(InFeatureClass, vRs.RasterInfo.SpatialReference); } } IWorkspace wksTemp = geoUtil.OpenRasterWorkspace(tempWksStr); IFunctionRasterDataset rs = rsUtil.createIdentityRaster(rsUtil.convertFeatureClassToRaster(InFeatureClass, rasterUtil.rasterType.IMAGINE, wksTemp, outRsNm, vRs.RasterInfo.CellSize.X, (IRasterDataset)vRs)); rs = rsUtil.createIdentityRaster(rs, rstPixelType.PT_FLOAT); int fieldIndex = InFeatureClass.FindField(fldName); if (fieldIndex == -1) { fieldIndex = InFeatureClass.FindField(fldName + "_1"); } if (fldName.ToLower() == InFeatureClass.OIDFieldName.ToLower() || fieldIndex == -1) { zRs = rs; } else { IRemapFilter rFilt = new RemapFilterClass(); IFeatureCursor ftrCur = InFeatureClass.Search(null, false); IFeature ftr = ftrCur.NextFeature(); while (ftr != null) { double id = ftr.OID; double nVl = System.Convert.ToDouble(ftr.get_Value(fieldIndex)); if (Double.IsNaN(nVl) || Double.IsInfinity(nVl)) { ftr = ftrCur.NextFeature(); } else { //Console.WriteLine("adding oid = " + id.ToString() + " and value = " + nVl.ToString()); rFilt.AddClass(id, id + 1, nVl); ftr = ftrCur.NextFeature(); } } zRs = rsUtil.calcRemapFunction(rs, rFilt); } }
private void setInRs() { IEnvelope env = new EnvelopeClass(); double mx, my; IRaster2 rs = (IRaster2)rsUtil.createRaster(valueraster); IPnt cellSize = valueraster.RasterInfo.CellSize; rs.PixelToMap((int)topleft.X, (int)topleft.Y, out mx, out my); env.PutCoords(mx, my - (cellSize.Y * vpixelBlock.Height), mx + (cellSize.X * vpixelBlock.Width), my); inrs = rsUtil.constantRasterFunction((IRaster)rs, env, 0, cellSize); }
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; }
public void btnExecute_Click(object sender, EventArgs e) { string tblNm = txtOutNm.Text; if (tblNm == null || tblNm == "") { MessageBox.Show("You must specify a output name", "No Output", 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; } IRasterBandCollection rsBc = new RasterClass(); for (int i = 0; i < lsbRaster.Items.Count; i++) { rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]); } this.Visible = false; esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false); DateTime dt = DateTime.Now; rp.addMessage("Building Raster Attribute Table. This may take a while..."); rp.stepPGBar(10); rp.TopMost = true; rp.Show(); try { string outDbStr = geoUtil.getDatabasePath(tblNm); string outName = System.IO.Path.GetFileNameWithoutExtension(tblNm); IWorkspace wks = geoUtil.OpenWorkSpace(outDbStr); IFunctionRasterDataset fDset = rsUtil.compositeBandFunction(rsBc); outtbl = rsUtil.calcCombinRasterFunctionTable(fDset, wks, outName); 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 creating attribute table"); rp.enableClose(); this.Close(); } }
private void createDictionaryArray() { IEnvelope env1 = referenceRaster.RasterInfo.Extent; IEnvelope env2 = transformRaster.RasterInfo.Extent; env1.Intersect(env2); clipGeo = (IGeometry)env1; IFunctionRasterDataset minRs = rsUtil.calcArithmaticFunction(referenceRaster, transformRaster, esriRasterArithmeticOperation.esriRasterMinus); clipRs = rsUtil.clipRasterFunction(minRs, clipGeo, esriRasterClippingType.esriRasterClippingOutside); IPnt pntSize = new PntClass(); pntSize.SetCoords(512, 512); IRasterCursor rsCur = ((IRaster2)rsUtil.createRaster(clipRs)).CreateCursorEx(pntSize); int pCnt = rsCur.PixelBlock.Planes; do { IPixelBlock pbMinBlock = rsCur.PixelBlock; for (int r = 0; r < pbMinBlock.Height; r++) { for (int c = 0; c < pbMinBlock.Width; c++) { for (int p = 0; p < pCnt; p++) { object vlObj = pbMinBlock.GetVal(p, c, r); if (vlObj == null) { continue; } else { int vl = System.Convert.ToInt32(vlObj); Dictionary <int, int> cDic = difDic[p]; int cnt = 0; if (!cDic.TryGetValue(vl, out cnt)) { cDic.Add(vl, 1); } else { cDic[vl] = cnt + 1; } cellCount[p] += 1; } } } } } while (rsCur.Next() == true); }
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 void Bind(object pArgument) { if (pArgument is MathFunctionArguments) { MathFunctionArguments args = (MathFunctionArguments)pArgument; inrs = args.InRaster; myFunctionHelper.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: MathFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is MathFunctionArguments) { MathFunctionArguments args = (MathFunctionArguments)pArgument; inrs = args.InRaster; myFunctionHelper.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: MathFunctionArguments"); } }
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); }
private static Dictionary <string, double> getStrataProportion(IFunctionRasterDataset strataRaster, rasterUtil rsUtil) { IRaster2 rs2 = (IRaster2)rsUtil.createRaster(strataRaster); Dictionary <string, double> outDic = new Dictionary <string, double>(); IRasterCursor rsCur = rs2.CreateCursorEx(null); //Console.WriteLine(((IRasterProps)rs2).Height.ToString() + ((IRasterProps)rs2).Height.ToString()); int n = 0; do { IPixelBlock pb = rsCur.PixelBlock; //Console.WriteLine("PixelBLock w_h = " + pb.Width.ToString() + "_" + pb.Height.ToString()); for (int r = 0; r < pb.Height; r++) { for (int c = 0; c < pb.Width; c++) { object vlObj = pb.GetVal(0, c, r); if (vlObj != null) { string vl = vlObj.ToString(); double vlCnt; if (outDic.TryGetValue(vl, out vlCnt)) { outDic[vl] = vlCnt + 1; } else { outDic.Add(vl, 1); } n += 1; } else { //Console.WriteLine("VL Null"); } } } } while (rsCur.Next() == true); //Console.WriteLine("OutDic Count = " + outDic.Count.ToString()); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); foreach (string s in outDic.Keys.ToArray()) { double vl = outDic[s]; outDic[s] = vl / n; } return(outDic); }
public void Bind(object pArgument) { if (pArgument is convertPixelTypeFunctionArguments) { convertPixelTypeFunctionArguments arg = (convertPixelTypeFunctionArguments)pArgument; inrs = arg.InRaster; convPType = arg.RasterPixelType; myFunctionHelper.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: LocalFunctionArguments"); } }
public IFunctionRasterDataset getShiftedRaster(IFunctionRasterDataset rasterToShift) { IFunctionRasterDataset mvRst = null; double x = 0; double y = 0; if (Horizontal) { x = -1 * rasterToShift.RasterInfo.CellSize.X; } else { y = rasterToShift.RasterInfo.CellSize.Y; } mvRst = rsUtil.shiftRasterFunction(rasterToShift, x, y); return(mvRst); }
private IFunctionRasterDataset createArivaltimeZones(IFunctionRasterDataset arrivalTime) { IRemapFilter arrivalRemap = new RemapFilterClass(); IRasterStatistics rsStats = ((IRasterBandCollection)arrivalTime).Item(0).Statistics; if (rsStats == null) { rsUtil.calcStatsAndHist(arrivalTime); rsStats = ((IRasterBandCollection)arrivalTime).Item(0).Statistics; } else if (!rsStats.IsValid) { rsStats.SkipFactorX = 1; rsStats.SkipFactorY = 1; rsStats.Recalculate(); } else { } double max = rsStats.Maximum; double min = rsStats.Minimum; double skip = 1; switch (arrCls) { case ArrivalClasses.Hours: skip = 60; break; case ArrivalClasses.Days: skip = 1440; break; default: break; } for (double i = 0; i <= max; i += skip) { double nVl = (i + skip) / skip; arrivalRemap.AddClass(min, i + skip, nVl); } IFunctionRasterDataset reRs = rsUtil.calcRemapFunction(arrivalTime, arrivalRemap); return(reRs);// reSampleRasterGrid(reRs); }
public void Bind(object pArgument) { if (pArgument is LocalRescaleFunctionArguments) { LocalRescaleFunctionArguments arg = (LocalRescaleFunctionArguments)pArgument; inrsBands = arg.InRaster; bndCnt = inrsBands.RasterInfo.BandCount; bndCntf = System.Convert.ToSingle(bndCnt-1); myFunctionHelper.Bind(inrsBands); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: LocalFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is LocalFunctionArguments) { LocalFunctionArguments arg = (LocalFunctionArguments)pArgument; inrsBands = arg.InRaster; inrs = arg.outRaster; myFunctionHelper.Bind(inrs); //myFunctionHelperCoef.Bind(inrsBands); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: LocalFunctionArguments"); } }
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); }
public void Bind(object pArgument) { if (pArgument is conditionalFunctionArguments) { conditionalFunctionArguments args = (conditionalFunctionArguments)pArgument; coefRs = args.CoefRaster; outRs = args.OutRaster; myFunctionHelper.Bind(outRs); myFunctionHelperCoef.Bind(coefRs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: Conditional arguments"); } }
public void Bind(object pArgument) { if (pArgument is PixelBlockToRasterFunctionArguments) { PixelBlockToRasterFunctionArguments args = (PixelBlockToRasterFunctionArguments)pArgument; inrs = args.InRaster; vPb = (IPixelBlock3)args.ValuePixelBlock; tlLoc = args.TopLeft; myFunctionHelper.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: PixelBlockToRasterArguments"); } }
public void Bind(object pArgument) { if (pArgument is conditionalFunctionArguments) { conditionalFunctionArguments args = (conditionalFunctionArguments)pArgument; coefRs = args.CoefRaster; outRs = args.OutRaster; myFunctionHelper.Bind(outRs); myFunctionHelperCoef.Bind(coefRs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: Conditional arguments"); } }
public void Bind(object pArgument) { if (pArgument is pcaArguments) { pcaArguments arg = (pcaArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; outrs = arg.OutRaster; pca = arg.PCA; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: pcaFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is focalBandFunctionArguments) { focalBandFunctionArguments arg = (focalBandFunctionArguments)pArgument; inrsBands = arg.InRaster; myFunctionHelper.Bind(inrsBands); bandsBefore = arg.BandsBefore; bandsAfter = arg.BandsAfter; tBands = 1 + bandsBefore + bandsAfter; myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: focalBandArguments"); } }
public void Bind(object pArgument) { if (pArgument is polytomousLogisticFunctionArguments) { polytomousLogisticFunctionArguments arg = (polytomousLogisticFunctionArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; slopes = arg.Slopes; outrs = arg.OutRaster; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: regressionFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is meanShiftFunctionArguments) { meanShiftFunctionArguments args = (meanShiftFunctionArguments)pArgument; inrs = args.InRaster; radius = args.Radius; valrs = args.ValueRaster; myFunctionHelper.Bind(inrs); myFunctionHelper2.Bind(valrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: meanShiftArguments"); } }
public void Bind(object pArgument) { if (pArgument is tobitFunctionArguments) { tobitFunctionArguments arg = (tobitFunctionArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; slopes = arg.Slopes; outrs = arg.OutRaster; censored = arg.CensoredValue; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: tobitnFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is aggregationFunctionArguments) { aggregationFunctionArguments args = (aggregationFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; cells = args.Cells; myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); //System.Windows.Forms.MessageBox.Show(orig.RasterInfo.CellSize.X.ToString()+"\n" + inrs.RasterInfo.CellSize.X.ToString()); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: aggregationFunctonArguments"); } }
public void Bind(object pArgument) { if (pArgument is clusterFunctionArguments) { clusterFunctionArguments arg = (clusterFunctionArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; outrs = arg.OutRaster; //Console.WriteLine("Number of Bands in outrs = " + ((IRasterBandCollection)outrs).Count.ToString()); cluster = (Statistics.dataPrepClusterBinary)arg.ClusterModel; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: plrFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is softMaxFunctionArguments) { softMaxFunctionArguments arg = (softMaxFunctionArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; outrs = arg.OutRaster; xVls = new double[((IRasterBandCollection)inrsBandsCoef).Count]; //Console.WriteLine("Number of Bands in outrs = " + ((IRasterBandCollection)outrs).Count.ToString()); lm = arg.LogitModel; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: plrFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is focalSampleArguments) { focalSampleArguments args = (focalSampleArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inop = args.Operation; offset = args.OffSets; getPlusWidthHeight(); myFunctionHelper.Bind(inrs); myFunctionHelperOrig.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: focalSampleFunctonArguments"); } }
public void Bind(object pArgument) { if (pArgument is pairedttestFunctionArguments) { pairedttestFunctionArguments arg = (pairedttestFunctionArguments)pArgument; inrsBandsCoef = arg.InRasterCoefficients; outrs = arg.OutRaster; //Console.WriteLine("Number of Bands in outrs = " + ((IRasterBandCollection)outrs).Count.ToString()); tDic = arg.TTestDictionary; IRasterProps rsProp = (IRasterProps)outrs; myFunctionHelper.Bind(outrs); myFunctionHelperCoef.Bind(inrsBandsCoef); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: plrFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is mergeFunctionArguments) { mergeFunctionArguments arg = (mergeFunctionArguments)pArgument; inrs = arg.InRaster; outrs = arg.OutRaster; //Console.WriteLine("Number of Bands in outrs = " + ((IRasterBandCollection)outrs).Count.ToString()); ftrCls = arg.Boundary; //ftrCls = arg.Boundary.Catalog; catIndex = ftrCls.FindField("catIndex"); IRasterProps rsProp = (IRasterProps)outrs; myFunctionHelper.Bind(outrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: mergeFunctionArguments"); } }
public void Bind(object pArgument) { if (pArgument is regionGroupFunctionArguments) { regionGroupFunctionArguments arg = (regionGroupFunctionArguments)pArgument; inrs = arg.InRaster; outrs = arg.OutRaster; //Console.WriteLine("Number of Bands in outrs = " + ((IRasterBandCollection)outrs).Count.ToString()); rsProp = (IRasterProps)outrs; width = rsProp.Width; height = rsProp.Height; myFunctionHelper.Bind(outrs); myFunctionHelperInput.Bind(inrs); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: randomForestArguments"); } }
public normalization(IFunctionRasterDataset ReferenceRaster, IFunctionRasterDataset TransformRaster, int PercentChange = 20, rasterUtil rasterUtility = null) { referenceRaster = ReferenceRaster; IRasterBandCollection rsBc = (IRasterBandCollection)referenceRaster; rsType = referenceRaster.RasterInfo.PixelType; cellCount = new int[rsBc.Count]; minArray = new double[rsBc.Count]; maxArray = new double[rsBc.Count]; sumX2Array = new double[rsBc.Count]; sumXArray = new double[rsBc.Count]; sumXYArray = new double[rsBc.Count]; sumYArray = new double[rsBc.Count]; sumY2Array = new double[rsBc.Count]; coef = new double[rsBc.Count][]; blockCellCount = new int[rsBc.Count]; difDic = new Dictionary<double, int>[rsBc.Count]; for (int i = 0; i < rsBc.Count; i++) { difDic[i] = new Dictionary<double, int>(); } transformRaster = TransformRaster; pChange = System.Convert.ToDouble(PercentChange) / 200d; rsUtil = rasterUtility; }
public void Bind(object pArgument) { if (pArgument is LandscapeFunctionArguments) { LandscapeFunctionArguments args = (LandscapeFunctionArguments)pArgument; inrs = args.InRaster; orig = args.OriginalRaster; inop = args.Operation; landType = args.LandscapeType; inWindow = args.WindowType; clms = args.Columns; rws = args.Rows; radius = args.Radius; myFunctionHelper.Bind(inrs); myFunctionHelperCoef.Bind(orig); myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; myValidFlag = true; } else { throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments"); } }
private static Dictionary<string, double> getStrataProportion(IFunctionRasterDataset strataRaster,rasterUtil rsUtil) { IRaster2 rs2 = (IRaster2)rsUtil.createRaster(strataRaster); Dictionary<string, double> outDic = new Dictionary<string, double>(); IRasterCursor rsCur = rs2.CreateCursorEx(null); //Console.WriteLine(((IRasterProps)rs2).Height.ToString() + ((IRasterProps)rs2).Height.ToString()); int n = 0; do { IPixelBlock pb = rsCur.PixelBlock; //Console.WriteLine("PixelBLock w_h = " + pb.Width.ToString() + "_" + pb.Height.ToString()); for (int r = 0; r < pb.Height; r++) { for (int c = 0; c < pb.Width; c++) { object vlObj = pb.GetVal(0, c, r); if (vlObj != null) { string vl = vlObj.ToString(); double vlCnt; if (outDic.TryGetValue(vl, out vlCnt)) { outDic[vl] = vlCnt + 1; } else { outDic.Add(vl, 1); } n += 1; } else { //Console.WriteLine("VL Null"); } } } } while (rsCur.Next() == true); //Console.WriteLine("OutDic Count = " + outDic.Count.ToString()); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); foreach (string s in outDic.Keys.ToArray()) { double vl = outDic[s]; outDic[s] = vl / n; } return outDic; }
private static Dictionary<string, double[][]> getDictionaryValues(ESRI.ArcGIS.Geodatabase.IFeatureClass pointFtr, ESRI.ArcGIS.Geodatabase.IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, geoDatabaseUtility geoUtil, rasterUtil rsUtil) { IRaster2 rs2 = (IRaster2)rsUtil.createRaster(strataRaster); int[] ptfldIndex = new int[fldsToSummarize.Length]; for (int i = 0; i < ptfldIndex.Length; i++) { ptfldIndex[i] = pointFtr.FindField(fldsToSummarize[i].Name); } Dictionary<string, double[][]> outDic = new Dictionary<string, double[][]>(); IFeatureCursor sCur = pointFtr.Search(null, true); IFeature sFtr = sCur.NextFeature(); while (sFtr != null) { IGeometry geo = sFtr.Shape; IPoint pnt = (IPoint)geo; int clm, rw; rs2.MapToPixel(pnt.X, pnt.Y,out clm, out rw); object strataVlObj = rs2.GetPixelValue(0, clm, rw); if(strataVlObj!=null) { string strataVl = strataVlObj.ToString(); double[][] vlArr; if (outDic.TryGetValue(strataVl, out vlArr)) { for (int i = 0; i < ptfldIndex.Length; i++) { object vlObj = sFtr.get_Value(ptfldIndex[i]); if (vlObj != null) { double vl = System.Convert.ToDouble(vlObj); vlArr[i][0] += vl; vlArr[i][1] += (vl * vl); vlArr[i][2] += 1; } } } else { vlArr = new double[fldsToSummarize.Length][]; for (int i = 0; i < ptfldIndex.Length; i++) { double[] vlSumArr = new double[3]; object vlObj =sFtr.get_Value(ptfldIndex[i]); if (vlObj != null) { double vl = System.Convert.ToDouble(vlObj); vlSumArr[0] = vl; vlSumArr[1] = (vl * vl); vlSumArr[2] = 1; } vlArr[i] = vlSumArr; } outDic[strataVl] = vlArr; } } sFtr = sCur.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur); return outDic; }
public static void summarizeBiomassPolygon(IFeatureClass pointFtr, IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, IFeatureClass standsFtr, geoDatabaseUtility geoUtil = null, rasterUtil rsUtil = null) { if (geoUtil == null) geoUtil = new geoDatabaseUtility(); if(rsUtil == null) rsUtil = new rasterUtil(); int cnt = 0; //need to work on calculating N Dictionary<string,double[][]> vlDic = getDictionaryValues(pointFtr, fldsToSummarize, strataRaster, geoUtil, rsUtil); //Strata: SummaryFields [{sum,sum2,cnt},...] int[] meanFldIndex = new int[fldsToSummarize.Length]; int[] varFldIndex = new int[fldsToSummarize.Length]; int[] cntFldIndex = new int[fldsToSummarize.Length]; //string cntName = geoUtil.createField(standsFtr, "n", esriFieldType.esriFieldTypeInteger, false); //int cntIndex = standsFtr.FindField(cntName); foreach (IField fld in fldsToSummarize) { string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false); varFldIndex[cnt] = standsFtr.FindField(sName); string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false); meanFldIndex[cnt] = standsFtr.FindField(mName); string cntName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false); cntFldIndex[cnt] = standsFtr.FindField(cntName); cnt++; } IFeatureCursor uCur = standsFtr.Update(null, true); IFeature uFtr = uCur.NextFeature(); while (uFtr != null) { ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape; IFunctionRasterDataset cRs = rsUtil.clipRasterFunction(strataRaster, geo, esriRasterClippingType.esriRasterClippingOutside); //Console.WriteLine("Clipping raster"); Dictionary<string, double> rsStrataPropDic = getStrataProportion(cRs,rsUtil); //Strata: proportion of area //int tn = 0; //double[] tn = new double[meanFldIndex.Length]; double[][] updateValuesArr = new double[meanFldIndex.Length][]; for (int i = 0; i < meanFldIndex.Length; i++) { updateValuesArr[i] = new double[3]; } foreach (KeyValuePair<string, double> kvp in rsStrataPropDic) { string stratum = kvp.Key; double proportion = kvp.Value; //Console.WriteLine(stratum + " = " + proportion.ToString()); double[][] vlDicArr; if (vlDic.TryGetValue(stratum, out vlDicArr)) { //double n = vlDicArr[0][2]; //tn += System.Convert.ToInt32(n); for (int i = 0; i < meanFldIndex.Length; i++) { double[] dArr = vlDicArr[i]; double n = dArr[2]; //tn[i] += n; double s=dArr[0]; double s2=dArr[1]; updateValuesArr[i][0] += (s/n) * proportion;//mean updateValuesArr[i][1] += (s2-Math.Pow(s,2)/n)/(n-1) * proportion;//variance updateValuesArr[i][2] += n; } } } //uFtr.set_Value(cntIndex, tn); for (int i = 0; i < meanFldIndex.Length; i++) { uFtr.set_Value(meanFldIndex[i], updateValuesArr[i][0]); uFtr.set_Value(varFldIndex[i], updateValuesArr[i][1]); uFtr.set_Value(cntFldIndex[i], updateValuesArr[i][2]); } uCur.UpdateFeature(uFtr); uFtr = uCur.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur); }
public void GetFinalRaster(out string nm, out IFunctionRasterDataset rs, out string desc) { nm = ""; rs = null; desc = ""; //System.Windows.Forms.MessageBox.Show("LstName = " + lstName+ " and has dictionary value = " + rstDic.ContainsKey(lstName).ToString()); if (rstDic.ContainsKey(lstName)) { nm = lstName; rs = rstDic[lstName]; desc = lnLst[lnLst.Count - 1]; } }
private void btnExecute_Click(object sender, EventArgs e) { string rstNm = txtOutNm.Text; string funNm = cmbFunction.Text; int before = System.Convert.ToInt32(nudBefore.Value); int after = System.Convert.ToInt32(nudAfter.Value); if (rstNm == null || rstNm == "") { MessageBox.Show("You must specify a output name","No Output",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; } if ( funNm==null||funNm=="") { MessageBox.Show("You must select at least on function", "No Function Selected", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } IRasterBandCollection rsBc = new RasterClass(); for (int i = 0; i < lsbRaster.Items.Count; i++) { rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]); } IFunctionRasterDataset fdset = rsUtil.compositeBandFunction(rsBc); rasterUtil.localType op = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType),funNm); this.Visible = false; esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false); DateTime dt = DateTime.Now; rp.addMessage("Calculating raster values. This may take a while..."); rp.stepPGBar(10); rp.TopMost = true; rp.Show(); try { outraster = rsUtil.focalBandfunction(fdset,op,before,after); //rp.addMessage("Number of bands = " + ((IRasterBandCollection)outraster).Count); if (mp != null&&addToMap) { rp.addMessage("Calculating Statistics..."); rp.Refresh(); IRasterLayer rstLyr = new RasterLayerClass(); //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset); rstLyr.CreateFromDataset((IRasterDataset)outraster); rstLyr.Name = rstNm; rstLyr.Visible = false; mp.AddLayer(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 Creating Rasters" + t); rp.enableClose(); this.Close(); } }
public void addRasterToComboBox(string rstName, IFunctionRasterDataset rst) { if (!cmbInRaster1.Items.Contains(rstName)) { cmbInRaster1.Items.Add(rstName); rstDic[rstName]= rst; } }
public void convertFeatureToRaster(IFeatureClass InFeatureClass, string fldName) { ftrCls = InFeatureClass; ftrField = fldName; IDataset dSet = (IDataset)InFeatureClass; string outRsNm = dSet.BrowseName; wks = dSet.Workspace; if (vRs != null) { if (!checkProjectionsFtr()) { if (rd != null) rd.addMessage("Re-projecting feature class to match value raster's projection"); InFeatureClass = reprojectInFeatureClass(InFeatureClass, vRs.RasterInfo.SpatialReference); } } IWorkspace wksTemp = geoUtil.OpenRasterWorkspace(tempWksStr); IFunctionRasterDataset rs = rsUtil.createIdentityRaster(rsUtil.convertFeatureClassToRaster(InFeatureClass, rasterUtil.rasterType.IMAGINE, wksTemp, outRsNm, vRs.RasterInfo.CellSize.X, (IRasterDataset)vRs)); rs = rsUtil.createIdentityRaster(rs, rstPixelType.PT_FLOAT); int fieldIndex = InFeatureClass.FindField(fldName); if(fieldIndex == -1) { fieldIndex = InFeatureClass.FindField(fldName + "_1"); } if (fldName.ToLower() == InFeatureClass.OIDFieldName.ToLower()||fieldIndex == -1) { zRs = rs; } else { IRemapFilter rFilt = new RemapFilterClass(); IFeatureCursor ftrCur = InFeatureClass.Search(null, false); IFeature ftr = ftrCur.NextFeature(); while (ftr != null) { double id = ftr.OID; double nVl = System.Convert.ToDouble(ftr.get_Value(fieldIndex)); if (Double.IsNaN(nVl) || Double.IsInfinity(nVl)) { ftr = ftrCur.NextFeature(); } else { //Console.WriteLine("adding oid = " + id.ToString() + " and value = " + nVl.ToString()); rFilt.AddClass(id, id + 1, nVl); ftr = ftrCur.NextFeature(); } } zRs = rsUtil.calcRemapFunction(rs, rFilt); } }
public IFunctionRasterDataset getShiftedRaster(IFunctionRasterDataset rasterToShift) { IFunctionRasterDataset mvRst = null; double x = 0; double y = 0; if (Horizontal) { x = -1 * rasterToShift.RasterInfo.CellSize.X; } else { y = rasterToShift.RasterInfo.CellSize.Y; } mvRst = rsUtil.shiftRasterFunction(rasterToShift, x, y); return mvRst; }