登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
已有所有闪电发生的位置来计算和绘制闪电密度图。数据见此贴:http://bbs.06climate.com/forum.php?mod=viewthread&tid=14099&extra=&page=1
用脚本程序来实现,首先定义一个格点数据(GridData),主要参数是格点的X/Y方向的起始位置、格点间距、格点数。然后读取闪电位置数据文件,计算出每个闪电位于X/Y方向上第几个格点,将该格点的值加1,遍历所有闪电后就可以算出每个格点的闪电数目。可以将此格点数据存为一个文本格点数据文件(比如Surfer ASCII 格点数据),格点数据可以依据图例(LegendScheme)设置来生成等值线填充图层(Shaded)。
可以验证一下上面计算出的闪电密度数据是否正确。先用脚本程序生成一个闪电位置点图层:
再用上面保存的格点数据文件生成一个Grid_Fill图层:
将该图层每个图元进行标注(也就是每个格点中闪电发生的次数),图形放大后可以数数一些格点内的闪电个数和标注数字是否相同(相同当然说明计算正确了)
脚本程序如下:
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2013-5-5
- # Purpose: Read and plot lighting frequency data
- # Note: Sample
- #-----------------------------------------------------------
- #---- Import clr and classes
- import clr
- clr.AddReferenceByPartialName("System")
- clr.AddReferenceByPartialName("System.Drawing")
- from System import *
- clr.AddReference("MeteoInfoC.dll")
- from MeteoInfoC import *
- from MeteoInfoC.Data import *
- from MeteoInfoC.Data.MeteoData import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Shape import *
- import os.path
- #---- Set directory
- dataDir = "D:\\Temp\\ascii\\"
- #---- Define grid data
- print 'Define grid data...'
- x0 = 105
- y0 = 28
- xdelt = 0.1
- ydelt = 0.1
- xnum = 55
- ynum = 45
- gData = GridData(x0,xdelt,xnum,y0,ydelt,ynum)
- #---- Read lighting data file
- print 'Read lighting data file...'
- fn = dataDir + "cunshuju.txt"
- tf = open(fn)
- for aline in tf:
- datalist = aline.split()
- lat = float(datalist[1])
- lon = float(datalist[0])
- xIdx = int((lon - x0 + xdelt / 2) / xdelt)
- if xIdx < 0 or xIdx > xnum -1:
- continue
- yIdx = int((lat - y0 + ydelt / 2) / ydelt)
- if yIdx < 0 or yIdx > ynum - 1:
- continue
-
- gData.Data[yIdx, xIdx] += 1
- #---- Ouput grid data as Surfer ASCII data file
- outfn = dataDir + "test.grd"
- gData.SaveAsSurferASCIIFile(outfn)
- #---- Create shaded layer from the grid data
- aLS = LegendScheme(ShapeTypes.Polygon)
- aLS.ImportFromXMLFile(dataDir + "test.lgs")
- aLayer = DrawMeteoData.CreateShadedLayer(gData, aLS, "Lighting_Shaded", "Frequency")
- aLayer.IsMaskout = True
- mipy.MapDocument.ActiveMapFrame.AddLayer(aLayer)
- mipy.MapDocument.ActiveMapFrame.MoveLayer(aLayer, 0)
- print 'Finished!'
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2013-5-5
- # Purpose: Read and plot lighting data
- # Note: Sample
- #-----------------------------------------------------------
- #---- Import clr and classes
- import clr
- clr.AddReferenceByPartialName("System")
- clr.AddReferenceByPartialName("System.Drawing")
- from System import *
- from System.Drawing import *
- from System.Collections.Generic import *
- clr.AddReference("MeteoInfoC.dll")
- from MeteoInfoC import *
- from MeteoInfoC.Data.MapData import *
- from MeteoInfoC.Geoprocess import *
- from MeteoInfoC.Layer import *
- from MeteoInfoC.Shape import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Drawing import *
- import os.path
- #---- Create a point layer to plot lighting data
- print 'Create lighting point layer...'
- pLayer = VectorLayer(ShapeTypes.Point)
- pLayer.LayerName = "Lighting_Point"
- pLayer.Visible = True
- pLayer.EditAddField("ID", String)
- #---- Read lighting data file
- print 'Read lighting data file...'
- fn = "D:\\Temp\\ascii\\cunshuju.txt"
- tf = open(fn)
- id = 1
- for aline in tf:
- datalist = aline.split()
- lat = float(datalist[1])
- lon = float(datalist[0])
- aPS = PointShape()
- aPoint = PointD(lon, lat)
- aPS.Point = aPoint
- shapeNum = pLayer.ShapeNum
- if pLayer.EditInsertShape(aPS, shapeNum):
- pLayer.EditCellValue("ID", shapeNum, str(id))
-
- id += 1
- pLayer.UpdateLegendScheme(LegendType.SingleSymbol, "ID")
- for legend in pLayer.LegendScheme.LegendBreaks:
- legend.Style = PointStyle.Plus
- legend.DrawOutline = False
- legend.Color = Color.LightBlue
- legend.Size = 8
- mipy.MapDocument.ActiveMapFrame.AddLayer(pLayer)
- print 'Finished!'
|