| | |
| | | import com.dji.sample.patches.utils.ShapeFileUtil; |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | |
| | | import static com.dji.sample.patches.utils.FormatConversionUtil.getCentros; |
| | | import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert; |
| | | import static com.dji.sample.patches.utils.ZipUtil.*; |
| | | import static com.dji.sample.territory.utils.CoordinateSystemUtil.*; |
| | | import static org.locationtech.jts.io.WKTConstants.POLYGON; |
| | | |
| | | @Service |
| | | public class ShpToDataSourceServiceImpl implements ShpToDataSourceService { |
| | | |
| | | @Autowired |
| | | private ShpToDataSourceMapper mapper; |
| | | private ShpToDataSourceMapper shpToDataSourceMapper; |
| | | |
| | | @Autowired |
| | | private IWaylineFileService service; |
| | | private String head = POLYGON; |
| | | @Value("${patches.url.path.kmz.sourceDir}") |
| | | private String sourceDir; |
| | | @Value("${patches.url.path.kmz.destKMZFile}") |
| | | private String outkmz; |
| | | private MultipartFile multipartFile; |
| | | |
| | | String json; |
| | |
| | | @Autowired |
| | | private PatchesConfigPojo patchesConfigPojo; |
| | | |
| | | @Transactional |
| | | public MultipartFile insertGeo(MultipartFile file, String workspaceId, String waylineName, double airportLat, double airportLon) throws Exception { |
| | | List<LotInfo> list = new ArrayList<>(); |
| | | File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip()); |
| | |
| | | String[] points = end.split(","); |
| | | lotInfo.setXzb(Double.valueOf(points[0])); |
| | | lotInfo.setYzb(Double.valueOf(points[1])); |
| | | mapper.insert(lotInfo); |
| | | shpToDataSourceMapper.insert(lotInfo); |
| | | } |
| | | Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(list, airportLat, airportLon); |
| | | XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, list); |
| | | CreateWaylineFileUtils.createWaylineFile(xmlModel,patchesConfigPojo.getWaylines(),patchesConfigPojo.getWaylines(),patchesConfigPojo.getWaylines(),patchesConfigPojo.getWaylines()); |
| | | CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines()); |
| | | // 压缩文件夹中的内容 |
| | | String destKMZFile = outkmz + waylineName + ".kmz"; // 输出的KMZ文件路径 |
| | | zipFolder(sourceDir, destKMZFile); |
| | | String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径 |
| | | zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile); |
| | | multipartFile = convert(new File(destKMZFile)); |
| | | MultipartFileTOFileUtil.deleteFile(file1); |
| | | return multipartFile; |
| | | } |
| | | |
| | | @Transactional |
| | | public void savaInMysql(List<TbDkjbxxEntity> list, String workspaceId) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | LotInfo lotInfo = new LotInfo(); |
| | | lotInfo.setWorkspaceId(workspaceId); |
| | | lotInfo = dbConvertToEntity(list.get(i), workspaceId); |
| | | shpToDataSourceMapper.insert(lotInfo); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将SQlite数据库中DKJBXX对象转换为LotInfo对象。 |
| | | * |
| | | * @param file 需要转换的DKJBXX对象。 |
| | | * @return 返回一个构建好的LotInfo对象,包含从数据库实体中转换来的信息。 |
| | | */ |
| | | private LotInfo dbConvertToEntity(TbDkjbxxEntity file, String workspaceId) { |
| | | double[] coordinates = extractCoordinates(pointCGCStoWGS(file.getXzb(), file.getYzb())); |
| | | LotInfo.LotInfoBuilder builder = LotInfo.builder(); |
| | | builder.bsm(file.getBsm()) |
| | | .bz(file.getBz()) |
| | | .dkmj(file.getDkmj()) |
| | | .dkmc(file.getDkmc()) |
| | | .dkbh(file.getDkbh()) |
| | | .xmc(file.getXmc()) |
| | | .xzb(coordinates[0]) |
| | | .sfbhzdk(file.getSfbhzdk()) |
| | | .sjlx(file.getSjlx()) |
| | | .dkfw(poylonCGCStoWGS(file.getDkfw())) |
| | | .xzqdm(file.getXzqdm()) |
| | | .yzb(coordinates[1]) |
| | | .kzxx(file.getKzxx()) |
| | | .dklx(file.getDklx()) |
| | | .workspaceId(workspaceId) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | } |
| | | |
| | | |