一聚教程网:一个值得你收藏的教程网站

热门教程

Java MeteoInfo解析与绘图代码教程

时间:2022-06-29 02:07:46 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下Java MeteoInfo解析与绘图代码教程,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

MeteoDataInfo meteoDataInfo = new MeteoDataInfo();
        meteoDataInfo.openMICAPSData("D:解析数据cldascldasTEM20081000.000");
        GridData grid = meteoDataInfo.getGridData();
        //读取地图A
        VectorLayer scmap = MapDataManage.readMapFile_ShapeFile("C:UsersAdministratorDownloads好例子网_全国省、县界线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.setOutlineColor(Color.black);

        //读取色阶
        LegendScheme als = LgsUtil.readFromLgs("D:apache-tomcat-8.0.50alt色阶TEM.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(true);
        //抗锯齿
        layout.getActiveMapFrame().setMapView(view);
        view.setAntiAlias(true);
        layout.setAntiAlias(true);

        //根据视图计算视图的宽高
        Extent extent = view.getExtent();
        int size = 800;
        Rectangle rectangle = new Rectangle(size, (int) (size * 1D / extent.getWidth() * extent.getHeight()));

        //设置地图区域大小和外边距
        int width = rectangle.width;
        int left = 50;
        int height = rectangle.height;
        int right = 140;
        int top = 50;
        int bottom = 50;
        //设置页面边界
        layout.setPageBounds(new Rectangle(0, 0, width + left + right, height + top + bottom));
        //获取地图框
        MapFrame frame = layout.getActiveMapFrame();
        //设置布局边界
        frame.setLayoutBounds(new Rectangle(left, top, width, height));
        //绘制网格刻度线
        frame.setDrawGridLine(true);
        //设置网格间隔值
        frame.setGridXDelt(0.5);
        frame.setGridYDelt(0.5);
        //设置图例
        Rectangle bounds = layout.getActiveMapFrame().getLayoutBounds();
        LayoutLegend legend = layout.addLegend(bounds.x + bounds.width + 15, 0);
        legend.setLegendStyle(LegendStyles.Normal);
        legend.setTop(bounds.y + (bounds.height - legend.getHeight()) / 2);
        legend.setLegendLayer(layer);

        //导出
        layout.exportToPicture(PathUtil.getDeskPath()+"/1.png");

以上的方法只设定了刻度线和色阶,其他的也很简单,在下面说明一下

标题设定-放到设定好视图大小的后面
Rectangle bounds = layout.getActiveMapFrame().getLayoutBounds();
layout.addText(title, bounds.x + bounds.width / 2, y, 18);

热门栏目