- 积分
- 478
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-8-7
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2015-1-12 09:40:23
|
显示全部楼层
源码如下
#region 构造函数
public Form1()
{
InitializeComponent();
}
#endregion
#region 窗体载入
private void Form1_Load(object sender, EventArgs e)
{
Add_FS_County_Line();
createShare();
SetMapLayout();
}
#endregion
#region 添加县区界线
private void Add_FS_County_Line()
{
string aFile = @"F:\资料\shp地图\荆门\荆门地区.shp";
MapLayer aLayer = MapDataManage.OpenLayer(aFile);
aLayer.LegendScheme.LegendBreaks[0].Color = Color.Black;
aLayer.LayerName = "县区";
aLayer.IsMaskout = false;
MeteoInfoC.Layer.VectorLayer label = (MeteoInfoC.Layer.VectorLayer)aLayer;
label.LabelSet.FieldName = "NAME";
label.AvoidCollision = true;
label.AddLabels();
layersLegend1.ActiveMapFrame.AddLayer(aLayer);
mapView1.ZoomToExtent(mapView1.Extent);
}
#endregion
#region 设置maplayout
private void SetMapLayout()
{
//设置画布尺寸
mapLayout1.PageBounds = Rectangle.FromLTRB(0, 0, 900, 600);
mapLayout1.ActiveLayoutMap.Left = 3;
mapLayout1.ActiveLayoutMap.Top = 3;
mapLayout1.ActiveLayoutMap.Width = 893;
mapLayout1.ActiveLayoutMap.Height = 593;
//设置画布活动区域边界样式
mapLayout1.ActiveLayoutMap.DrawNeatLine = true;
mapLayout1.ActiveLayoutMap.NeatLineColor = Color.Black;
mapLayout1.ActiveLayoutMap.NeatLineSize = 3;
//加入标题
mapLayout1.AddText("降水分布图", 250, 45, "黑体", 14);
//加入图例
LayoutLegend alegend = mapLayout1.AddLegend(3, 417);
alegend.Font = new Font("宋体", 10);
alegend.LegendStyle = LegendStyles.Normal;
alegend.LegendLayer = layersLegend1.ActiveMapFrame.MapView.Layers[1];
alegend.DrawNeatLine = true;
alegend.NeatLineColor = Color.Black;
alegend.NeatLineSize = 2;
//加入指北针
LayoutNorthArrow lna = mapLayout1.AddNorthArrow(820, 40);
lna.BackColor = Color.White;
lna.ForeColor = Color.Black;
lna.Width = 40;
lna.Height = 60;
mapLayout1.PaintGraphics();
mapLayout1.Refresh();
}
#endregion
#region 设置插值格点数据
private void createShare()
{
//设置插值格点数据
GridDataSetting aGDP = new GridDataSetting();
Extent ex = new Extent();
ex.minX = 10;
ex.minY = 10;
ex.maxX = 150;
ex.maxY = 150;
aGDP.DataExtent = ex; //加入插值范围
aGDP.YNum = 150; //格点点数
aGDP.XNum = 150; //格点点数
//插值方法
InterpolationSetting agrid = new InterpolationSetting();
agrid.GridDataSet = aGDP;
agrid.InterpolationMethod = InterpolationMethods.IDW_Radius;
agrid.Radius = 2;
agrid.MinPointNum = 1;
double[] X = new double[1];
double[] Y = new double[1];
ContourDraw.CreateGridXY(aGDP, ref X, ref Y);
VectorLayer alayer = (VectorLayer)layersLegend1.ActiveMapFrame.MapView.Layers[0];
AttributeTable att = new AttributeTable();
att = alayer.AttributeTable;
DataTable dt = att.Table;
int column = dt.Columns.Count;
int row = dt.Rows.Count;
double[,] S = new double[3, row];
Random rand = new Random();
double[] num = new double[2] { 0, 30.8 };
MeteoInfoC.Layer.VectorLayer label = (MeteoInfoC.Layer.VectorLayer)layersLegend1.ActiveMapFrame.MapView.Layers[0];
for (int i = 0; i < label.ShapeNum; i++)
{
Shape tempshape = label.ShapeList[i];
S[0, i] = tempshape.Extent.minX;
S[1, i] = tempshape.Extent.minY;
S[2, i] = num[rand.Next(0, 2)];
}
S = ContourDraw.FilterDiscreteData_Radius(S, agrid.Radius, agrid.GridDataSet.DataExtent, -9999.0F);
GridData grid = new GridData();
grid = ContourDraw.InterpolateDiscreteData_Radius(S, X, Y, agrid.MinPointNum, agrid.Radius, -9999.0F);
LegendScheme lgd = new LegendScheme(ShapeTypes.Polygon);
double min = grid.GetMinValue();
double max = grid.GetMaxValue();
lgd.ImportFromXMLFile(AppDomain.CurrentDomain.BaseDirectory + "\\Rain.lgs");
lgd.MaxValue = max;
lgd.MinValue = min;
VectorLayer lineLayer = new VectorLayer(ShapeTypes.Polygon);
lineLayer = DrawMeteoData.CreateShadedLayer(grid, lgd, "图例(毫米)", "LGD");
lineLayer.Visible = true;
lineLayer.IsMaskout = true;
layersLegend1.ActiveMapFrame.AddLayer(lineLayer);
//加入掩膜
MaskOut ma = new MaskOut(mapView1);
ma.MaskLayer = "县区";
ma.SetMaskLayer = true;
mapView1.MaskOut = ma;
mapView1.PaintLayers();
layersLegend1.Refresh();
}
#endregion |
|