各气象常用坐标投影在WEB页面出图的例子(JSP)

各气象常用坐标投影类(从Coordinate.java类继承)在WEB页面出图的JSP代码,包括经纬度坐标与屏幕坐标的相互转换。一般地,设置缩放系数为1.0时,各投影的缩放比例与Micaps1.0版相同(注:Micaps1.0启动时缺省的缩放比例为2.0)。

projection.jsp
01  <% page contentType= "image/jpeg; charset=gb2312"  %>
02 
03  <% page  import = "
04           cma.common.isoline.*,
05           cma.common.projection.*,
06           cma.micaps.diamond.*,
07           java.io.*,
08           java.awt.*,
09           java.awt.geom.*,
10           java.awt.image.*,
11           java.util.*,
12           java.text.*,
13           com.sun.image.codec.jpeg.*" %>
14 
15  <%
16       String  startDate   = String.valueOf ( new  Date ()) ;
17       //设置页面不缓存
18       response.setHeader ( "Pragma" , "No-cache" ) ;
19       response.setHeader ( "Cache-Control" , "no-cache" ) ;
20       response.setDateHeader ( "Expires" 0 ) ;
21       out.clear () ;
22       System.setProperty ( "java.awt.headless" "true" ) ;
23 
24       int              width   =  2400 ;
25       int              height  =  2000 ;
26       BufferedImage   image   =  new  BufferedImage ( width, height, BufferedImage.TYPE_3BYTE_BGR ) ;
27       Graphics2D      g       = image.createGraphics () ;
28       g.setColor ( new  Color ( 207 , 240 , 255 )) ; //Micaps1.0的背景色
29       //g.setColor(Color.white);
30       g.fillRect ( 0 0 , width, height ) ; //背景色填充
31       //Lambert       coordinate  = new Lambert(110.0, 30.0, 110.0, 35.0, width/2, height/2, 1.0);//兰勃特投影
32       //Linear        coordinate  = new Linear(110.0, 35.0,width/2, height/2, 1.0);//线性投影
33       //Mercator      coordinate  = new Mercator(110.0, 35.0,width/2, height/2, 1.0);//麦卡脱投影
34       //Polar         coordinate  = new Polar(109.40, 24.35, width/2, height/2, 1.0);//极坐标投影
35       Stereogram      coordinate  =  new  Stereogram ( 110.0 90.0 110.0 90.0 , width/ 2 , height/ 2 1.0 ) ; //BBQ极射赤面投影(南极是无效点)
36       //Stereogram    coordinate  = new Stereogram(110.0, -90.0, 110.0, -90.0, width/2, height/2, 1.0);//NBQ极射赤面投影(北极是无效点)
37 
38       Diamond09.drawBorderline ( g, Color.gray, coordinate,  "/path/to/ProvinceMap.dat" ) ; //画省界、国界、洲界
39       coordinate.drawGridLine ( g, null, Color.green,  10 10 ) ; //画经纬线
40 
41 
42       g.setColor ( Color.red ) ;
43       DecimalFormat   df  =  new  DecimalFormat ( "0.####" ) ;
44  //显示定位误差,与缩放比例有关。(由高分辨率的经纬度坐标获得低分辨率的屏幕坐标,再计算对应的经纬度坐标,必然会产生误差。)
45       for ( double  lon= 0.0 ;lon< 360.0 ;lon=lon+ 10.0 ) {
46           for ( double  lat=- 80.0 ;lat< 90.0 ;lat=lat+ 10.0 ) {
47               Point           pos0= coordinate.getPosition ( lon, lat ) ;
48               Point2D.Double  crd = coordinate.getCoordinate ( pos0.x, pos0.y ) ;
49               g.drawString ( df.format ( crd.x-lon ) + "," +df.format ( crd.y-lat ) , pos0.x, pos0.y ) ;
50           }
51       }
52 
53       g.dispose () ;
54 
55       //输出到浏览器
56  //  javax.imageio.ImageIO.write(image, "JPEG", response.getOutputStream());//这种方法得到的图片质量不高
57 
58       //输出到浏览器
59       ServletOutputStream sos     = response.getOutputStream () ;
60       JPEGImageEncoder    encoder = JPEGCodec.createJPEGEncoder ( sos ) ;
61 
62       //以下三行改进图片质量
63       JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam ( image ) ;
64       param.setQuality ( 1.0f false ) ;
65       encoder.setJPEGEncodeParam ( param ) ;
66 
67       encoder.encode ( image ) ;
68  %>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值