public Classifier(IServerContext mapContext, double [] values, int [] counts, String classifierType, int breaks) { m_classifier = (IClassifyGEN)mapContext.CreateObject("esriSystem." + classifierType); int b = breaks; m_classifier.Classify(values, counts, ref b); m_breaks = b; }
/// <summary> /// Returns breaks based on the given arguments. /// </summary> /// <param name="method">The classification method</param> /// <param name="featureClass">The featureClass with the data</param> /// <param name="field">The field to specify the data</param> /// <param name="numberOfClasses">The number of classes</param> /// <returns>An array of breaks. NOTE: the first value in the array is the smallest and not part of the breaks. Find more at: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IClassifyGEN_Interface/0042000000m2000000/ </returns> public static double[] Classify(IClassifyGEN method, IFeatureClass featureClass, IField field, int numberOfClasses) { double[] data; int[] freq; var numberClasses = numberOfClasses; Histogram(featureClass, field, out data, out freq); method.Classify(data, freq, numberOfClasses); return(method.ClassBreaks as double[]); }
private void btRender_Click(object sender, EventArgs e) { int number = 0; if (cbColorRamp.SelectedIndex == -1) { if (lang == Language.Chinese) { MessageBox.Show("请先选择一种色带"); } else if (lang == Language.English) { MessageBox.Show("Please choose a color ribbon first"); } return; } try { number = int.Parse(txtNumber.Text); if (number <= 1) { if (lang == Language.Chinese) { MessageBox.Show("类别数量只能为>1的正整数"); } else if (lang == Language.English) { MessageBox.Show("The class number can only be a positive integer of >1"); } } } catch { if (lang == Language.Chinese) { MessageBox.Show("类别数量只能为整数"); } else if (lang == Language.English) { MessageBox.Show("The class number can only be an integer"); } } IRasterClassifyColorRampRenderer pRasterClassifyRenderer = new RasterClassifyColorRampRendererClass(); IRasterRenderer pRasterRenderer = pRasterClassifyRenderer as IRasterRenderer; IUniqueValues uniVal = new UniqueValuesClass(); IRasterCalcUniqueValues2 calValues = new RasterCalcUniqueValuesClass(); calValues.MaxUniqueValueCount = 10000000; calValues.AddFromRaster(rasterLayer.Raster, cbSelectedBand.SelectedIndex, uniVal); object vValues, vFrequences; uniVal.GetHistogram(out vValues, out vFrequences); double[] doubleArray = (double[])vValues; int[] longArray = (int[])vFrequences; int order = SortTool.CheckInOrder(doubleArray, doubleArray.Length); if (order == 0) { SortTool.QuickSort3(doubleArray, 0, doubleArray.Length - 1, longArray); } else if (order == -1) { SortTool.Reverse(doubleArray, doubleArray.Length, longArray); } IClassifyGEN classify = GetMethod(cbMethod.Text); classify.Classify((double[])vValues, (int[])vFrequences, ref number); double[] classes = classify.ClassBreaks as double[]; pRasterRenderer.Raster = rasterLayer.Raster; pRasterClassifyRenderer.ClassCount = number; for (int i = 0; i < classes.Length; i++) { pRasterClassifyRenderer.set_Break(i, classes[i]); } pRasterRenderer.Update(); IStyleGalleryItem galleryItem = symbol.GetItem(cbColorRamp.SelectedIndex); IColorRamp colorRamp = galleryItem.Item as IColorRamp; IFillSymbol fill = new SimpleFillSymbolClass() as IFillSymbol; int increase = colorRamp.Size / (number - 1); for (int i = 0; i < pRasterClassifyRenderer.ClassCount - 1; i++) { fill.Color = colorRamp.get_Color(i * increase); pRasterClassifyRenderer.set_Symbol(i, fill as ISymbol); pRasterClassifyRenderer.set_Label(i, pRasterClassifyRenderer.get_Break(i).ToString() + "-" + pRasterClassifyRenderer.get_Break(i + 1).ToString()); } fill.Color = colorRamp.get_Color(colorRamp.Size - 1); pRasterClassifyRenderer.set_Symbol(pRasterClassifyRenderer.ClassCount - 1, fill as ISymbol); pRasterClassifyRenderer.set_Label(pRasterClassifyRenderer.ClassCount - 1, pRasterClassifyRenderer.get_Break(pRasterClassifyRenderer.ClassCount - 1).ToString() + "-" + pRasterClassifyRenderer.get_Break(pRasterClassifyRenderer.ClassCount).ToString()); rasterLayer.Renderer = pRasterRenderer; succeed = true; this.Close(); }