using System;
using System.Collections.Generic;
using
System.ComponentModel;
using System.Data;
using System.Drawing;
using
System.Linq;
using System.Text;
using System.Windows.Forms;
using
ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Controls;
using
ESRI.ArcGIS.Carto;
namespace 专题图自动化系统
{
public partial class ColorMap
: Form
{
double max, min;
AxMapControl
axMapControl1;
string
FindField;
public ColorMap(double
_max,double _min,AxMapControl ax,string
findField)
{
InitializeComponent();
max =
_max;
min
= _min;
axMapControl1 =
ax;
FindField = findField;
}
IFeatureClass
pFeatureClass;
private void
FindCity()
{
IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as
IFeatureLayer;
if (pFeatureLayer !=
null)
pFeatureClass =
pFeatureLayer.FeatureClass;
int[] index = new
int[2];//name字段+查询依据字段
for (int i = 0; i < index.Length;
i++)
{
if (i ==
0)
index[i] =
pFeatureClass.Fields.FindField("name");
else
index[i] =
pFeatureClass.Fields.FindField(FindField);
}
IFeatureCursor pFeatureCursor =
pFeatureClass.Search(null,false);
IFeature pFeature =
pFeatureCursor.NextFeature();
object [] value=new
object[index.Length];
while (pFeature !=
null)
{
for (int i = 0; i < index.Length;
i++)
{
value[i] =
pFeature.get_Value(index[i]);
if (i ==
1)
{
double a =
Convert.ToDouble(value[1].ToString());
switch
(searchCity.Length)
{
case 2: N1.Add(value[0].ToString());
break;
case 3: if (a <= searchCity[1]) {
N1.Add(value[0].ToString());}
else{N2.Add(value[0].ToString());}break;
case 4: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
if (a > searchCity[2]) { N3.Add(value[0].ToString());
}break;
case 5: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
if (a > searchCity[2]&&a<=searchCity[3]) {
N3.Add(value[0].ToString());
}
if(a>searchCity[3]){N4.Add(value[0].ToString());}break;
case 6: if (a <= searchCity[1]) { N1.Add(value[0].ToString());
}
if (a > searchCity[1] && a <= searchCity[2]) {
N2.Add(value[0].ToString());
}
if (a > searchCity[2] && a <= searchCity[3]) {
N3.Add(value[0].ToString());
}
if (a > searchCity[3]&&a<=searchCity[4]) {
N4.Add(value[0].ToString());
}
if(a>searchCity[4]){N5.Add(value[0].ToString());}break;
}
}
}
pFeature =
pFeatureCursor.NextFeature();
}
}
List<string> N1 = new
List<string>();
List<string> N2 = new
List<string>();
List<string> N3 = new
List<string>();
List<string> N4 = new
List<string>();
List<string> N5 = new
List<string>();
private void
DrawCity()
{
Bitmap
bt = new
Bitmap(panel3.Width,panel3.Height);
Graphics g =
Graphics.FromImage(bt);
Pen pen = new
Pen(Color.Black,1);
string []n1=new
string[6];
if (N1 !=
null)
{
foreach (string a in
N1)
{
n1[1] += a +
",";
}
}
if (N2
!= null)
{
foreach (string a in
N2)
{
n1[2] += a +
",";
}
}
if (N3
!= null)
{
foreach (string a in
N3)
{
n1[3] += a +
",";
}
}
if (N4
!= null)
{
foreach (string a in
N4)
{
n1[4] += a +
",";
}
}
if (N5
!= null)
{
foreach (string a in
N5)
{
n1[5] += a +
",";
}
}
for (int
i = 1; i <= n;
i++)
{
g.DrawString("第" + i + "级:" +n1[i], new Font("黑体", 10), new
SolidBrush(Color.Black), new PointF(20, 25 *
i));
}
panel3.BackgroundImage = bt;
}
private void
DrawString()
{
Bitmap
bt = new
Bitmap(panel2.Width,panel2.Height);
Graphics g =
Graphics.FromImage(bt);
Pen pen = new
Pen(Color.Black,1);
double fromValue =
min;
searchCity[0] =
fromValue;
double
toValue;
for (int i = 1; i <= n;
i++)
{
if (i ==
index)
toValue = min + (x2 - temp[1]) * k /
flag;
else
toValue=min + i *
k;
searchCity[i] =
toValue;
g.DrawString("第"+i+"级:"+fromValue+"万到"+toValue+"万",new Font("黑体",10),new
SolidBrush(Color.Black),new
PointF(20,25*i));
fromValue=toValue;
}
panel2.BackgroundImage = bt;
}
double
k;
private void
DrawZft()
{
Bitmap
bt = new
Bitmap(panel1.Width,panel1.Height);
Graphics g =
Graphics.FromImage(bt);
Pen pen = new
Pen(Color.White,1);
g.DrawLine(pen,new Point(30,0),new
Point(30,panel1.Height-30));
g.DrawLine(pen,new Point(30,panel1.Height-30),new
Point(panel1.Width-4,panel1.Height-30));
k = (max - min) /
n;
for
(int i = 1; i <= n+1;
i++)
{
if (i ==
index)
{
g.DrawString((min + (x2-temp[1]) * k/flag).ToString(), new Font("宋体", 9), new
SolidBrush(Color.White), new PointF(x2 - 2,
panel1.Height-30));
g.DrawLine(pen, new PointF(x2, panel1.Height-30), new PointF(x2,
0));
}
else
{
g.DrawString((min + (i-1) * k).ToString(), new Font("宋体", 9), new
SolidBrush(Color.White), new PointF(temp[i] - 8,
panel1.Height-30));
g.DrawLine(pen, new PointF(temp[i], panel1.Height-30), new PointF(temp[i],
0));
}
}
panel1.BackgroundImage = bt;
}
int
n=0;
float[]
temp;
int
flag;
double
[]searchCity;
private void
comboBox1_SelectedIndexChanged(object sender, EventArgs
e)
{
n =
int.Parse(comboBox1.SelectedItem.ToString());
temp = new float[n +
2];
searchCity=new
double[n+1];
flag = (panel1.Width - 4) / (n +
1);
for
(int i = 1; i <= n+1;
i++)
{
temp[i] = flag *
i;
}
if (N1
!=
null)
N1.Clear();
if (N2 !=
null)
N2.Clear();
if (N3 !=
null)
N3.Clear();
if (N4 !=
null)
N4.Clear();
if (N5 !=
null)
N5.Clear();
DrawZft();
DrawString();
FindCity();
DrawCity();
}
int
index=0;
int x1, x2,
x3;
private void
panel1_MouseDown(object sender, MouseEventArgs
e)
{
x1 =
e.X;
for
(int i = 1; i < temp.Length;
i++)
{
if (Math.Abs(x1 - temp[i]) <
3)
{
index =
i;
}
}
}
private void
panel1_MouseMove(object sender, MouseEventArgs
e)
{
x2=e.X;
if
(index !=
0)
{
if (N1 !=
null)
N1.Clear();
if (N2 !=
null)
N2.Clear();
if (N3 !=
null)
N3.Clear();
if (N4 !=
null)
N4.Clear();
if (N5 !=
null)
N5.Clear();
DrawZft();
DrawString();
FindCity();
DrawCity();
}
}
private void
panel1_MouseUp(object sender, MouseEventArgs
e)
{
x3 =
e.X;
temp[index] =
x3;
DrawZft();
index = 0;
}
}
}
模仿ArcGIS用Graphics重绘的直方图分级调节器,布布扣,bubuko.com