爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4116|回复: 1

MeteoInfo脚本教程(十五):地图投影

[复制链接]

新浪微博达人勋

发表于 2014-12-20 20:39:54 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 MeteoInfo 于 2014-12-20 20:44 编辑

MeteoInfo中地图投影的代码是从Proj4移植来的(Java版用的Proj4J库,代码已经放入了MeteoInfo库中,在软件lib目录中看不到Prj4J库的文件),投影之间的转换需要设置Proj4的投影字符串。比如Lambert Conformal投影表述为:



+proj=lcc   +lat_1=Latitude of first standard parallel
              +lat_2=Latitude of second standard parallel
              +lat_0=Latitude of false origin
              +lon_0=Longitude of false origin
              +x_0=False Origin Easting
              +y_0=False Origin Northing



具体的设置可以看Proj4的帮助文档,一些网页上也有描述,如: http://remotesensing.org/geotiff/proj_list/

投影时先建立投影字符串,然后创建ProjectionInfo类的对象,再用MapView类的projectLayers(ProjectionInfo projInfo)即可完成投影功能。

下面是两个示例脚本程序:
  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-11-22
  4. # Purpose: Read GrADS data and plot
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo
  12. from org.meteoinfo.data.meteodata import DrawMeteoData
  13. from org.meteoinfo.legend import LegendManage
  14. from org.meteoinfo.legend import LegendType
  15. from org.meteoinfo.legend import GridLabelPosition
  16. from org.meteoinfo.layout import LegendStyles
  17. from org.meteoinfo.shape import ShapeTypes
  18. from org.meteoinfo.projection import ProjectionInfo
  19. import os.path
  20. from java.awt import Color
  21. from javax.swing import JFrame

  22. #---- Set directories
  23. print 'Set directories...'
  24. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  25. dataDir = os.path.join(baseDir, 'sample/GrADS')
  26. mapDir = os.path.join(baseDir, 'map')
  27. figDir = 'D:/Temp/test'

  28. #---- Create MapLayout object
  29. mapLayout = MapLayout()
  30. mapFrame = mapLayout.getActiveMapFrame()

  31. #---- Load country layer
  32. print 'Load country layer...'
  33. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  34. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  35. lb.setDrawFill(False)
  36. lb.setOutlineColor(Color.blue)
  37. mapFrame.addLayer(countryLayer)

  38. #---- Open GrADS data
  39. print 'Open GrADS data...'
  40. mdi = MeteoDataInfo()
  41. mdi.openGrADSData(os.path.join(dataDir, 'model.ctl'))

  42. #---- Set time index
  43. mdi.setTimeIndex(2)

  44. #---- Get pressure grid data
  45. gdata = mdi.getGridData('PS')
  46. gdata.extendToGlobal()

  47. #---- Create legend scheme
  48. ls = LegendManage.createLegendSchemeFromGridData(gdata, LegendType.GraduatedColor, ShapeTypes.Polygon)

  49. #---- Create pressure shaded layer
  50. print 'Create pressure shaded layer...'
  51. pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True)

  52. #---- Add layer
  53. mapFrame.addLayer(pressLayer)

  54. #--- Move pressure layer to bottom
  55. mapFrame.moveLayer(pressLayer, 0)

  56. #---- Add title
  57. title = mapLayout.addText('MeteoInfo script demo - Projection', 350, 50, 'Arial', 16)

  58. #---- Project mapview
  59. print 'Project mapview...'
  60. projStr = '+proj=moll +lon_0=105'
  61. projInfo = ProjectionInfo(projStr)
  62. mapFrame.getMapView().projectLayers(projInfo)

  63. #---- Set mapframe
  64. mapFrame.setDrawNeatLine(False)
  65. mapFrame.setDrawGridLine(True)
  66. mapFrame.setDrawGridLabel(False)
  67. mapFrame.setGridLabelPosition(GridLabelPosition.All)
  68. mapFrame.setGridXDelt(30)
  69. mapFrame.setGridYDelt(30)

  70. #---- Add legend
  71. legend = mapLayout.addLegend(150, 420)
  72. legend.setLegendStyle(LegendStyles.Bar_Horizontal)
  73. legend.setLegendLayer(pressLayer)

  74. #---- Output figure
  75. print 'Output figure...'
  76. mapLayout.paintGraphics()
  77. #mapLayout.exportToPicture(os.path.join(figDir, 'pressure_test.png'))

  78. frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
  79. frame.add(mapLayout)
  80. frame.visible = True
  81. print 'Finished!'
  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-11-22
  4. # Purpose: Read GrADS data and plot
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  12. from org.meteoinfo.legend import LegendManage, LegendType, GridLabelPosition
  13. from org.meteoinfo.layout import LegendStyles
  14. from org.meteoinfo.shape import ShapeTypes
  15. from org.meteoinfo.projection import ProjectionInfo
  16. from org.meteoinfo.global import Extent
  17. import os.path
  18. from java.awt import Color
  19. from javax.swing import JFrame

  20. #---- Set directories
  21. print 'Set directories...'
  22. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  23. dataDir = os.path.join(baseDir, 'sample/GrADS')
  24. mapDir = os.path.join(baseDir, 'map')
  25. figDir = 'D:/Temp/test'

  26. #---- Create MapLayout object
  27. mapLayout = MapLayout()
  28. mapFrame = mapLayout.getActiveMapFrame()
  29. mapLayout.getActiveLayoutMap().setWidth(650)
  30. mapLayout.getActiveLayoutMap().setHeight(380)

  31. #---- Load country layer
  32. print 'Load country layer...'
  33. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  34. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  35. lb.setDrawFill(False)
  36. lb.setOutlineColor(Color.blue)
  37. mapFrame.addLayer(countryLayer)

  38. #---- Open GrADS data
  39. print 'Open GrADS data...'
  40. mdi = MeteoDataInfo()
  41. mdi.openGrADSData(os.path.join(dataDir, 'model.ctl'))

  42. #---- Set time index
  43. mdi.setTimeIndex(2)

  44. #---- Get pressure grid data
  45. gdata = mdi.getGridData('PS')
  46. gdata.extendToGlobal()

  47. #---- Create legend scheme
  48. ls = LegendManage.createLegendSchemeFromGridData(gdata, LegendType.GraduatedColor, ShapeTypes.Polygon)

  49. #---- Create pressure shaded layer
  50. print 'Create pressure shaded layer...'
  51. pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True)

  52. #---- Add layer
  53. mapFrame.addLayer(pressLayer)

  54. #--- Move pressure layer to bottom
  55. mapFrame.moveLayer(pressLayer, 0)

  56. #---- Add title
  57. title = mapLayout.addText('MeteoInfo script demo - Lambert projection', 350, 30, 'Arial', 16)

  58. #---- Project mapview
  59. print 'Project mapview...'
  60. projStr = '+proj=lcc +lat_1=30 +lat_2=60 +lat_0=0 +lon_0=110'
  61. projInfo = ProjectionInfo(projStr)
  62. mapFrame.getMapView().projectLayers(projInfo)
  63. extent = Extent(78, 130, 15, 53)
  64. mapFrame.getMapView().zoomToExtentLonLatEx(extent)

  65. #---- Set mapframe
  66. mapFrame.setDrawNeatLine(True)
  67. mapFrame.setDrawGridLine(True)
  68. mapFrame.setDrawGridLabel(True)
  69. mapFrame.setGridLabelPosition(GridLabelPosition.LeftBottom)
  70. mapFrame.setGridXDelt(10)
  71. mapFrame.setGridYDelt(10)

  72. #---- Add legend
  73. legend = mapLayout.addLegend(150, 440)
  74. legend.setLegendStyle(LegendStyles.Bar_Horizontal)
  75. legend.setLegendLayer(pressLayer)

  76. #---- Output figure
  77. print 'Output figure...'
  78. mapLayout.paintGraphics()
  79. #mapLayout.exportToPicture(os.path.join(figDir, 'pressure_test.png'))

  80. frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
  81. frame.add(mapLayout)
  82. frame.visible = True
  83. print 'Finished!'


Image00094.png
Image00095.png











本帖被以下淘专辑推荐:

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-31 15:49:25 | 显示全部楼层
正在学习中,谢谢楼主!
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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