| | |
| | | package com.se.simu.controller; |
| | | |
| | | import com.se.simu.domain.vo.R; |
| | | import com.se.simu.utils.FileUtil; |
| | | import com.se.simu.utils.ZipUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("1-ä¸ä¼ å个shpæä»¶") |
| | | @PostMapping("/uploadShp") |
| | | public R<Object> uploadShp(@RequestParam("file") MultipartFile file) throws IOException { |
| | | if (file.isEmpty()) { |
| | | return success("æä»¶ä¸è½ä¸ºç©º"); |
| | | } |
| | | // è·åå½åå¹´ææ¥ |
| | | String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
| | | String targetDir = Paths.get(uploadedFolder, date).toString(); |
| | | log.info("ç®æ ç®å½: {}", targetDir); |
| | | createDirectoriesIfNotExists(targetDir); |
| | | try { |
| | | // æä»¶å°åå
¨ç§° |
| | | Path filePath = Paths.get(targetDir, file.getOriginalFilename()); |
| | | // æä»¶å |
| | | file.transferTo(filePath); |
| | | ZipUtils.unzip(targetDir + "\\" + file.getOriginalFilename(),targetDir); |
| | | File zipfile=new File(targetDir + "\\" + file.getOriginalFilename()); |
| | | zipfile.delete(); |
| | | return success(FileUtil.getShpPath(targetDir), "æä»¶ä¸ä¼ æå"); |
| | | } catch (IOException e) { |
| | | log.error("æä»¶ä¸ä¼ 失败", e); |
| | | return fail("æä»¶ä¸ä¼ 失败"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("1-ä¸ä¼ å个æä»¶") |
| | | @PostMapping("/uploads") |
| | |
| | | return fail("è§£æèå´æä»¶å¤±è´¥ï¼éæ©èå´ä¸è½ä¸ºç©ºï¼è¯·éæ°éæ©æä»¶ï¼", false); |
| | | } |
| | | } |
| | | |
| | | JSONArray jsonArray = new JSONArray(); |
| | | String stationFile = vo.getStationFile(); |
| | | log.info("ç«ç¹æä»¶shpå°åï¼{}", stationFile); |
| | | try { |
| | |
| | | return fail("ç«ç¹æä»¶shpå°åä¸è½ä¸ºç©º", false); |
| | | } |
| | | // 1 读åshpæä»¶ï¼è·åç«ç¹åæ å¼ |
| | | JSONArray jsonArray = ShpToolUtils.readShpGetLocal(stationFile); |
| | | jsonArray = ShpToolUtils.readShpGetLocal(stationFile); |
| | | System.out.println("jsonArray = " + jsonArray); |
| | | } catch (Exception e) { |
| | | log.error("è§£æç«ç¹æä»¶shp失败"); |
| | |
| | | |
| | | String stationRainFile = vo.getStationRainFile(); |
| | | log.info("ç«ç¹é¨éCSVæä»¶å°åï¼{}", floodFile); |
| | | JSONArray array = new JSONArray(); |
| | | try { |
| | | // 夿å°åä¸ä¸ºç©º |
| | | if (StringUtils.isEmpty(stationRainFile)) { |
| | |
| | | // åå»ºè¡¨å æ¶é´æ³ |
| | | String tableName = "station_rain_" + System.currentTimeMillis(); |
| | | // 1 读åCSV æä»¶ |
| | | CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | array = CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | // è·åä»¿çæ¶é´ duration |
| | | Integer duration = CsvToSQLiteUtils.getDuration(tableName); |
| | | log.info("ä»¿çæ¶é´ duration = {}", duration); |
| | |
| | | return fail("鲿±èå´ä¸è½ä¸ºç©º", false); |
| | | } |
| | | } |
| | | //todo ç»è£
cityjson |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("shp", jsonArray); |
| | | jsonObject.put("csv", array); |
| | | // å¼å§æ¨¡æè®¡ç® |
| | | boolean flag = simuFilesService.createByfiles(vo); |
| | | return success(flag, flag ? "æå" : "失败"); |
| | |
| | | package com.se.simu.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import org.apache.commons.csv.CSVFormat; |
| | | import org.apache.commons.csv.CSVRecord; |
| | | |
| | |
| | | * @param stationRainFile Station Rain æä»¶ |
| | | * @param tableName 表åç§° |
| | | */ |
| | | public static void readCsvSaveLocal(String stationRainFile, String tableName) { |
| | | public static JSONArray readCsvSaveLocal(String stationRainFile, String tableName) { |
| | | // 1. å建SQLiteæ°æ®åºè¿æ¥ |
| | | JSONArray array=null; |
| | | try (Connection conn = DriverManager.getConnection("jdbc:sqlite:rainfall.db")) { |
| | | if (conn != null) { |
| | | // 2. å建表ï¼å¦æä¸åå¨ï¼ |
| | |
| | | // 4. å¼å§äºå¡ |
| | | conn.setAutoCommit(false); |
| | | // 5. 读åCSVæä»¶å¹¶æå
¥æ°æ® |
| | | readCsvAndInsertDatas(stationRainFile, conn, tableName); |
| | | array = readCsvAndInsertDatas(stationRainFile, conn, tableName); |
| | | // 6. æäº¤äºå¡ |
| | | conn.commit(); |
| | | System.out.println("æ°æ®æåæå
¥å°SQLiteæ°æ®åºï¼"); |
| | |
| | | } catch (SQLException e) { |
| | | System.err.println("SQLiteè¿æ¥å¤±è´¥: " + e.getMessage()); |
| | | } |
| | | return array; |
| | | } |
| | | |
| | | |
| | | private static void readCsvAndInsertDatas(String csvFilePath, Connection conn, String tableName) { |
| | | private static JSONArray readCsvAndInsertDatas(String csvFilePath, Connection conn, String tableName) { |
| | | // ä½¿ç¨ Apache Commons CSV 读åCSVæä»¶ |
| | | JSONArray array = new JSONArray(); |
| | | try (Reader reader = new InputStreamReader(Files.newInputStream(Paths.get(csvFilePath)), "GBK")) { |
| | | Iterable<CSVRecord> records = CSVFormat.DEFAULT |
| | | .withHeader("é¨éç«", "éé¨é", "ç»åº¦", "纬度", "datatime") |
| | |
| | | .parse(reader); |
| | | |
| | | String insertDataSql = "INSERT INTO " + tableName + " (station_name, rainfall, longitude, latitude, datetime) VALUES (?, ?, ?, ?, ?);"; |
| | | |
| | | try (PreparedStatement pstmt = conn.prepareStatement(insertDataSql)) { |
| | | // æ¹éå¤§å° |
| | | int batchSize = 1000; |
| | |
| | | pstmt.setDouble(3, longitude); |
| | | pstmt.setDouble(4, latitude); |
| | | pstmt.setString(5, datetime); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("stationName", stationName); |
| | | jsonObject.put("rainfall", rainfall); |
| | | jsonObject.put("longitude", longitude); |
| | | jsonObject.put("latitude", latitude); |
| | | jsonObject.put("datetime", datetime); |
| | | array.add(jsonObject); |
| | | // æ·»å å°æ¹å¤ç |
| | | pstmt.addBatch(); |
| | | count++; |
| | |
| | | } catch (IOException e) { |
| | | System.err.println("读åCSVææå
¥æ°æ®æ¶åºé: " + e.getMessage()); |
| | | } |
| | | return array; |
| | | } |
| | | |
| | | /** |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.simu.utils; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | public class FileUtil { |
| | | public static String getShpPath(String dirPath) { |
| | | File root = new File(dirPath); |
| | | List<String> filePath=new ArrayList<>(); |
| | | traverse(root,filePath); |
| | | for (String path:filePath |
| | | ) { |
| | | if (path.endsWith(".shp")){ |
| | | return path; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void traverse(File dir,List<String> filePath) { |
| | | File[] files = dir.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | if (file.isDirectory()) { |
| | | traverse(file, filePath); |
| | | } else { |
| | | filePath.add(file.getAbsolutePath()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | import java.util.List; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | import java.util.zip.ZipInputStream; |
| | | |
| | | /** |
| | | * zip |
| | |
| | | // è¿éä¹å¯ä»¥éæ©æå°ç®å½è·¯å¾ |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.out.println("GBKç¼ç "); |
| | | try { |
| | | File file = ZipUtil.unzip(zipFilePath, destDir, CharsetUtil.CHARSET_GBK); |
| | | File[] file1 = file.listFiles(); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "type": "CityJSON_Extension", |
| | | "name": "PipeLine", |
| | | "uri": "http://www.smartearth.cn/extension.schema. PipeLine.json", |
| | | "version": "1.0.0", |
| | | "description": "Extension for PipeLine model", |
| | | "extraCityObjects": { |
| | | "+PipeLine": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "../cityobjects.schema.json#/_AbstractCityObject" |
| | | }, |
| | | { |
| | | "properties": { |
| | | "type": { |
| | | "enum": [ |
| | | "+PipeLine" |
| | | ] |
| | | }, |
| | | "topLevel": { |
| | | "type": "boolean" |
| | | }, |
| | | "attributes": { |
| | | "type": "object", |
| | | "properties": { |
| | | "function": { |
| | | "type": "string" |
| | | }, |
| | | "bs": { |
| | | "type": "object", |
| | | "description": "æ è¯", |
| | | "properties": { |
| | | "qqwybs": { |
| | | "type": "string", |
| | | "description": "å
¨çå¯ä¸ç¼ç " |
| | | }, |
| | | "hydm": { |
| | | "type": "string", |
| | | "description": "è¡ä¸ä»£ç " |
| | | }, |
| | | "fldm": { |
| | | "type": "string", |
| | | "description": "å类代ç " |
| | | }, |
| | | "mc": { |
| | | "type": "string", |
| | | "description": "åç§°" |
| | | } |
| | | } |
| | | }, |
| | | "zt": { |
| | | "type": "object", |
| | | "description": "ç¶æ", |
| | | "properties": { |
| | | "ztgb": { |
| | | "type": "string", |
| | | "description": "ç¶ææ¹å" |
| | | } |
| | | } |
| | | }, |
| | | "sk": { |
| | | "type": "object", |
| | | "description": "æ¶ç©º", |
| | | "properties": { |
| | | "cssj": { |
| | | "type": "string", |
| | | "description": "äº§çæ¶é´" |
| | | }, |
| | | "gxsj": { |
| | | "type": "string", |
| | | "description": "æ´æ°æ¶é´" |
| | | }, |
| | | "xwsj": { |
| | | "type": "string", |
| | | "description": "æ¶äº¡æ¶é´" |
| | | } |
| | | } |
| | | }, |
| | | "ssxzq": { |
| | | "type": "string", |
| | | "description": "æå±è¡æ¿åºå" |
| | | } |
| | | } |
| | | }, |
| | | "children": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "geometry": { |
| | | "type": "array", |
| | | "items": { |
| | | "oneOf": [ |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/MultiPoint" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/MultiLineString" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/MultiSurface" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/CompositeSurface" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/Solid" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/CompositeSolid" |
| | | }, |
| | | { |
| | | "$ref": "geomprimitives.schema.json#/MultiSolid" |
| | | }, |
| | | { |
| | | "$ref": "geomtemplates.schema.json#/GeometryInstance" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | | "required": [ |
| | | "type", |
| | | "topLevel", |
| | | "geometry" |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |