阅读:1507回复:0
各位GIS的兄弟们,来帮个忙,看看这个...........
<P>这个是一个分类渲染的,不过运行不了的,请你们帮个忙看看是应该怎么改的</P>
<P>出错就在这一行 Classes =(double[])pClassify.ClassBreaks;<BR>,说是未将对象实例化的,</P> <P>public class Form1 : System.Windows.Forms.Form<BR> {<BR> private System.Windows.Forms.Button cmdClassBk;<BR> private ESRI.ArcGIS.MapControl.AxMapControl axMapControl1;<BR> public const string strNameField = "STATE_NAME";<BR> public const string strPopField1="POP1990";<BR> // public const string strPopField2="POP1999";<BR> private IGeoFeatureLayer pGeoFeatureLayer;<BR> /// <summary><BR> /// 必需的设计器变量。<BR> /// </summary><BR> private System.ComponentModel.Container components = null;</P> <P> public Form1()<BR> {<BR> //<BR> // Windows 窗体设计器支持所必需的<BR> //<BR> InitializeComponent();</P> <P> //<BR> // TOD 在 InitializeComponent 调用后添加任何构造函数代码<BR> //<BR> }</P> <P> /// <summary><BR> /// 清理所有正在使用的资源。<BR> /// </summary><BR> protected override void Dispose( bool disposing )<BR> {<BR> if( disposing )<BR> {<BR> if (components != null) <BR> {<BR> components.Dispose();<BR> }<BR> }<BR> base.Dispose( disposing );<BR> }</P> <P> #region Windows 窗体设计器生成的代码<BR> /// <summary><BR> /// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR> /// 此方法的内容。<BR> /// </summary><BR> private void InitializeComponent()<BR> {<BR> System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));<BR> this.cmdClassBk = new System.Windows.Forms.Button();<BR> this.axMapControl1 = new ESRI.ArcGIS.MapControl.AxMapControl();<BR> ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit();<BR> this.SuspendLayout();<BR> // <BR> // cmdClassBk<BR> // <BR> this.cmdClassBk.Location = new System.Drawing.Point(240, 24);<BR> this.cmdClassBk.Name = "cmdClassBk";<BR> this.cmdClassBk.TabIndex = 0;<BR> this.cmdClassBk.Text = "ClassBk";<BR> this.cmdClassBk.Click += new System.EventHandler(this.cmdClassBk_Click);<BR> // <BR> // axMapControl1<BR> // <BR> this.axMapControl1.Location = new System.Drawing.Point(16, 64);<BR> this.axMapControl1.Name = "axMapControl1";<BR> this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState")));<BR> this.axMapControl1.Size = new System.Drawing.Size(672, 320);<BR> this.axMapControl1.TabIndex = 1;<BR> // <BR> // Form1<BR> // <BR> this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR> this.ClientSize = new System.Drawing.Size(720, 390);<BR> this.Controls.Add(this.axMapControl1);<BR> this.Controls.Add(this.cmdClassBk);<BR> this.Name = "Form1";<BR> this.Text = "Form1";<BR> ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit();<BR> this.ResumeLayout(false);</P> <P> }<BR> #endregion</P> <P> /// <summary><BR> /// 应用程序的主入口点。<BR> /// </summary><BR> [STAThread]<BR> static void Main() <BR> {<BR> Application.Run(new Form1());<BR> }</P> <P> private void cmdClassBk_Click(object sender, System.EventArgs e)<BR> {<BR> pGeoFeatureLayer=new FeatureLayerClass();<BR> ITable pTable;<BR> ITableHistogram pTableHistogram;<BR> IHistogram pHistogram;<BR> IClassify pClassify;<BR> object dataValues;<BR> object dataFrequency;<BR> if(axMapControl1.LayerCount>0)<BR> {<BR> pGeoFeatureLayer=axMapControl1.get_Layer(0) as IGeoFeatureLayer;<BR> }<BR> pTable =pGeoFeatureLayer as ITable;<BR> pTableHistogram = new TableHistogramClass();<BR> pHistogram = pTableHistogram as IHistogram;<BR> pTableHistogram.Field = strPopField1;<BR> //pTableHistogram.Field = strPopField2;<BR> pTableHistogram.Table = pTable;<BR> pHistogram.GetHistogram(out dataValues, out dataFrequency);<BR> <BR> <BR> pClassify = new EqualIntervalClass();<BR> pClassify.SetHistogramData( dataValues, dataFrequency);<BR> <BR> <BR> double[] Classes;<BR> int numDesiredClasses = 3;<BR> pClassify.Classify(ref numDesiredClasses); <BR> <FONT color=#ff0000> Classes =(double[])pClassify.ClassBreaks;<BR></FONT> //Classes = pClassify.ClassBreaks as double[];<BR> int ClassesCount = Classes.Length;<BR> </P> <P> IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();<BR> pClassBreaksRenderer.Field = strPopField1;<BR> // pClassBreaksRenderer.Field = strPopField2 ;<BR> pClassBreaksRenderer.BreakCount = ClassesCount;<BR> pClassBreaksRenderer.SortClassesAscending = true;</P> <P> IHsvColor pFromColor = new HsvColorClass();<BR> pFromColor.Hue = 60 ; <BR> pFromColor.Saturation = 100;<BR> pFromColor.Value = 96;</P> <P> IHsvColor pToColor = new HsvColorClass();<BR> pToColor.Hue = 0;<BR> pToColor.Saturation = 100;<BR> pToColor.Value = 96;</P> <P> IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();<BR> IEnumColors pEnumColors;<BR> bool ok;</P> <P> pRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;<BR> pRamp.FromColor = pFromColor;<BR> pRamp.ToColor = pToColor;<BR> pRamp.Size = ClassesCount;<BR> pRamp.CreateRamp(out ok);<BR> pEnumColors = pRamp.Colors;</P> <P> IColor pColor;<BR> ISimpleFillSymbol pFillSymbol;<BR> int breakIndex;</P> <P> for(breakIndex =0;breakIndex<ClassesCount;breakIndex++)<BR> {<BR> pColor = pEnumColors.Next();<BR> pFillSymbol = new SimpleFillSymbolClass();<BR> pFillSymbol.Color = pColor;<BR> pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;<BR> pClassBreaksRenderer.set_Symbol(breakIndex, pFillSymbol as ISymbol);<BR> pClassBreaksRenderer.set_Break(breakIndex, (double)Classes[breakIndex + 1]);<BR> }<BR> pGeoFeatureLayer.Renderer = pClassBreaksRenderer as IFeatureRenderer;<BR> this.axMapControl1.CtlRefresh(esriViewDrawPhase.esriViewGeography,null,null);</P> <P><BR> }</P> <P> }</P> |
|