- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
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)即可完成投影功能。
下面是两个示例脚本程序:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-11-22
- # Purpose: Read GrADS data and plot
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- from org.meteoinfo.data.meteodata import DrawMeteoData
- from org.meteoinfo.legend import LegendManage
- from org.meteoinfo.legend import LegendType
- from org.meteoinfo.legend import GridLabelPosition
- from org.meteoinfo.layout import LegendStyles
- from org.meteoinfo.shape import ShapeTypes
- from org.meteoinfo.projection import ProjectionInfo
- import os.path
- from java.awt import Color
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- dataDir = os.path.join(baseDir, 'sample/GrADS')
- mapDir = os.path.join(baseDir, 'map')
- figDir = 'D:/Temp/test'
- #---- Create MapLayout object
- mapLayout = MapLayout()
- mapFrame = mapLayout.getActiveMapFrame()
- #---- Load country layer
- print 'Load country layer...'
- countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
- lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setDrawFill(False)
- lb.setOutlineColor(Color.blue)
- mapFrame.addLayer(countryLayer)
- #---- Open GrADS data
- print 'Open GrADS data...'
- mdi = MeteoDataInfo()
- mdi.openGrADSData(os.path.join(dataDir, 'model.ctl'))
- #---- Set time index
- mdi.setTimeIndex(2)
- #---- Get pressure grid data
- gdata = mdi.getGridData('PS')
- gdata.extendToGlobal()
- #---- Create legend scheme
- ls = LegendManage.createLegendSchemeFromGridData(gdata, LegendType.GraduatedColor, ShapeTypes.Polygon)
- #---- Create pressure shaded layer
- print 'Create pressure shaded layer...'
- pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True)
- #---- Add layer
- mapFrame.addLayer(pressLayer)
- #--- Move pressure layer to bottom
- mapFrame.moveLayer(pressLayer, 0)
- #---- Add title
- title = mapLayout.addText('MeteoInfo script demo - Projection', 350, 50, 'Arial', 16)
- #---- Project mapview
- print 'Project mapview...'
- projStr = '+proj=moll +lon_0=105'
- projInfo = ProjectionInfo(projStr)
- mapFrame.getMapView().projectLayers(projInfo)
- #---- Set mapframe
- mapFrame.setDrawNeatLine(False)
- mapFrame.setDrawGridLine(True)
- mapFrame.setDrawGridLabel(False)
- mapFrame.setGridLabelPosition(GridLabelPosition.All)
- mapFrame.setGridXDelt(30)
- mapFrame.setGridYDelt(30)
- #---- Add legend
- legend = mapLayout.addLegend(150, 420)
- legend.setLegendStyle(LegendStyles.Bar_Horizontal)
- legend.setLegendLayer(pressLayer)
- #---- Output figure
- print 'Output figure...'
- mapLayout.paintGraphics()
- #mapLayout.exportToPicture(os.path.join(figDir, 'pressure_test.png'))
- frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-11-22
- # Purpose: Read GrADS data and plot
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
- from org.meteoinfo.legend import LegendManage, LegendType, GridLabelPosition
- from org.meteoinfo.layout import LegendStyles
- from org.meteoinfo.shape import ShapeTypes
- from org.meteoinfo.projection import ProjectionInfo
- from org.meteoinfo.global import Extent
- import os.path
- from java.awt import Color
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- dataDir = os.path.join(baseDir, 'sample/GrADS')
- mapDir = os.path.join(baseDir, 'map')
- figDir = 'D:/Temp/test'
- #---- Create MapLayout object
- mapLayout = MapLayout()
- mapFrame = mapLayout.getActiveMapFrame()
- mapLayout.getActiveLayoutMap().setWidth(650)
- mapLayout.getActiveLayoutMap().setHeight(380)
- #---- Load country layer
- print 'Load country layer...'
- countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
- lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setDrawFill(False)
- lb.setOutlineColor(Color.blue)
- mapFrame.addLayer(countryLayer)
- #---- Open GrADS data
- print 'Open GrADS data...'
- mdi = MeteoDataInfo()
- mdi.openGrADSData(os.path.join(dataDir, 'model.ctl'))
- #---- Set time index
- mdi.setTimeIndex(2)
- #---- Get pressure grid data
- gdata = mdi.getGridData('PS')
- gdata.extendToGlobal()
- #---- Create legend scheme
- ls = LegendManage.createLegendSchemeFromGridData(gdata, LegendType.GraduatedColor, ShapeTypes.Polygon)
- #---- Create pressure shaded layer
- print 'Create pressure shaded layer...'
- pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True)
- #---- Add layer
- mapFrame.addLayer(pressLayer)
- #--- Move pressure layer to bottom
- mapFrame.moveLayer(pressLayer, 0)
- #---- Add title
- title = mapLayout.addText('MeteoInfo script demo - Lambert projection', 350, 30, 'Arial', 16)
- #---- Project mapview
- print 'Project mapview...'
- projStr = '+proj=lcc +lat_1=30 +lat_2=60 +lat_0=0 +lon_0=110'
- projInfo = ProjectionInfo(projStr)
- mapFrame.getMapView().projectLayers(projInfo)
- extent = Extent(78, 130, 15, 53)
- mapFrame.getMapView().zoomToExtentLonLatEx(extent)
- #---- Set mapframe
- mapFrame.setDrawNeatLine(True)
- mapFrame.setDrawGridLine(True)
- mapFrame.setDrawGridLabel(True)
- mapFrame.setGridLabelPosition(GridLabelPosition.LeftBottom)
- mapFrame.setGridXDelt(10)
- mapFrame.setGridYDelt(10)
- #---- Add legend
- legend = mapLayout.addLegend(150, 440)
- legend.setLegendStyle(LegendStyles.Bar_Horizontal)
- legend.setLegendLayer(pressLayer)
- #---- Output figure
- print 'Output figure...'
- mapLayout.paintGraphics()
- #mapLayout.exportToPicture(os.path.join(figDir, 'pressure_test.png'))
- frame = JFrame('MeteoInfo Script Sample', size = (750, 530))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finished!'
|
|