爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 3666|回复: 7

脚本生成降水图背景如何透明

[复制链接]

新浪微博达人勋

发表于 2014-8-15 10:20:00 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
用脚本生成降水图,背景地图都设置透明,如何设置?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-15 10:46:26 | 显示全部楼层
如果背景图层是面图层,将其LegendScheme的每个LegendBreak的DrawFill设为False即可。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-15 10:50:27 | 显示全部楼层
感谢回复{:eb502:}{:eb502:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2014-8-15 10:56:26 | 显示全部楼层
我按照给的办法设置 ,还是有背景,背景是白色的,不是透明的,能给段代码例子吗?谢谢了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-15 11:12:33 | 显示全部楼层
La_respiration 发表于 2014-8-15 10:56
我按照给的办法设置 ,还是有背景,背景是白色的,不是透明的,能给段代码例子吗?谢谢了

你先把你的脚本贴出来看看吧
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-15 11:21:28 | 显示全部楼层
本帖最后由 La_respiration 于 2014-8-15 11:23 编辑

# coding=utf-8
#---- 引入类库

import clr
import time
import datetime
import System
clr.AddReferenceByPartialName("System")

clr.AddReferenceByPartialName("System.Windows.Forms")

clr.AddReferenceByPartialName("System.Drawing")
clr.AddReference('System.Data')
from System.Data import *
from System import *
from System.Windows.Forms import *

from System.Drawing import *

clr.AddReference("MeteoInfoC.dll")

from MeteoInfoC import *

from MeteoInfoC.Data.MapData import *
from MeteoInfoC.Data import *
from MeteoInfoC.Data.MeteoData import *

from MeteoInfoC.Layout import *

from MeteoInfoC.Legend import *

from MeteoInfoC.Projections import *

from MeteoInfoC.Shape import *

dt=DateTime.Now
if System.DateTime.Now.Hour>8 :
        print System.DateTime.Now.Hour
else:
        print "hello world"
print dt.AddDays(-1).ToString()


#---- 设置路径变量
#print myarr
BaseDir = "d:\\app\\"

MapDir = BaseDir + "Map\\"

LegendDir = BaseDir + "Legend\\"

DataDir = BaseDir + "Sample\\MICAPS\\"


#---- 打开图层

lnLayer = MapDataManage.OpenLayer(MapDir + "ln.shp")

lb = lnLayer.LegendScheme.LegendBreaks[0]

lb.Color = Color.Yellow

lb.OutlineColor = Color.Gray

lb.OutlineSize = 1

lb.DrawFill = False

countyLayer = MapDataManage.OpenLayer(MapDir + "countyname.shp")

lb = countyLayer.LegendScheme.LegendBreaks[0]

lb.Color = Color.Gray



countynameLayer = MapDataManage.OpenLayer(MapDir + "county.shp")

lb = countynameLayer.LegendScheme.LegendBreaks[0]

lb.Color = Color.Gray

lb.OutlineColor = Color.Red

lb.Size = 0

countynameLayer.LabelSet.FieldName = "NAME";

countynameLayer.LabelSet.LabelFont = Font("楷体", 12);
countynameLayer.LabelSet.LabelColor=Color.Red
countynameLayer.LabelSet.YOffset = 15;

countynameLayer.AddLabels();


#---- 创建MIApp类的对象

myApp = MIApp()

mapLayout = myApp.MapLayout

layoutMap = mapLayout.ActiveLayoutMap

mapFrame = layoutMap.MapFrame

mapView = mapFrame.MapView

#----设置Layout
mapLayout.SetPaperSize(650, 800)
#---- 添加图层

mapFrame.AddLayer(lnLayer)

mapFrame.AddLayer(countyLayer)

mapFrame.AddLayer(countynameLayer)


#---- mercator投影

projInfo = ProjectionInfo(" +proj=lonlat +ellps=WGS84 +datum=WGS84 +no_defs= +k=1")

mapView.ProjectLayers(projInfo)


#---- 按照经纬度范围缩放地图

mapView.ZoomToExtentLonLat(119,125.652801513672,37.6575018310547,43.77)

#---- 设置屏蔽图层(只绘制辽宁省内图形)

mapView.MaskOut.SetMaskLayer = True
mapView.MaskOut.MaskLayer = lnLayer.LayerName


#---- 设置ActiveLayoutMap(图层显示)

layoutMap.DrawGridLine = False

layoutMap.DrawNeatLine = False

layoutMap.DrawGridLabel = False

layoutMap.DrawGridTickLine = False
layoutMap.Left = -40
layoutMap.Top = -20
layoutMap.Width = 900
layoutMap.Height = 750


#---- 设置图形标题
#---- 220=left ,50=top
aText = mapLayout.AddText("Temp",150,30,"黑体",16)  


#print time.strftime('%H')

#---- 设置图例

aLegend = mapLayout.AddLegend(10,110)
aLegend.LegendStyle = LegendStyles.Bar_Vertical               

aLegend.DrawNeatLine = False
#aLegend.Height=100
#aLegend.Width=80
aLegend.Title = "降水量(毫米)"

aLegend.BackColor = Color.White

aLegend.Font = Font("微软雅黑", 12)



#---- 站点数据插值为格点数据的设置

interpSet = InterpolationSetting(118.9417,125.6528,38.7675,44.0831,500,500,"IDW_Radius",0.5,1)


#---- 设置图例

ls = LegendScheme(ShapeTypes.Polygon)

ls.ImportFromXMLFile(LegendDir + "1H.lgs")


ls2 = LegendScheme(ShapeTypes.Point)

ls2.ImportFromXMLFile(LegendDir + "null.lgs")

#---- 设置MeteoDataInfo

mid = MeteoDataInfo()

#---- 打开站点数据文件

mid.OpenLonLatData("d:\\data.txt")

#---- 获取降水量站点数据
stData = mid.GetStationData("Precipitation")
nameData=mid.GetStationInfoData()
#---- 将站点数据差值为格点数据
gData = DrawMeteoData.InterpolateData(stData, interpSet)
#---- 生成降水量图层
rainLayer = DrawMeteoData.CreateShadedLayer(gData, ls, "Precipitation", "Rain")
#templayer = DrawMeteoData.CreateContourLayer(gData,ls2,"Precipitation", "Rain2")
templayer=  DrawMeteoData.CreateSTInfoLayer(nameData,ls2,"Precipitation")
templayer.LabelSet.DrawLabels = True
templayer.LabelSet.DrawShadow = False
templayer.LabelSet.ShadowColor = Color.White
templayer.LabelSet.YOffset = 3
templayer.LabelSet.LabelColor = Color.Black
templayer.LabelSet.FieldName = "Precipitation"
templayer.LabelSet.ColorByLegend = True
templayer.LabelSet.DynamicContourLabel = True
templayer.LabelSet.LabelFont=Font("Arial",8)
templayer.AddLabels();
#rainLayer.LabelSet.FieldName="Precipitation"
#rainLayer.LabelSet.LabelFont=Font("Arial",8);
#rainLayer.AddLabels();
rainLayer.IsMaskout = True
templayer.IsMaskout=True
#---- 添加图层
mapFrame.AddLayer(rainLayer)
mapFrame.AddLayer(templayer)
print "Display finished"  
#---- 调整图层顺序(以避免压盖)
mapFrame.MoveLayerToBottom(rainLayer)  
#---- 设置标题名称
title = "降水分布"
aText.SetLabelText(title)  
#---- 设置图例名称
aLegend.Title = "降水量(毫米)"
#---- 绘制图形
mapLayout.PaintGraphics()
#---- 输出图形为文件
#mapLayout.ExportToPicture("E:\\Temp\\" + outFile)  

#---- 显示程序窗体(只是为了看效果,自动运行时不需要)
#myApp.SaveFigure(time.strftime('%H')+".png")

mapLayout.ExportToPicture("d:\\kkk.PNG",800)
#Application.Run(myApp)

#myApp.Show()
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-8-15 13:26:10 | 显示全部楼层
La_respiration 发表于 2014-8-15 11:21
# coding=utf-8
#---- 引入类库

增加下面的代码:
mapFrame.MapView.BackColor = Color.Transparent
mapLayout.PageBackColor = Color.Transparent
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-8-15 13:58:16 | 显示全部楼层
感谢,可以了
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表