src/main/java/com/se/simu/controller/SimuController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/utils/EntityLibraryUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/utils/ProjectionToGeographicUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/utils/SemUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/GX_YSBZ_P.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/JT_CSZGD_L.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/layerQueryDetailParams.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/layerQueryParams.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/se/simu/controller/SimuController.java
@@ -15,14 +15,17 @@ import com.se.simu.utils.*; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.*; import org.springframework.web.util.UriUtils; import javax.annotation.Resource; import java.io.*; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; @@ -458,15 +461,41 @@ if (!file.exists()) { file.mkdirs(); } SemUtils.cityJsonToSem(pointPath, filePatn+ "node.sem"); return success(filePatn+ "node.sem"); SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem"); return success(filePatn + "node.sem"); } @ApiOperation(value = "管线转cityjson") @GetMapping(value = "/lineToCityJson", produces = "application/json; charset=UTF-8") public R<String> lineToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { @ApiOperation(value = "管线semçæ") @PostMapping(value = "/lineToSem", produces = "application/json; charset=UTF-8") public R<String> lineToSem(@RequestBody List<GridDto> dtos) throws Exception { String path = outPath + "\\line\\"; List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); JSONArray jsonArrayList = EntityLibraryUtils.getPointInfo(dtos); if (jsonArrayList.size() == 0) { return fail("该åºåä¸åå¨ç®¡çº¿ï¼"); } StringBuffer stringBuffer = new StringBuffer("id in ("); for (int i = 0; i < jsonArrayList.size(); i++) { jsonArrayList.getJSONObject(i).getInteger("id"); stringBuffer.append("'" + jsonArrayList.getJSONObject(i).getInteger("id") + "',"); } String sql = stringBuffer.toString(); sql = sql.substring(0, sql.length() - 1) + ")"; String publicKey = EntityLibraryUtils.getPublicKey(); StringBuffer paramBuffer = new StringBuffer(""); while (!"".equals(sql)) { if (sql.length() > 110) { String item = sql.substring(0, 110); paramBuffer.append(EntityLibraryUtils.encrypt(item, publicKey) + ","); sql = sql.replace(item, ""); } else { paramBuffer.append(EntityLibraryUtils.encrypt(sql, publicKey) + ","); sql = ""; } } String src=paramBuffer.toString().substring(0, paramBuffer.length() - 1); JSONArray arrayDetail = EntityLibraryUtils.getPointDetail(src); //todo æ¿æ¢mapencodedString List<Map<String, Object>> list = new ArrayList<>(); JSONObject jsonObject = getModule("linemodule.json"); for (Map<String, Object> map : list ) { @@ -511,9 +540,61 @@ if (!file.exists()) { file.mkdirs(); } SemUtils.cityJsonToSem(pointPath, filePatn+ "link.sem"); SemUtils.cityJsonToSem(pointPath, filePatn + "link.sem"); return success(filePatn + "link.sem"); } // @ApiOperation(value = "管线转cityjson") // @GetMapping(value = "/lineToCityJson", produces = "application/json; charset=UTF-8") // public R<String> lineToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { // String path = outPath + "\\line\\"; // List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); // JSONObject jsonObject = getModule("linemodule.json"); // for (Map<String, Object> map : list // ) { // //æ¼è£ åºç¡ä¿¡æ¯ // JSONObject cityObject = new JSONObject(); // cityObject.put("type", "+PipeLine"); // JSONObject attribute = new JSONObject(); // attribute.put("name", map.get("msfs")); // JSONArray geometry = new JSONArray(); // JSONObject metry = new JSONObject(); // metry.put("type", "MultiLineString"); // metry.put("lod", 0); // JSONArray boundarie = new JSONArray(); // JSONArray array = JSONObject.parseObject(map.get("the_geom").toString()).getJSONArray("coordinates"); // for (int i = 0; i < array.size(); i++) { // JSONObject object = JSONObject.parseObject(array.get(i).toString()); // jsonObject.getJSONArray("vertices").add(ProjectionToGeographicUtil.getPoint(Double.valueOf(object.get("x").toString()), Double.valueOf(object.get("y").toString()))); // boundarie.add(jsonObject.getJSONArray("vertices").size() - 1); // } // JSONArray jsonArray = new JSONArray(); // jsonArray.add(boundarie); // metry.put("boundaries", jsonArray); // JSONArray metryArray = new JSONArray(); // metryArray.add(metry); // cityObject.put("geometry", metryArray); // cityObject.put("attributes", attribute); // cityObject.put("attributes", attribute); // geometry.add(metry); // jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); // } // long times = System.currentTimeMillis(); // String pointPath = path + times + "\\管线.json"; // File dirFile = new File(path + times); // if (!dirFile.exists()) { // dirFile.mkdirs(); // } // FileWriter fileWriter = new FileWriter(pointPath); // fileWriter.write(jsonObject.toJSONString()); // fileWriter.close(); // String filePatn = inPath + "\\tongzhou\\"; // File file = new File(filePatn); // if (!file.exists()) { // file.mkdirs(); // } // SemUtils.cityJsonToSem(pointPath, filePatn+ "link.sem"); // return success(filePatn + "link.sem"); // } @ApiOperation(value = "å°å½¢è½¬cityjson") @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8") src/main/java/com/se/simu/utils/EntityLibraryUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,160 @@ package com.se.simu.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.common.io.Resources; import com.se.simu.domain.dto.GridDto; import org.apache.commons.codec.binary.Base64; import org.springframework.http.*; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriUtils; import javax.crypto.Cipher; import java.net.URL; import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.List; /** * å®ä½åºè¯·æ± */ public class EntityLibraryUtils { /** * è·åå å¯å ¬é¥ * * @return å ±é¥ */ public static String getPublicKey() { JSONObject jsonObject = new JSONObject(); String json = jsonObject.toJSONString(); // åéJSONæ ¼å¼çPOSTè¯·æ± HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(json, headers); RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://106.120.22.26:8024/geo-service/setting/publickey", request, String.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { String body = responseEntity.getBody(); return JSONObject.parseObject(body).getString("data"); } return null; } public static String encrypt(String str, String publicKey) throws Exception { //Base64ç¼ç çå ¬é¥ byte[] decoded = Base64.decodeBase64(publicKey); RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); // RSAå å¯:RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); String outstr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8))); return outstr; } public static String decrypt(String str, String privateKey) throws Exception { if (str == null || "".equals(str)) { return str; } //64ä½è§£ç å å¯åçå符串 byte[] inputByte = Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8)); //Base64ç¼ç çç§é¥ byte[] decoded = Base64.decodeBase64(privateKey); RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); //RSAè§£å¯:RSA/ECB/NoPadding Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, priKey); String outstn = new String(cipher.doFinal(inputByte), StandardCharsets.UTF_8); return outstn; } public static void main(String[] args) throws Exception { String publickey = getPublicKey(); System.out.println("å ¬é¥=" + publickey); String en = encrypt("id in ('46235','49876')", publickey); System.out.println("å å¯å符串=" + en); String encode = UriUtils.encode(en, StandardCharsets.UTF_8); System.out.println("encodeå符串=" + encode); String decode = UriUtils.decode(encode, StandardCharsets.UTF_8); System.out.println("decodeå符串=" + decode); System.out.println("è§£å¯å符串=" + decrypt(decode, "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJiF6WkdgHlimpakWJMvH3Xnjwws7qqoo1rhbg/iLzLGly/EKLvUzD6D7FUFk+GAP/sOKh1cZZEvi1KkGd6OufqMKdDvRvVtGjXExI5MLJDVDaYTsqhzNF8maB2H7dwR+iiDGph2DMPQtuV/k/dalXMxR6O8Q2MPQfaUiOVebKBbAgMBAAECgYARrPs21ldsOdQmfxdQv1ZLCLHYPGDQYEjGIHfr2U+U99TPkVETK38cA5fg5ouTx5QimSqiSnHu2G6x/hiNZUcCJp/1agvsFEI2FLokShYbitOYa07Da1eIKpZA5F+P5j5/QOVpVsWOxvEDA/dkF+vrV4vU/iV7H3QJqBfsLSxEeQJBAO43SVkzJM6dqnRw7sib7SOvguicnr7UKt0Tadc1PwLMWCCFu+4p3iN9Zj/7K5VHjomW+NIv7UAGynDfHBpv1x0CQQCj6ONm+m4FlaTdg+Pc36BBy4Gd6ucm6WfjDTHMaZi3uzINjTPBut6DmrUt68dyHdGpo6OIjCdX3xU27HtmjiPXAkEAwjdhHdCM2cfCCV1p0TUPimC2ImBPLNZefBAv4r4OuYFQ+HMQXYTVD6pViySEzBijJZppEzTwAZuHwa6lgwhcIQJBAI8PBOssSDq3kV2Fb6unwseqR0b9byKXNQUGzyAKSjCSQe1yAGpmHy/eJ6Qc1cbUH9pf6KuVKAGZw3pcjJfGF6ECQQCx9dJ2qJjm2R78/HH0SkOATpMATgewtHH5tRJfCJv7NLveuYNRFH1An4APWYq9IdVfyn+4gyXz3OClteE7jAkt")); } /** * 管线å表 * * @param dtos åä¸ªåæ ç¹ * @return æ¡éå é¨ç®¡çº¿ */ public static JSONArray getPointInfo(List<GridDto> dtos) { JSONArray paramArray = new JSONArray(); for (GridDto dto : dtos ) { paramArray.add(ProjectionToGeographicUtil.get4548Point(dto.getLon(), dto.getLat())); } paramArray.add(ProjectionToGeographicUtil.get4548Point(dtos.get(0).getLon(), dtos.get(0).getLat())); JSONObject jsonObject = getModule("layerQueryParams.json"); jsonObject.getJSONObject("geometry").getJSONArray("coordinates").add(paramArray); RestTemplate restTemplate = new RestTemplate(); // åéJSONæ ¼å¼çPOSTè¯·æ± HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); String json = jsonObject.toJSONString(); HttpEntity<String> request = new HttpEntity<>(json, headers); ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://106.120.22.26:8024/geo-service/entitydbdata/layer/query", request, String.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { String body = responseEntity.getBody(); return JSONObject.parseObject(body).getJSONObject("data").getJSONArray("items"); } return null; } /** * 管线å表详æ * * @param param æ¥è¯¢åæ° * @return åæ°å 详æ */ public static JSONArray getPointDetail(String param) { JSONObject jsonObject = getModule("layerQueryDetailParams.json"); jsonObject.put("where", param); RestTemplate restTemplate = new RestTemplate(); // åéJSONæ ¼å¼çPOSTè¯·æ± StringHttpMessageConverter converter = new StringHttpMessageConverter(StandardCharsets.UTF_8); converter.setSupportedMediaTypes(MediaType.parseMediaTypes("text/plain;charset=UTF-8")); restTemplate.getMessageConverters().add(0, converter); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); String json = jsonObject.toJSONString(); HttpEntity<String> request = new HttpEntity<>(json, headers); ResponseEntity<String> responseEntity = restTemplate.exchange("http://106.120.22.26:8024/geo-service/entitydbdata/layer/query", HttpMethod.POST, request, String.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { String body = responseEntity.getBody(); return JSONObject.parseObject(body).getJSONArray("features"); } return null; } /** * è·å请æ±json * * @param moduleName jsonå * @return jsonå 容 */ private static JSONObject getModule(String moduleName) { JSONObject jsonObject = new JSONObject(); try { URL resource = Resources.getResource(moduleName); String fileContent = Resources.toString(resource, StandardCharsets.UTF_8); jsonObject = JSONObject.parseObject(fileContent); System.out.println(fileContent); } catch (Exception e) { e.printStackTrace(); } return jsonObject; } } src/main/java/com/se/simu/utils/ProjectionToGeographicUtil.java
@@ -29,4 +29,29 @@ vertice.add(0.0); return vertice; } public static JSONArray get4548Point(Double x,Double y) { // å建 CRSFactory 对象 CRSFactory crsFactory = new CRSFactory(); // å®ä¹æå½±åæ ç³»ç»ï¼è¿é以 UTM æå½±ä¸ºä¾ï¼zone 33N CoordinateReferenceSystem sourceCRS = crsFactory.createFromName("EPSG:4326"); // å®ä¹å°çåæ ç³»ç»ï¼è¿éä½¿ç¨ WGS84 CoordinateReferenceSystem targetCRS = crsFactory.createFromName("EPSG:4548"); // åå»ºåæ è½¬æ¢å¯¹è±¡ BasicCoordinateTransform transform = new BasicCoordinateTransform(sourceCRS, targetCRS); // è¾å ¥æå½±åæ ï¼ä»¥ UTM æå½±åæ 为ä¾ï¼å使¯ç±³ ProjCoordinate sourceCoord = new ProjCoordinate(x, y); ProjCoordinate targetCoord = new ProjCoordinate(); // æ§è¡åæ è½¬æ¢ transform.transform(sourceCoord, targetCoord); JSONArray vertice = new JSONArray(); vertice.add(targetCoord.x); vertice.add(targetCoord.y); return vertice; } public static void main(String[] args) { System.out.println(getPoint(470554.2614775232,4416699.023973457)); System.out.println(get4548Point(116.65575979450138,39.883938395445966)); } } src/main/java/com/se/simu/utils/SemUtils.java
@@ -14,7 +14,7 @@ } public static void semToCityJson() throws Exception { //sem转cityjson SEM sem2 = new SEM("D:\\uwsolver\\tongzhou\\raingage.sem"); sem2.writeToCityJSON("D:\\uwsolver\\tongzhou\\raingage\\raingage.json"); SEM sem2 = new SEM("D:\\uwsolver\\tongzhou\\link.sem"); sem2.writeToCityJSON("D:\\uwsolver\\tongzhou\\link\\link.json"); } } src/main/resources/GX_YSBZ_P.json
ÎļþÒÑɾ³ý src/main/resources/JT_CSZGD_L.json
ÎļþÒÑɾ³ý src/main/resources/layerQueryDetailParams.json
¶Ô±ÈÐÂÎļþ @@ -0,0 +1 @@ {"dbid":"85257774fdb64e5f99f6778696cad02a","querytype":"polyline","layerid":"1e677d48-8dff-4975-b9a0-c16500193629","where":"","containCount":false,"token":"54bc48d424ee49c6b07c1c6f91a583ea"} src/main/resources/layerQueryParams.json
¶Ô±ÈÐÂÎļþ @@ -0,0 +1 @@ {"dbid":"85257774fdb64e5f99f6778696cad02a","layerid":"1e677d48-8dff-4975-b9a0-c16500193629","token":"54bc48d424ee49c6b07c1c6f91a583ea","start":1,"count":100000,"like":null,"outfields":"seid,bsm","containCount":true,"geometry":{"type":"Polygon","coordinates":[]}}