小功能实现(十八)生成kml文件

本文介绍了如何使用JavaAPIforKml库生成KML文件,包括设置依赖、数据准备、创建Style、Placemark、LineString以及将输出流回前端的方法。
摘要由CSDN通过智能技术生成

引入依赖

        <!--解析、生成kml文件类-->
        <dependency>
            <groupId>de.micromata.jak</groupId>
            <artifactId>JavaAPIforKml</artifactId>
            <version>2.2.0</version>
        </dependency>

使用方法

注意:需要什么内容可自行添加

	//生成线路路径kml文件并返回流给前端
    public void exportCornerKml(List<Map<String,String>> cornerData, HttpServletResponse httpServletResponse) throws Exception{
        //数据准备
        OutputStream outputStream=null;

        Kml kml = KmlFactory.createKml();
        Document document = kml.createAndSetDocument().withName("").withId("").withVisibility(true).withOpen(true).withDescription("");

        // 创建Style
        Style style = document.createAndAddStyle().withId("normal_default");
        LineStyle lineStyle = style.createAndSetLineStyle().withColor("ffffffff").withWidth(1);

		// 创建Placemark
        Placemark placemark = document.createAndAddPlacemark();
        placemark.withName("和城-厉阳");
        placemark.withVisibility(true).withDescription("");
        placemark.withStyleUrl("#default");

        // 创建LineString
        LineString lineString = placemark.createAndSetLineString();
        lineString.withExtrude(false).withTessellate(true).withAltitudeMode(AltitudeMode.CLAMP_TO_GROUND);
        List<Coordinate> coordinates = new ArrayList<>();
        for (int i=0;i<cornerData.size();i++){
            coordinates.add(new Coordinate(Double.valueOf(cornerData.get(i).get("positionX")), Double.valueOf(cornerData.get(i).get("positionY")), 0.0));
        }
        lineString.setCoordinates(coordinates);

        //输出
        try {
            //获取表并写入
            outputStream=httpServletResponse.getOutputStream();
            httpServletResponse.setContentType("application/vnd.google-earth.kml+xml");
            httpServletResponse.setCharacterEncoding("utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("路径.kml", "UTF-8"));
            kml.marshal(outputStream);
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

生成文件

在这里插入图片描述

Google Earth KML文件生成工具是一种用于创建KML(Keyhole Markup Language)文件的工具。KML文件是一种用于地图可视化和地理信息展示的开放标准文件格式,它可以包含地图坐标、文本、图像、视频和其他地理信息。 Google Earth KML文件生成工具的主要功能是帮助用户创建和编辑KML文件,以实现地图数据的可视化和交互。使用该工具,用户可以通过简单的拖拽和点击操作来添加标记、路径、面和图层等元素,并指定它们的属性和样式。用户还可以导入和导出各种地图数据格式,如Shapefile、CSV和GPX,以便更方便地利用现有的地图数据。 KML文件生成工具通常会提供丰富的地图编辑功能,如测距、面积计算、缩放和旋转等,以支持用户更精细的地图设计。某些工具还具备高级功能,如卫星图像覆盖、地形生成和地理编码等,以满足用户更复杂的地理数据处理需求。 最重要的是,Google Earth KML文件生成工具往往与Google Earth软件无缝集成,可以直接将生成KML文件导入到Google Earth中进行可视化展示。Google Earth是一款功能强大的虚拟地球软件,用户可以在其中展现自己创建的地图数据,并享受全球范围的真实地貌、三维建筑和街景等视觉体验。 总之,Google Earth KML文件生成工具是一种便捷的工具,具备易用性和灵活性,可以帮助用户快速创建和编辑KML文件,并通过Google Earth进行地图数据的可视化展示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值