- 积分
- 418
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-8-4
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2012-12-17 22:55:40
|
显示全部楼层
本帖最后由 记忆碎片 于 2012-12-18 09:09 编辑
结贴!
再次感谢王老师的指导。所有代码共享如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using LightningStrikeLibrary;
- using MeteoInfoC.Layer;
- using MeteoInfoC.Shape;
- using MeteoInfoC.Legend;
- using MeteoInfoC.Drawing;
- using System.Drawing;
- using MeteoInfoC;
- namespace MeteoInfoControlLibrary
- {
- class DrawLightningStrikes
- {
- public DrawLightningStrikes(List<LightningStrike_Standard> _strikes,LayersLegend _targetLayerLegend)
- {
- strikesSource = new List<LightningStrike_Standard>();
- strikesSource = _strikes;
- ClassifyStrikes(strikesSource);
- targetLayerLegend = _targetLayerLegend;
- }
- #region 属性变量
- List<LightningStrike_Standard> strikesSource, strikesSourceNegative, strikesSourcePositive;
- LayersLegend targetLayerLegend;
- string layerNameNegative="NegativeFlashesLayer";
- string layerNamePositive = "PositiveFlashesLayer";
- public string LayerNamePositive
- {
- get { return layerNamePositive; }
- set { layerNamePositive = value; }
- }
- public string LayerNameNegative
- {
- get { return layerNameNegative; }
- set { layerNameNegative = value; }
- }
- public List<LightningStrike_Standard> StrikesSource
- {
- get { return strikesSource; }
- set { strikesSource = value; }
- }
- public LayersLegend TargetLayerLegend
- {
- get { return targetLayerLegend; }
- set { targetLayerLegend = value; }
- }
- #endregion
- #region 私有函数
- /// <summary>
- /// 给strikesSourceNegative、strikesSourcePositive赋值
- /// </summary>
- private void ClassifyStrikes(List<LightningStrike_Standard> _strikesSource)
- {
- strikesSourceNegative = new List<LightningStrike_Standard>();
- strikesSourcePositive = new List<LightningStrike_Standard>();
- strikesSourceNegative = _strikesSource.Where(r => r.Intensity <= 0).Select(r => r).ToList();
- strikesSourcePositive = _strikesSource.Where(r => r.Intensity > 0).Select(r => r).ToList();
- }
- /// <summary>
- /// 添加负闪图层,用蓝色"-"表示
- /// </summary>
- /// <param name="_strikesSourceNegative"></param>
- private void DrawStrikesSourceNegative(List<LightningStrike_Standard> _strikesSourceNegative)
- {
- //New layer
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Point);
- aLayer.LayerName = layerNameNegative;
- aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Blue, 10);
- //((PointBreak)aLayer.LegendScheme.breakList[0]).Style = PointStyle.Plus; //标记为加号
- //减号标记未知,等待王老师增加Point.Minus
- ((PointBreak)aLayer.LegendScheme.breakList[0]).MarkerType = MarkerType.Character;
- ((PointBreak)aLayer.LegendScheme.breakList[0]).CharIndex = 45;//减号
- //((PointBreak)aLayer.LegendScheme.breakList[0]).CharIndex = 43;//加号
- aLayer.Visible = true;
- //Add fields
- aLayer.EditAddField("日期时间", typeof(DateTime));
- aLayer.EditAddField("经度", typeof(double));
- aLayer.EditAddField("纬度", typeof(double));
- aLayer.EditAddField("强度", typeof(double));
- aLayer.EditAddField("陡度", typeof(double));
- aLayer.EditAddField("误差", typeof(double));
- aLayer.EditAddField("探测方式", typeof(string));
- ////Prepare coordinate data
- //int sourceSumNum = _strikesSourceNegative.Count();
- //Add shape
- foreach (IStrike_Standard tmpStrike in _strikesSourceNegative)
- {
- PointShape aPS = new PointShape();
- PointD aPoint = new PointD();
- aPoint.X = tmpStrike.Longitude;
- aPoint.Y = tmpStrike.Latitude;
- aPS.Point = aPoint;
- int shapeNum = aLayer.ShapeNum;
- if (aLayer.EditInsertShape(aPS, shapeNum))
- {
- //Edit record value
- aLayer.EditCellValue("日期时间", shapeNum, tmpStrike.DateAndTime);
- aLayer.EditCellValue("经度", shapeNum, aPoint.X);
- aLayer.EditCellValue("纬度", shapeNum, aPoint.Y);
- aLayer.EditCellValue("强度", shapeNum, tmpStrike.Intensity);
- aLayer.EditCellValue("陡度", shapeNum, tmpStrike.Slope);
- aLayer.EditCellValue("误差", shapeNum, tmpStrike.Error);
- aLayer.EditCellValue("探测方式", shapeNum, tmpStrike.LocationMode);
- }
- }
- //Add layer
- targetLayerLegend.ActiveMapFrame.AddLayer(aLayer);
- targetLayerLegend.ActiveMapFrame.MapView.PaintLayers();
- targetLayerLegend.Refresh();
- }
- /// <summary>
- /// 添加负闪图层,用红色"+"表示
- /// </summary>
- /// <param name="_strikesSourcePositive"></param>
- private void DrawStrikesSourcePositive(List<LightningStrike_Standard> _strikesSourcePositive)
- {
- //New layer
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Point);
- aLayer.LayerName = layerNameNegative;
- aLayer.LegendScheme = LegendManage.CreateSingleSymbolLegendScheme(ShapeTypes.Point, Color.Red, 10);
- //((PointBreak)aLayer.LegendScheme.breakList[0]).Style = PointStyle.Plus; //标记为加号
- //减号标记未知,等待王老师增加Point.Minus
- ((PointBreak)aLayer.LegendScheme.breakList[0]).MarkerType = MarkerType.Character;
- //((PointBreak)aLayer.LegendScheme.breakList[0]).CharIndex = 45;//减号
- ((PointBreak)aLayer.LegendScheme.breakList[0]).CharIndex = 43;//加号
- aLayer.Visible = true;
- //Add fields
- aLayer.EditAddField("日期时间", typeof(DateTime));
- aLayer.EditAddField("经度", typeof(double));
- aLayer.EditAddField("纬度", typeof(double));
- aLayer.EditAddField("强度", typeof(double));
- aLayer.EditAddField("陡度", typeof(double));
- aLayer.EditAddField("误差", typeof(double));
- aLayer.EditAddField("探测方式", typeof(string));
- ////Prepare coordinate data
- //int sourceSumNum = _strikesSourceNegative.Count();
- //Add shape
- foreach (IStrike_Standard tmpStrike in _strikesSourcePositive)
- {
- PointShape aPS = new PointShape();
- PointD aPoint = new PointD();
- aPoint.X = tmpStrike.Longitude;
- aPoint.Y = tmpStrike.Latitude;
- aPS.Point = aPoint;
- int shapeNum = aLayer.ShapeNum;
- if (aLayer.EditInsertShape(aPS, shapeNum))
- {
- //Edit record value
- aLayer.EditCellValue("日期时间", shapeNum, tmpStrike.DateAndTime);
- aLayer.EditCellValue("经度", shapeNum, aPoint.X);
- aLayer.EditCellValue("纬度", shapeNum, aPoint.Y);
- aLayer.EditCellValue("强度", shapeNum, tmpStrike.Intensity);
- aLayer.EditCellValue("陡度", shapeNum, tmpStrike.Slope);
- aLayer.EditCellValue("误差", shapeNum, tmpStrike.Error);
- aLayer.EditCellValue("探测方式", shapeNum, tmpStrike.LocationMode);
- }
- }
- //Add layer
- targetLayerLegend.ActiveMapFrame.AddLayer(aLayer);
- targetLayerLegend.ActiveMapFrame.MapView.PaintLayers();
- targetLayerLegend.Refresh();
- }
- #endregion
- /// <summary>
- /// 绘制闪电图层,需要strikesSourceNegative, strikesSourcePositive
- /// </summary>
- public void DrawStrikes()
- {
- DrawStrikesSourcePositive(strikesSourcePositive);
- DrawStrikesSourceNegative(strikesSourceNegative);
- }
- }
- }
复制代码
LightningStrikeLibrary.dll
(13.5 KB, 下载次数: 0)
|
|