- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2014-11-29 23:45 编辑
MeteoInfo是一个GIS软件,矢量图层不仅有图形信息还有属性信息,这些属性信息可以很方便地标注在地图上,增加地图的可读性。气象上最常用的站点的标注,这里给出一个Demo脚本程序将中国省会城市名标注出来。正确运行此脚本需要下载最新的MeteoInfo Java 1.1.7R1版本,主要是为了Jython对中文的支持,详细信息见此贴:http://bbs.06climate.com/forum.php?mod=viewthread&tid=30872&extra=page%3D1。
矢量图层(VectorLayer)有一个属性是LabelSet类,里面有各类标注的设置参数,主要设置要标注的属性字段、字体、颜色、偏移等信息。
为了在脚本编辑器中正确显示中文,需要将其字体设置为中文字体,通过脚本编辑器窗体的“Options -> Set Font”菜单可以设置字体。脚本程序如下:
- # coding=utf-8#-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-11-26
- # Purpose: Label the point layer
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.global import Extent
- import os.path
- from java.awt import Color
- from java.awt import Font
- from java.awt import GraphicsEnvironment
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- mapDir = os.path.join(baseDir, 'map')
- #---- Create MapLayout object
- mapLayout = MapLayout()
- mapFrame = mapLayout.getActiveMapFrame()
- #---- Load layers
- print 'Load country layer...'
- fn = os.path.join(mapDir, 'country1.shp')
- countryLayer = MapDataManage.loadLayer(fn)
- lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setDrawFill(False)
- lb.setOutlineColor(Color.black)
- mapFrame.addLayer(countryLayer)
- print 'Load river layer...'
- fn = os.path.join(mapDir, 'rivers.shp')
- riverLayer = MapDataManage.loadLayer(fn)
- lb = riverLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setColor(Color.blue)
- lb.setSize(1.5)
- mapFrame.addLayer(riverLayer)
- print 'Load city layer...'
- cityLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'res1_4m.shp'))
- lb = cityLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setSize(6)
- lb.setColor(Color.red)
- labset = cityLayer.getLabelSet()
- labset.setFieldName('NAME')
- font = Font(u'楷体', Font.PLAIN, 16)
- labset.setLabelFont(font)
- labset.setYOffset(15)
- cityLayer.addLabels()
- mapFrame.addLayer(cityLayer)
- #---- Add title
- title = mapLayout.addText('MeteoInfo' + u'脚本示例', 350, 30, u'黑体', 16)
- #---- Zoom layout map
- print 'Zoom layout map...'
- mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))
- #---- Set mapframe
- mapFrame.setGridXDelt(10)
- mapFrame.setGridYDelt(10)
- mapLayout.paintGraphics()
- frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
运行结果如下:
|
|