4 files modified
1 files added
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public static Coordinate [] getRoutePointOrder(List<LotInfo> list) { |
| | | public static Coordinate[] getRoutePointOrder(List<LotInfo> list, double airportLat, double airportLon) { |
| | | List<Coordinate> centros = new ArrayList<>(); |
| | | List<List<Coordinate>> extremePoints = new ArrayList<>(); |
| | | Map<Coordinate,List<Coordinate>> points = new HashMap<>(); |
| | | Map<Coordinate, List<Coordinate>> points = new HashMap<>(); |
| | | list.forEach(patche -> { |
| | | String wkt = patche.getDkfw(); |
| | | // 解析WKT字符串为多边形 |
| | |
| | | // 开始封装图斑4个航线 |
| | | List<Coordinate> coordinatePointList = getExtremePoints(polygon); |
| | | extremePoints.add(coordinatePointList); |
| | | points.put(coordinateCentro,coordinatePointList); |
| | | points.put(coordinateCentro, coordinatePointList); |
| | | |
| | | }); |
| | | |
| | | // 开始排序 |
| | | // 机场经纬度 |
| | | double airportLat = 28.624514734; // 机场纬度 |
| | | double airportLon = 115.856725497; // 机场经度 |
| | | Coordinate [] coordinates = new Coordinate[centros.size() + 1]; |
| | | Coordinate[] coordinates = new Coordinate[centros.size() + 1]; |
| | | List<Coordinate> coordinateList = new ArrayList<>(); |
| | | coordinates[0] = new Coordinate(airportLon, airportLat); //第一个为机场经纬度 |
| | | coordinateList.add(new Coordinate(airportLon, airportLat)); //第一个为机场经纬度) |
| | | for (int i = 1; i < centros.size() + 1; i++) { |
| | | coordinates[i] = centros.get(i-1); |
| | | coordinateList.add(centros.get(i-1)); |
| | | coordinates[i] = centros.get(i - 1); |
| | | coordinateList.add(centros.get(i - 1)); |
| | | } |
| | | |
| | | // 对中心坐标数组进行排序 |
| | | Coordinate[] retCoordinate = new Coordinate[coordinateList.size()]; |
| | | Coordinate[] sortedCoordinates = DistanceCalculator.sortByDistance(coordinateList, airportLat, airportLon, 0,retCoordinate); |
| | | Coordinate[] sortedCoordinates = DistanceCalculator.sortByDistance(coordinateList, airportLat, airportLon, 0, retCoordinate); |
| | | |
| | | // 开始拼接图斑点位--按中心坐标数组排序顺序 |
| | | // 长度-3第一个起点只有一个点位 |
| | |
| | | return retc; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | //测试 |
| | | List<LotInfo> list = new ArrayList<>(); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.866465564947 28.6344502965542, 115.86425430209 28.6357383285408, 115.864551734716 28.633120921433, 115.866977149064 28.6338435339976, 115.866465564947 28.6344502965542))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.864006690605 28.6202713913694, 115.86002109342 28.6162025130492, 115.866374254306 28.6142037658042, 115.865912044006 28.6172001020759, 115.864006690605 28.6202713913694))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.839366933455 28.6161999317332, 115.841288489469 28.6160843601496, 115.840931570318 28.6181544912247, 115.838147600941 28.618654178036, 115.839366933455 28.6161999317332))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.857499052697 28.6784702230642, 115.859109158101 28.6762273976226, 115.863677723232 28.6766081113836, 115.862154868188 28.6790827508297, 115.857499052697 28.6784702230642))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.834974056705 28.6659171428962, 115.833760531592 28.6634960413229, 115.832422084777 28.6624550271329, 115.829745191145 28.6631986086972, 115.831232354274 28.6608191476914, 115.833314382654 28.6603729987527, 115.835545127347 28.6618601618814, 115.837032290475 28.6639421902615, 115.834974056705 28.6659171428962))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.885622116006 28.5766308429787, 115.883936664461 28.5771582901683, 115.883365593819 28.5752547213636, 115.883555950699 28.5740174016407, 115.88365112914 28.5724945465969, 115.885364341064 28.5721138328361, 115.886696839227 28.5725897250371, 115.887458266749 28.5736366878797, 115.886792017668 28.5753498998039, 115.885622116006 28.5766308429787))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.857644341395 28.5750890964568, 115.857572957565 28.5729475815515, 115.858429563527 28.5728761977213, 115.859072017998 28.5738041875136, 115.859072017998 28.5748035611361, 115.857644341395 28.5750890964568))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.912181587649 28.6231542087745, 115.912181587649 28.6215123806805, 115.915893546818 28.6212268453598, 115.916036314478 28.6231542087745, 115.912181587649 28.6231542087745))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.842039042965 28.6314426646115, 115.840992080122 28.631252307731, 115.842324578286 28.6305860586493, 115.843181184248 28.6305860586493, 115.84403779021 28.6304908802091, 115.84394261177 28.6317281999322, 115.842039042965 28.6314426646115))").build()); |
| | | list.add(LotInfo.builder().dkfw("POLYGON((115.807011889796 28.623935465138, 115.805869748513 28.6224126100944, 115.810247956764 28.6220318963334, 115.809581707682 28.623935465138, 115.807011889796 28.623935465138))").build()); |
| | | |
| | | getRoutePointOrder(list); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.utils.GeoToolsUtil; |
| | | import com.dji.sample.patches.xml.mode.*; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | @RequestMapping(value = "/xml") |
| | | @Slf4j |
| | | public class XMLController { |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | |
| | | // list.add(LotInfo.builder().dkbh("dkbh09").dkfw("POLYGON((115.842039042965 28.6314426646115, 115.840992080122 28.631252307731, 115.842324578286 28.6305860586493, 115.843181184248 28.6305860586493, 115.84403779021 28.6304908802091, 115.84394261177 28.6317281999322, 115.842039042965 28.6314426646115))").build()); |
| | | // list.add(LotInfo.builder().dkbh("dkbh10").dkfw("POLYGON((115.807011889796 28.623935465138, 115.805869748513 28.6224126100944, 115.810247956764 28.6220318963334, 115.809581707682 28.623935465138, 115.807011889796 28.623935465138))").build()); |
| | | |
| | | // 机场经纬度 |
| | | double airportLat = 28.624514734; // 机场纬度 |
| | | double airportLon = 115.856725497; // 机场经度 |
| | | // 解析图斑生成航点,按顺序返回 |
| | | Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(list, airportLat, airportLon); |
| | | |
| | | Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(list); |
| | | // 初始化模板对象 |
| | | XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, list); |
| | | |
| | | XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates,list); |
| | | //生成航线文件 |
| | | CreateWaylineFileUtils.createWaylineFile(xmlModel); |
| | | |
| | | |
| | | |
| | | |
| | | xml2XmlDoc(xmlModel, "src\\main\\resources\\template\\template.xml", "src\\main\\resources\\template\\wpmz\\template.kml"); |
| | | xml2XmlDoc(xmlModel, "src\\main\\resources\\template\\waylines.xml", "src\\main\\resources\\template\\wpmz\\waylines.wpml"); |
| | | } |
| | | |
| | | /** |
| | | * 将xml模板转换为newxml |
| | | * |
| | | * @param model 需要填充到模板的数据 |
| | | * @param templetFilePath 模板文件路径 |
| | | * @param targetFilePath 目标文件保存路径 |
| | | */ |
| | | public static void xml2XmlDoc(XMLTemplateModel model, String templetFilePath, String targetFilePath) { |
| | | Writer out = null; |
| | | try { |
| | | // 将模板文件路径拆分为文件夹路径和文件名称 |
| | | String tempLetDir = templetFilePath.substring(0, templetFilePath.lastIndexOf("\\")); |
| | | // 注意:templetFilePath.lastIndexOf("/")中,有的文件分隔符为:\ 要注意文件路径的分隔符 |
| | | String templetName = templetFilePath.substring(templetFilePath.lastIndexOf("\\") + 1); |
| | | // 将目标文件保存路径拆分为文件夹路径和文件名称 |
| | | String targetDir = targetFilePath.substring(0, targetFilePath.lastIndexOf("\\")); |
| | | String targetName = targetFilePath.substring(targetFilePath.lastIndexOf("\\") + 1); |
| | | Configuration configuration = new Configuration(); |
| | | configuration.setDefaultEncoding(String.valueOf(StandardCharsets.UTF_8)); |
| | | // 如果目标文件目录不存在创建 |
| | | File file = new File(targetDir); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | //加载模板数据(从文件路径中获取文件) |
| | | configuration.setDirectoryForTemplateLoading(new File(tempLetDir)); |
| | | //获取模板实例 |
| | | Template template = configuration.getTemplate(templetName); |
| | | File outFile = new File(targetDir + File.separator + targetName); |
| | | //模板和数据模型合并生成文件 |
| | | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8)); |
| | | //生成文件 |
| | | template.process(model, out); |
| | | out.flush(); |
| | | out.close(); |
| | | } catch (Exception e) { |
| | | log.error("write xml failed:", e); |
| | | } finally { |
| | | if (out != null) { |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e) { |
| | | log.error("close out failed:", e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | import com.dji.sample.patches.xml.mode.share.ActionMode; |
| | | import com.dji.sample.patches.xml.mode.share.ActionTrigger; |
| | | import com.dji.sample.patches.xml.mode.share.action.utils.*; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | @Data |
| | | @Builder |
| | | @Slf4j |
| | | public class XMLTemplateModel { |
| | | |
| | | private String author = "aix"; |
| | |
| | | |
| | | private Folder folder; |
| | | |
| | | /** |
| | | * 初始化模板对象 |
| | | * @param coordinates |
| | | * @param lotInfos |
| | | * @return |
| | | */ |
| | | public static XMLTemplateModel init(Coordinate[] coordinates,List<LotInfo> lotInfos) { |
| | | |
| | | Folder folder = FolderUtils.setFloder(); |
| New file |
| | |
| | | package com.dji.sample.patches.xml.utils; |
| | | |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | | * @DESCRIPTION: |
| | | * @USER: aix |
| | | * @DATE: 2024/4/3 9:58 |
| | | */ |
| | | @Slf4j |
| | | public class CreateWaylineFileUtils { |
| | | |
| | | /** |
| | | * 生成航线文件 |
| | | * @param xmlModel |
| | | */ |
| | | public static void createWaylineFile(XMLTemplateModel xmlModel) { |
| | | xml2XmlDoc(xmlModel, "src\\main\\resources\\template\\template.xml", "src\\main\\resources\\template\\wpmz\\template.kml"); |
| | | xml2XmlDoc(xmlModel, "src\\main\\resources\\template\\waylines.xml", "src\\main\\resources\\template\\wpmz\\waylines.wpml"); |
| | | } |
| | | |
| | | /** |
| | | * 将xml模板转换为newxml |
| | | * |
| | | * @param model 需要填充到模板的数据 |
| | | * @param templetFilePath 模板文件路径 |
| | | * @param targetFilePath 目标文件保存路径 |
| | | */ |
| | | private static void xml2XmlDoc(XMLTemplateModel model, String templetFilePath, String targetFilePath) { |
| | | Writer out = null; |
| | | try { |
| | | // 将模板文件路径拆分为文件夹路径和文件名称 |
| | | String tempLetDir = templetFilePath.substring(0, templetFilePath.lastIndexOf("\\")); |
| | | // 注意:templetFilePath.lastIndexOf("/")中,有的文件分隔符为:\ 要注意文件路径的分隔符 |
| | | String templetName = templetFilePath.substring(templetFilePath.lastIndexOf("\\") + 1); |
| | | // 将目标文件保存路径拆分为文件夹路径和文件名称 |
| | | String targetDir = targetFilePath.substring(0, targetFilePath.lastIndexOf("\\")); |
| | | String targetName = targetFilePath.substring(targetFilePath.lastIndexOf("\\") + 1); |
| | | Configuration configuration = new Configuration(); |
| | | configuration.setDefaultEncoding(String.valueOf(StandardCharsets.UTF_8)); |
| | | // 如果目标文件目录不存在创建 |
| | | File file = new File(targetDir); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | //加载模板数据(从文件路径中获取文件) |
| | | configuration.setDirectoryForTemplateLoading(new File(tempLetDir)); |
| | | //获取模板实例 |
| | | Template template = configuration.getTemplate(templetName); |
| | | File outFile = new File(targetDir + File.separator + targetName); |
| | | //模板和数据模型合并生成文件 |
| | | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8)); |
| | | //生成文件 |
| | | template.process(model, out); |
| | | out.flush(); |
| | | out.close(); |
| | | } catch (Exception e) { |
| | | log.error("write xml failed:", e); |
| | | } finally { |
| | | if (out != null) { |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e) { |
| | | log.error("close out failed:", e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | <Document> |
| | | <!-- 步骤1:实现文件创建信息 --> |
| | | <wpml:author>Aix</wpml:author> |
| | | <wpml:createTime>1711960016175</wpml:createTime> |
| | | <wpml:updateTime>1711960016175</wpml:updateTime> |
| | | <wpml:createTime>1712109755073</wpml:createTime> |
| | | <wpml:updateTime>1712109755073</wpml:updateTime> |
| | | <!-- 步骤2:设置任务配置 --> |
| | | <wpml:missionConfig> |
| | | <wpml:flyToWaylineMode>safely</wpml:flyToWaylineMode> |