- 积分
- 55946
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2018-6-27 17:55 编辑
对于线对象的绘制每条线只能是固定的颜色,要实现用不同的颜色绘制一条线需要将该线分隔为多条线来绘制。这里示例读取HYSPLIT输出的气团轨迹数据,生成轨迹图层,在生成轨迹图层的时候每两个节点就生成一条线,并将轨迹节点的高度作为属性加入图层中。利用轨迹高度数据形成色标来显示轨迹,达到一条轨迹不同高度用不同颜色显示的目的。
脚本程序:
- #Read trajectory data file
- fn = 'E:/Trajectory/RYO-to Yaqiang/05060306'
- f = open(fn)
- line = f.readline()
- mfn = int(line.split()[0])
- for i in range(mfn):
- f.readline()
- line = f.readline()
- sn = int(line.split()[0])
- for i in range(sn):
- f.readline()
- f.readline()
- lons = []
- lats = []
- alts = []
- for line in f:
- dd = line.split()
- lat = float(dd[9])
- lon = float(dd[10])
- alt = float(dd[11])
- lats.append(lat)
- lons.append(lon)
- alts.append(alt)
- alts = array(alts)
- f.close()
- #Create trajectory layer
- layer = MILayer(shapetype='line')
- layer.addfield('Height', 'float')
- lon1 = lons[0]
- lat1 = lats[0]
- for j in range(1, len(lons)):
- lon = lons[j]
- lat = lats[j]
- alt = alts[j]
- layer.addshape([lon1,lon], [lat1, lat], [alt])
- lon1 = lon
- lat1 = lat
- levs = arange(0, 1000, 100)
- cols = makecolors(len(levs) + 1)
- ls = makesymbolspec('line', levels=levs, colors=cols, field='Height', size=2)
- #Plot
- axesm()
- geoshow('country', edgecolor=(204,204,204), facecolor=(250,235,252))
- geoshow(layer, symbolspec=ls)
- scatterm(lons[0], lats[0], size=8, facecolor='r')
- text(lons[0], lats[0]-1, 'Fukushima')
- colorbar(layer)
- title('Multi-color line')
- yticks(arange(30, 51, 5))
- xlim(130, 160)
- ylim(30, 50)
MeteoInfoLab有专门的函数读取HYSPLIT输出的轨迹文件并生成轨迹图层,脚本也可以写成这样:
- #Read trajectory data file
- fn = 'D:/Temp/HYSPLIT/05060306'
- f = addfile_hytraj(fn)
- layer = f.trajlayer()
- stlayer = f.trajsplayer()
- spoint = stlayer.shapes()[0].getPoint()
- slon = spoint.X
- slat = spoint.Y
- levs = arange(0, 1000, 100)
- cols = makecolors(len(levs) + 1)
- ls = makesymbolspec('line', levels=levs, colors=cols, field='Geometry_Z', size=2)
- #Plot
- axesm()
- geoshow('country', edgecolor=(204,204,204), facecolor=(250,235,252))
- geoshow(layer, symbolspec=ls)
- ss = makesymbolspec('point', {'marker':'S','size':12})
- geoshow(stlayer, symbolspec=ss)
- text(slon, slat-1, 'Fukushima')
- colorbar(layer)
- title('Multi-color line (Geometry_Z field)')
- yticks(arange(30, 51, 5))
- xlim(130, 160)
- ylim(30, 50)
|
|