MeteoInfo

MeteoInfo-Java分析与绘图教程(四)

上文大家说到,将地形图累加在色斑图上,但绝大多数全是通讯卫星制图,从现在起解读micaps数据信息制图,一样也是大量自定配备

最先大家分析micaps数据信息,将以前学得的物品拿过来制图

MeteoDataInfo meteoDataInfo = new MeteoDataInfo();
meteoDataInfo.openMICAPSData(\"D:\\\\分析数据信息\\\\cldas\\\\cldas\\\\TEM\\\\20081000.000\");
GridData grid = meteoDataInfo.getGridData();
//载入地形图A
VectorLayer scmap = MapDataManage.readMapFile_ShapeFile(\"E:\\\\shp\\\\四川\\\\四川省(3)_市界.shp\");
//叙述地形图边境线
PolygonBreak pb = (PolygonBreak) scmap.getLegendScheme().getLegendBreak(0);
//是不是设定添充
pb.setDrawFill(false);
//设定轮廊尺寸
pb.setOutlineSize(2f);
//设定轮廊色调
pb.setOutlineColor(Color.black);
//载入色彩平衡
LegendScheme als = LgsUtil.readFromLgs(\"D:\\\\apache-tomcat-8.0.50\\\\alt色彩平衡\\\\color\\\\ECMWF_HR\\\\TMP.lgs\");
//绘制图层
VectorLayer layer = DrawMeteoData.createShadedLayer(grid,als,\"\",\"\",true);
//创建视图
MapView view = new MapView();
//累加涂层
view.addLayer(layer);
view.addLayer(scmap);
MapLayout layout = new MapLayout();
//除去图型外框
layout.getActiveMapFrame().setDrawNeatLine(false);
//地区界限
Extent extent = view.getExtent();
//设定矩形框的宽和高
Rectangle bounds = new Rectangle(800, (int) (800 * 1D / extent.getWidth() * extent.getHeight()));
//设定地形图外框
layout.setPageBounds(new Rectangle(0, 0, bounds.width, bounds.height));
//设定网页页面外框
layout.getActiveMapFrame().setLayoutBounds(new Rectangle(0, 0, bounds.width, bounds.height));
layout.getActiveMapFrame().setMapView(view);
layout.exportToPicture(PathUtil.getDeskPath() \"/1.png\");

能看出去,micaps绘图和通讯卫星制图的差别只在分析数据信息openData的方式上,及其绘制图层createShadedLayer上,这一方式是制作色斑图(等价图),而createContourLayer是制作等值线,可以转换试一试

%title插图%num

自然具体应用的时候,图一定是不用这类的,比如四川的信息就应当只在四川地区展现,别的地区就为空缺,这儿就涉及到到了地形图激光切割,可以将涂层依照地形图界限激光切割掉

 

        MeteoDataInfo meteoDataInfo = new MeteoDataInfo();        meteoDataInfo.openMICAPSData(\"D:\\\\分析数据信息\\\\cldas\\\\cldas\\\\TEM\\\\20081000.000\");        GridData grid = meteoDataInfo.getGridData();        //载入地形图A        VectorLayer scmap = MapDataManage.readMapFile_ShapeFile(\"C:\\\\Users\\\\Administrator\\\\Downloads\\\\好例子网_全国省、县界限shp文件格式矢量图片(精准到县地区)\\\\全国省、县界限shp文件格式矢量图片(精准到县地区)\\\\sichuan.shp\");        //载入色彩平衡        LegendScheme als = LgsUtil.readFromLgs(\"D:\\\\apache-tomcat-8.0.50\\\\alt色彩平衡\\\\color\\\\ECMWF_HR\\\\TMP.lgs\");        //绘制图层        VectorLayer layer = DrawMeteoData.createShadedLayer(grid,als,\"\",\"\",true);        //创建视图        MapView view = new MapView();        layer = layer.clip(scmap);        //累加涂层        view.addLayer(layer);        MapLayout layout  = new MapLayout();        //除去图型外框        layout.getActiveMapFrame().setDrawNeatLine(false);        //地区界限        Extent extent = view.getExtent();        //设定矩形框的宽和高        Rectangle bounds = new Rectangle(800, (int) (800 * 1D / extent.getWidth() * extent.getHeight()));        //设定地形图外框        layout.setPageBounds(new Rectangle(0, 0, bounds.width, bounds.height));        //设定网页页面外框        layout.getActiveMapFrame().setLayoutBounds(new Rectangle(0, 0, bounds.width, bounds.height));        layout.getActiveMapFrame().setMapView(view);        //照片储放详细地址        String imagePath = PathUtil.getDeskPath() \"/1.png\";        layout.exportToPicture(imagePath);        //全透明解决        //载入照片        BufferedImage bi = ImageIO.read(new File(imagePath));        //数据转换        BufferedImage img = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);        Graphics2D g = (Graphics2D) img.getGraphics();        g.drawImage(bi, null, 0, 0);        //全透明解决        int alpha = 0;        for(int i=img.getMinY(); i<img.getHeight(); i  ){            for(int j=img.getMinX(); j<img.getWidth(); j  ){                int rgb = img.getRGB(j, i);                //全透明一部分不用解决                if(rgb < 0){                    int R = (rgb & 0xff0000) >> 16;                    int G = (rgb & 0xff00) >> 8;                    int B = (rgb & 0xff);                    //将乳白色去除                    Color color = Color.white;                    if(color.getRed() == R && color.getGreen() == G && color.getBlue() == B){                        alpha = 0;                    }                    else {                        alpha = 255;                    }                    rgb = (alpha << 24) | (rgb & 0x00ffffff);                    img.setRGB(j, i, rgb);                }            }        }        //释放出来資源        g.dispose();        ImageIO.write(img, \"png\", new File(imagePath));

最先大家必须注意到的是shp文件,假如不清楚怎么下载shp,可以立即去好例子网在线下载shp,现有的,很便捷,这一shp文件大家必须的是省界,文档里边不必有市的信息内容,不然没法截个边沿

第二点,大家将乳白色干了全透明解决,那样就变成了气候领域必须的3d贴图了,全透明解决可以集成化一个方式,我单纯性是因为便捷才那样写

%title插图%num

有一些时候大家必须在图上见到大城市界限,这时大家就可以在加一个市界涂层,将图堆叠上来

        MeteoDataInfo meteoDataInfo = new MeteoDataInfo();        meteoDataInfo.openMICAPSData(\"D:\\\\分析数据信息\\\\cldas\\\\cldas\\\\TEM\\\\20081000.000\");        GridData grid = meteoDataInfo.getGridData();        //载入地形图A        VectorLayer scmap = MapDataManage.readMapFile_ShapeFile(\"C:\\\\Users\\\\Administrator\\\\Downloads\\\\好例子网_全国省、县界限shp文件格式矢量图片(精准到县地区)\\\\全国省、县界限shp文件格式矢量图片(精准到县地区)\\\\sichuan.shp\");        //载入地形图B        VectorLayer qgmap = MapDataManage.readMapFile_ShapeFile(\"E:\\\\shp\\\\四川\\\\四川省(3)_市界.shp\");        //叙述地形图边境线        PolygonBreak pb = (PolygonBreak) qgmap.getLegendScheme().getLegendBreak(0);        //是不是设定添充        pb.setDrawFill(false);        //设定轮廊尺寸        pb.setOutlineSize(2f);        //设定轮廊色调        pb.setOutlineColor(Color.black);        //载入色彩平衡        LegendScheme als = LgsUtil.readFromLgs(\"D:\\\\apache-tomcat-8.0.50\\\\alt色彩平衡\\\\color\\\\ECMWF_HR\\\\TMP.lgs\");        //绘制图层        VectorLayer layer = DrawMeteoData.createShadedLayer(grid,als,\"\",\"\",true);        //创建视图        MapView view = new MapView();        layer = layer.clip(scmap);        //累加涂层        view.addLayer(layer);        view.addLayer(qgmap);        MapLayout layout  = new MapLayout();        //除去图型外框        layout.getActiveMapFrame().setDrawNeatLine(false);        //地区界限        Extent extent = view.getExtent();        //设定矩形框的宽和高        Rectangle bounds = new Rectangle(800, (int) (800 * 1D / extent.getWidth() * extent.getHeight()));        //设定地形图外框        layout.setPageBounds(new Rectangle(0, 0, bounds.width, bounds.height));        //设定网页页面外框        layout.getActiveMapFrame().setLayoutBounds(new Rectangle(0, 0, bounds.width, bounds.height));        layout.getActiveMapFrame().setMapView(view);        //照片储放详细地址        String imagePath = PathUtil.getDeskPath() \"/1.png\";        layout.exportToPicture(imagePath);        //全透明解决        //载入照片        BufferedImage bi = ImageIO.read(new File(imagePath));        //数据转换        BufferedImage img = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);        Graphics2D g = (Graphics2D) img.getGraphics();        g.drawImage(bi, null, 0, 0);        //全透明解决        int alpha = 0;        for(int i=img.getMinY(); i<img.getHeight(); i  ){            for(int j=img.getMinX(); j<img.getWidth(); j  ){                int rgb = img.getRGB(j, i);                //全透明一部分不用解决                if(rgb < 0){                    int R = (rgb & 0xff0000) >> 16;                    int G = (rgb & 0xff00) >> 8;                    int B = (rgb & 0xff);                    //将乳白色去除                    Color color = Color.white;                    if(color.getRed() == R && color.getGreen() == G && color.getBlue() == B){                        alpha = 0;                    }                    else {                        alpha = 255;                    }                    rgb = (alpha << 24) | (rgb & 0x00ffffff);                    img.setRGB(j, i, rgb);                }            }        }        //释放出来資源        g.dispose();        ImageIO.write(img, \"png\", new File(imagePath));

%title插图%num

填补java工具表明:

public static LegendScheme readFromLgs(String path) throws Exception {        LegendScheme scheme = new LegendScheme();