求教 SharpMap高手,绘制等值面填色遇到的问题!

u010812075 u010812075 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
等值线绘制是GIS中很重要的一个功能, 所有的算法都封装在一个dll 中,我这里调用即可,下面的方法是在PictureBox1上用Paint 绘制出来的方法,主要是Graphics类绘的,现在想把所有的绘图函数换成sharpmap 的,
以下是我的代码, 等值线 可以绘制出来,但是在绘制等值面时,填色时结果颜色没法正确的填色,得到的是一个颜色,没有那种分级的效果
希望能指点一个错误所在:

private void TSB_Contour_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;

m_GridData = InterpolateDiscreteData(m_DiscreteData);
TracingContourLines();
m_ContourLines = Contour.SmoothLines(m_ContourLines);
m_ContourLines = Contour.CutContourWithPolygon(m_ContourLines, m_CutPList);
m_IsCutted = true;
TracingPolygons();
CreateLegend();

Cursor = Cursors.Default;
//

Point[] Points = null;
Point sPoint = default(Point);
wContour.PointD aPoint = default(wContour.PointD);
MapLine aMapLine = default(MapLine);
List<PointD> newPList = new List<PointD>();
int i = 0;
int j = 0;
Pen aPen = default(Pen);
Font drawFont = new Font("Arial", 8);

wContour.PolyLine aline = default(wContour.PolyLine);
double aValue = 0;
Color aColor = default(Color);
SolidBrush aBrush = default(SolidBrush);

SharpMap.Geometries.Point ps = new SharpMap.Geometries.Point();

SharpMap.Geometries.GeometryCollection geoms = new SharpMap.Geometries.GeometryCollection();

//List<SharpMap.Geometries.Geometry> geoms = new List<SharpMap.Geometries.Geometry>();

if (this.CB_ColorIn.Checked) //填充色
{
Color aBackcolor = Color.White;
SharpMap.Layers.VectorLayer contureLayer = new SharpMap.Layers.VectorLayer("等值面");
wContour.Polygon aPolygon = default(wContour.Polygon);
for (i = 0; i <= m_ContourPolygons.Count - 1; i++)
{
aPolygon = m_ContourPolygons[i];
aline = aPolygon.OutLine;
aValue = aPolygon.LowValue;
aColor = m_Colors[Array.IndexOf(m_CValues, aValue) + 1];
if (!aPolygon.IsHighCenter)
{
for (j = 0; j <= m_Colors.Length - 1; j++)
{
if (aColor == m_Colors[j])
{
aColor = m_Colors[j - 1];
}
}
}
newPList = aline.PointList;
SharpMap.Geometries.Polygon pl = new SharpMap.Geometries.Polygon();
//Points = new Point[newPList.Count];

System.Collections.Generic.List<SharpMap.Geometries.Point> pointList = new List<SharpMap.Geometries.Point>();
SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString();

for (j = 0; j <= newPList.Count - 1; j++)
{
aPoint = newPList[j];
sPoint.X = (int)((aPoint.X - m_MinLon) * 3600 * m_scaleX);
sPoint.Y = (int)((m_MaxLat - aPoint.Y) * 3600 * m_scaleY);
//Points[j] = sPoint;
ps.X = aPoint.X;
ps.Y = aPoint.Y;

pointList.Add(new SharpMap.Geometries.Point { X = aPoint.X, Y = aPoint.Y });

line.Vertices.Add(new SharpMap.Geometries.Point { X = aPoint.X, Y = aPoint.Y });

}
aPen = new Pen(Color.Black);
aPen.Color = aColor;
aBrush = new SolidBrush(Color.Black);
aBrush.Color = aColor;
//下面绘制 要换成SharpMap的方法填充色
//e.Graphics.FillPolygon(aBrush, Points);

SharpMap.Geometries.LinearRing linearRing = new SharpMap.Geometries.LinearRing(pointList);

SharpMap.Geometries.Polygon polygon = new SharpMap.Geometries.Polygon(linearRing);

//geoms.Add(polygon);
geoms.Collection.Add(polygon);

if (this.CB_Outline.Checked)
{
//下面绘制 要换成SharpMap的方法绘制等值线
//e.Graphics.DrawLines(Pens.LightGray, Points);
//geoms.Add(line);
geoms.Collection.Add(line);
}


contureLayer = new SharpMap.Layers.VectorLayer("等值面"+i.ToString());
contureLayer.MaxVisible = 16;
contureLayer.Style.Fill = new SolidBrush(aColor);

if (this.CB_Outline.Checked)
{
contureLayer.Style.Line = new Pen(Color.LightGray, 2);
}
else
{
contureLayer.Style.Line = new Pen(Color.Red, 2);
}

SharpMap.Data.Providers.GeometryProvider gp = new SharpMap.Data.Providers.GeometryProvider(geoms);
contureLayer.DataSource = gp;
contureLayer.SRID = 4326;
contureLayer.MaxVisible = 16;
mapBox1.Map.Layers.Add(contureLayer);


}
//绘制
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
mapBox1.Refresh();

}
else //不填色
{
for (i = 0; i <= m_ContourLines.Count - 1; i++)
{
aline = m_ContourLines[i];
aValue = aline.Value;
aColor = m_Colors[Array.IndexOf(m_CValues, aValue)];
newPList = aline.PointList;

Points = new Point[newPList.Count];
for (j = 0; j <= newPList.Count - 1; j++)
{
aPoint = newPList[j];
sPoint.X = (int)((aPoint.X - m_MinLon) * 3600 * m_scaleX);
sPoint.Y = (int)((m_MaxLat - aPoint.Y) * 3600 * m_scaleY);
Points[j] = sPoint;
}
aPen = new Pen(Color.Black);
aPen.Color = aColor;
// 下面绘制 要换成SharpMap的方法绘制等值线
//e.Graphics.DrawLines(aPen, Points);
}
}

if (this.CB_Station.Checked) //绘制站点
{
double lon = 0;
double lat = 0;
double t = 0;
for (i = 0; i <= m_DiscreteData.GetLength(1) - 1; i++)
{
lon = m_DiscreteData[0, i];
lat = m_DiscreteData[1, i];
sPoint.X = (int)((lon - m_MinLon) * 3600 * m_scaleX);
sPoint.Y = (int)((m_MaxLat - lat) * 3600 * m_scaleY);
t = m_DiscreteData[2, i];
//绘制小圆点 和字体 转成SharpMap的方法
//e.Graphics.DrawEllipse(Pens.Blue, sPoint.X, sPoint.Y, 1.5f, 1.5f);
//e.Graphics.DrawString(t.ToString("0.0"), drawFont, Brushes.Blue, sPoint.X, sPoint.Y);
}
}

//---- 绘制图例板
wContour.Legend.lPolygon aLPolygon = default(wContour.Legend.lPolygon);
for (i = 0; i <= m_LegendPolygons.Count - 1; i++)
{
aLPolygon = m_LegendPolygons[i];
aValue = aLPolygon.value;
if (aLPolygon.isFirst)
{
aColor = m_Colors[0];
}
else
{
aColor = m_Colors[Array.IndexOf(m_CValues, aValue) + 1];
}
newPList = aLPolygon.pointList;

Points = new Point[newPList.Count];
for (j = 0; j <= newPList.Count - 1; j++)
{
aPoint = newPList[j];
sPoint.X = (int)((aPoint.X - m_MinLon) * 3600 * m_scaleX);
sPoint.Y = (int)((m_MaxLat - aPoint.Y) * 3600 * m_scaleY);
Points[j] = sPoint;
}
aBrush = new SolidBrush(Color.Black);
aBrush.Color = aColor;
//下面绘制 填色多边形 和 绘制 转成SharpMap的方法
// e.Graphics.FillPolygon(aBrush, Points);
// e.Graphics.DrawPolygon(Pens.Black, Points);

sPoint = Points[2];
if (i < m_LegendPolygons.Count - 1)
{
//绘制文字,转成SharpMap的方法
//e.Graphics.DrawString(m_CValues[i].ToString("0.0"), drawFont, Brushes.Black, sPoint.X - 10, sPoint.Y - 15);
}
}

//---- Draw title
string tStr = null;
//tStr = "河南省" + Format(m_ObsDate, "yyyy年M月d日H时") + "地面温度分布图"
tStr = "Temperature of Henan province in " + m_ObsDate.ToString("yyyy-MM-dd H:00");
sPoint.X = this.mapBox1.Width / 2 - 200;
sPoint.Y = 20;
drawFont = new Font("Arial", 10, FontStyle.Bold);
//e.Graphics.DrawString(tStr, drawFont, Brushes.Black, sPoint.X, sPoint.Y);

}

...全文
评论
收藏 已收藏
分享
返回顶部
u010812075
C# 111,130 成员 642,540 内容