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 RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp,double minValue) //{ // IRasterBand band = GetBand(rastlayer); // if (band.Histogram == null) // { // band.ComputeStatsAndHist(); // } // IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass(); // IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer; // rasRender.Raster = rastlayer.Raster; // rasRender.Update(); // int numClasses = count; // IRasterHistogram pRasterHistogram = band.Histogram; // double[] dblValues = pRasterHistogram.Counts as double[]; // int intValueCount = dblValues.GetUpperBound(0) + 1; // double[] vValues = new double[intValueCount]; // IRasterStatistics pRasterStatistic = band.Statistics; // //double dMaxValue = pRasterStatistic.Maximum; // double dMaxValue = minValue; // double dMinValue = pRasterStatistic.Minimum; // double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount); // for (int i = 0; i < intValueCount; i++) // { // vValues[i] = i * BinInterval + pRasterStatistic.Minimum; // } // long[] longvalues = new long[dblValues.Length]; // for (int i = 0; i <= dblValues.Length - 1; i++) // { // longvalues[i] = long.Parse(Convert.ToString(dblValues[i])); // } // //IClassifyGEN classify = null; // IClassify classify = null; // switch (classMethod) // { // case "等间距分级": // EqualInterval eqclassify = new EqualIntervalClass(); // eqclassify.Classify(vValues, longvalues, ref numClasses); // classify = eqclassify as IClassify; // break; // case "自然断点分级": // NaturalBreaks naclassify = new NaturalBreaksClass(); // naclassify.Classify(vValues, longvalues, ref numClasses); // classify = naclassify as IClassify; // break; // } // //switch (classMethod) // //{ // // case "等间距分级": // // classify = new EqualIntervalClass(); // // break; // // case "自然断点分级": // // classify = new NaturalBreaksClass(); // // break; // //} // //classify.Classify(vValues, longvalues, ref numClasses); // double[] Classes = classify.ClassBreaks as double[]; // UID pUid = classify.ClassID; // IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties; // rasClassifyUI.ClassificationMethod = pUid; // rasClassifyRender.ClassCount = count; // IColor pColor; // ISimpleFillSymbol pSym; // for (int j = 0; j < count; j++) // { // pColor = ramp.get_Color(j * (ramp.Size / count)); // pSym = new SimpleFillSymbolClass(); // pSym.Color = pColor; // rasClassifyRender.set_Symbol(j, (ISymbol)pSym); // rasRender.Update(); // if (Classes[j] == 0) // { // rasClassifyRender.set_Label(j, Classes[j].ToString() + "-" + Classes[j + 1].ToString("0.000")); // rasRender.Update(); // } // else // { // rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000")); // rasRender.Update(); // } // } // rastlayer.Renderer = rasClassifyRender as IRasterRenderer; public void RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp) { try { //进行唯一值判断 IUniqueValues values = new UniqueValuesClass(); IRasterCalcUniqueValues unique = new RasterCalcUniqueValuesClass(); unique.AddFromRaster(rastlayer.Raster, 0, values); int uniquecount = values.get_UniqueCount(0); //计算统计图 IRasterBand band = GetBand(rastlayer); if (band.Histogram == null) { band.ComputeStatsAndHist(); } IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass(); IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer; rasRender.Raster = rastlayer.Raster; rasRender.Update(); int numClasses = count; IRasterHistogram pRasterHistogram = band.Histogram; double[] dblValues = pRasterHistogram.Counts as double[]; int intValueCount = dblValues.GetUpperBound(0) + 1; double[] vValues = new double[intValueCount]; IRasterStatistics pRasterStatistic = band.Statistics; double dMaxValue = pRasterStatistic.Maximum; double dMinValue = pRasterStatistic.Minimum; if (dMinValue == 0) { pRasterStatistic.IgnoredValues = pRasterStatistic.Minimum; pRasterStatistic.Recalculate(); dMinValue = pRasterStatistic.Minimum; } double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount); for (int i = 0; i < intValueCount; i++) { vValues[i] = i * BinInterval + pRasterStatistic.Minimum; } long[] longvalues = new long[dblValues.Length]; for (int i = 0; i <= dblValues.Length - 1; i++) { longvalues[i] = long.Parse(Convert.ToString(dblValues[i])); } //IClassifyGEN classify = null; IClassify classify = null; switch (classMethod) { case "等间距分级": EqualInterval eqclassify = new EqualIntervalClass(); eqclassify.Classify(vValues, longvalues, ref numClasses); classify = eqclassify as IClassify; break; case "自然断点分级": NaturalBreaks naclassify = new NaturalBreaksClass(); naclassify.Classify(vValues, longvalues, ref numClasses); classify = naclassify as IClassify; break; } #region //switch (classMethod) //{ // case "等间距分级": // classify = new EqualIntervalClass(); // break; // case "自然断点分级": // classify = new NaturalBreaksClass(); // break; //} //classify.Classify(vValues, longvalues, ref numClasses); #endregion double[] Classes = classify.ClassBreaks as double[]; int n = Classes.Count(); double dn = Classes[0]; UID pUid = classify.ClassID; IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties; rasClassifyUI.ClassificationMethod = pUid; rasClassifyRender.ClassCount = count; IColor pColor; ISimpleFillSymbol pSym; //排除数值 double[] exdouble = new double[2] { 0, Classes[0] }; IRasterDataExclusion ex = rasClassifyRender as IRasterDataExclusion; ex.ExcludeValues = exdouble; ex.ExcludeColor = GET(255, 255, 255); for (int j = 0; j < count; j++) { pColor = ramp.get_Color(j * (ramp.Size / count)); pSym = new SimpleFillSymbolClass(); pSym.Color = pColor; rasClassifyRender.set_Symbol(j, (ISymbol)pSym); rasRender.Update(); rasClassifyRender.set_Break(j, rasClassifyRender.get_Break(j)); rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000")); rasRender.Update(); } //IRasterProps rasterProps = (IRasterProps)rastlayer.Raster; //rasterProps.NoDataValue = 0; //IRasterDisplayProps props = rasClassifyRender as IRasterDisplayProps; //props.NoDataColor = GET(255, 255, 255); //rasRender.Update(); rastlayer.Renderer = rasClassifyRender as IRasterRenderer; } catch (Exception ex) { //MessageBox.Show(ex.ToString()); if (ex.ToString().Contains("唯一值过多")) { MessageBox.Show("唯一值数量已达到限制(65536)"); } else { MessageBox.Show("还未计算唯一值,进行唯一值计算!"); } } //catch //{ // MessageBox.Show("数据需要先计算统计值,请点击确定进行计算!"); //} }
public IRasterDataset TinToRaster2(ITinAdvanced pTinAdvanced, esriRasterizationType pRastConvType, String sDir, String sName, rstPixelType ePixelType, Double cellsize, IEnvelope pExtent, bool bPerm, String strType) { try { ESRI.ArcGIS.Geometry.IPoint pOrigin = pExtent.LowerLeft; pOrigin.X = pOrigin.X - (cellsize * 0.5); pOrigin.Y = pOrigin.Y - (cellsize * 0.5); int nCol, nRow; nCol = Convert.ToInt32(Math.Round(pExtent.Width / cellsize)) + 1; nRow = Convert.ToInt32(Math.Round(pExtent.Height / cellsize)) + 1; IGeoDataset pGeoDataset = pTinAdvanced as IGeoDataset; ISpatialReference2 pSpatialReference2 = pGeoDataset.SpatialReference as ISpatialReference2; IRasterDataset pRasterDataset = CreateRasterSurf(sDir, sName, strType, pOrigin, nCol, nRow, cellsize, cellsize, ePixelType, pSpatialReference2, bPerm); IRawPixels pRawPixels = GetRawPixels(pRasterDataset, 0); IPnt pBlockSize = new DblPntClass(); pBlockSize.X = nCol; pBlockSize.Y = nRow; IPixelBlock3 pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize) as IPixelBlock3; object blockArray = pPixelBlock.get_PixelDataByRef(0); ITinSurface pTinSurface = pTinAdvanced as ITinSurface; IGeoDatabaseBridge2 pbridge2 = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass(); IRasterProps pRasterProps = pRawPixels as IRasterProps; object nodataFloat; object nodataInt; pOrigin.X = pOrigin.X + (cellsize * 0.5); pOrigin.Y = pOrigin.Y + (cellsize * nRow) - (cellsize * 0.5); if (ePixelType.ToString() == "PT_FLOAT") { nodataFloat = pRasterProps.NoDataValue; pTinSurface.QueryPixelBlock(pOrigin.X, pOrigin.Y, cellsize, cellsize, pRastConvType, nodataFloat, blockArray); } else { nodataInt = pRasterProps.NoDataValue; pTinSurface.QueryPixelBlock(pOrigin.X, pOrigin.Y, cellsize, cellsize, pRastConvType, nodataInt, blockArray); } if (pTinAdvanced.ProcessCancelled == false) { return(null); } IPnt pOffset = new DblPntClass(); pOffset.X = 0; pOffset.Y = 0; pRawPixels.Write(pOffset, pPixelBlock as IPixelBlock); if (!bPerm && ePixelType.ToString() == "PT_FLOAT") { IRasterBand pBand = pRawPixels as IRasterBand; IRasterStatistics pStats = pBand.Statistics; pStats.Recalculate(); } if (bPerm) { pRawPixels = null; pPixelBlock = null; pRasterProps = null; blockArray = 0; pRasterDataset = OpenRasterDataset(sDir, sName); } return(pRasterDataset); } catch { return(null); } }
public void RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp) { IRasterBand band = GetBand(rastlayer); if (band.Histogram == null) { band.ComputeStatsAndHist(); } IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass(); IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer; rasRender.Raster = rastlayer.Raster; rasRender.Update(); int numClasses = count; IRasterHistogram pRasterHistogram = band.Histogram; double[] dblValues = pRasterHistogram.Counts as double[]; int intValueCount = dblValues.GetUpperBound(0) + 1; double[] vValues = new double[intValueCount]; IRasterStatistics pRasterStatistic = band.Statistics; double dMaxValue = pRasterStatistic.Maximum; double dMinValue = pRasterStatistic.Minimum; if (dMinValue == 0) { pRasterStatistic.IgnoredValues = pRasterStatistic.Minimum; pRasterStatistic.Recalculate(); dMinValue = pRasterStatistic.Minimum; } double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount); for (int i = 0; i < intValueCount; i++) { vValues[i] = i * BinInterval + pRasterStatistic.Minimum; } long[] longvalues = new long[dblValues.Length]; for (int i = 0; i <= dblValues.Length - 1; i++) { longvalues[i] = long.Parse(Convert.ToString(dblValues[i])); } //IClassifyGEN classify = null; IClassify classify = null; switch (classMethod) { case "等间距分级": EqualInterval eqclassify = new EqualIntervalClass(); eqclassify.Classify(vValues, longvalues, ref numClasses); classify = eqclassify as IClassify; break; case "自然断点分级": NaturalBreaks naclassify = new NaturalBreaksClass(); naclassify.Classify(vValues, longvalues, ref numClasses); classify = naclassify as IClassify; break; } //switch (classMethod) //{ // case "等间距分级": // classify = new EqualIntervalClass(); // break; // case "自然断点分级": // classify = new NaturalBreaksClass(); // break; //} //classify.Classify(vValues, longvalues, ref numClasses); double[] Classes = classify.ClassBreaks as double[]; UID pUid = classify.ClassID; IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties; rasClassifyUI.ClassificationMethod = pUid; rasClassifyRender.ClassCount = count; IColor pColor; ISimpleFillSymbol pSym; for (int j = 0; j < count; j++) { IRasterProps rasterProps = (IRasterProps)rastlayer.Raster; rasterProps.NoDataValue = 0; pColor = ramp.get_Color(j * (ramp.Size / count)); pSym = new SimpleFillSymbolClass(); pSym.Color = pColor; rasClassifyRender.set_Symbol(j, (ISymbol)pSym); rasRender.Update(); rasClassifyRender.set_Break(j, rasClassifyRender.get_Break(j)); rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000")); rasRender.Update(); } rastlayer.Renderer = rasClassifyRender as IRasterRenderer; }