张洋洋
2025-02-11 49aa6ed510d18506cc11d24299899ab0b35047b3
[add]cityjson转sem
已添加3个文件
已修改3个文件
已删除2个文件
415182 ■■■■■ 文件已修改
src/main/java/com/se/simu/controller/SimuController.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/EntityLibraryUtils.java 160 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/ProjectionToGeographicUtil.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/SemUtils.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/GX_YSBZ_P.json 409061 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/JT_CSZGD_L.json 5835 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/layerQueryDetailParams.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/layerQueryParams.json 1 ●●●● 补丁 | 查看 | 原始文档 | 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":[]}}