src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
@@ -22,6 +22,9 @@
import java.io.StringWriter;
import java.util.*;
import static com.dji.sample.patches.utils.TimerUtil.getNowDay;
import static com.dji.sample.patches.utils.TimerUtil.getNowTimeName;
public class ShapeFileUtil {
    //将文件解压
@@ -69,37 +72,60 @@
        FeatureJSON fjson = new FeatureJSON();
        JSONObject geoJsonObject = new JSONObject();
        geoJsonObject.put("type", "FeatureCollection");
            // 获取FeatureCollection
            FeatureCollection collection = getFeatureCollectionByShpFile(zipFile);
        // 获取FeatureCollection
        FeatureCollection collection = getFeatureCollectionByShpFile(zipFile);
            FeatureIterator iterator = collection.features();
            //遍历feature转为json对象
            while (iterator.hasNext()) {
                ShpDTO shpDTO = new ShpDTO();
                SimpleFeature feature = (SimpleFeature) iterator.next();
                StringWriter writer = new StringWriter();
                fjson.writeFeature(feature, writer);
                String temp = writer.toString();
                byte[] b = temp.getBytes("iso8859-1");
                temp = new String(b, "gbk");
                JSONObject json = JSONObject.parseObject(temp);
                shpDTO.setDKFW(json.getJSONObject("geometry").get("coordinates").toString());
                shpDTO.setGEO(json.getJSONObject("geometry").get("type").toString());
                shpDTO.setXZQDM(json.getJSONObject("properties").get("XZQDM").toString());
        FeatureIterator iterator = collection.features();
        //遍历feature转为json对象
        while (iterator.hasNext()) {
            ShpDTO shpDTO = new ShpDTO();
            SimpleFeature feature = (SimpleFeature) iterator.next();
            StringWriter writer = new StringWriter();
            fjson.writeFeature(feature, writer);
            String temp = writer.toString();
            byte[] b = temp.getBytes("iso8859-1");
            temp = new String(b, "gbk");
            JSONObject json = JSONObject.parseObject(temp);
            shpDTO.setDKFW(json.getJSONObject("geometry").getString("coordinates"));
            if ((json.getJSONObject("geometry").get("type")) != null) {
                shpDTO.setGEO(json.getJSONObject("geometry").getString("type"));
            }
            if ((json.getJSONObject("properties").get("XZQDM")) != null) {
                shpDTO.setXZQDM(json.getJSONObject("properties").getString("XZQDM"));
            }
            if ((json.getJSONObject("properties").getDouble("XZB")) != null &&
                    json.getJSONObject("properties").getDouble("YZB") != null) {
                double[] xy = getLongitudeLatitude(CoordinateSystemUtil.pointCGCStoWGS(
                                json.getJSONObject("properties").getDouble("XZB"),
                                json.getJSONObject("properties").getDouble("YZB")));
                        json.getJSONObject("properties").getDouble("XZB"),
                        json.getJSONObject("properties").getDouble("YZB")));
                shpDTO.setXZB(xy[0]);
                shpDTO.setYZB(xy[1]);
                shpDTO.setDKBH(json.getJSONObject("properties").getString("JCBH"));
                shpDTO.setJCMJ(json.getJSONObject("properties").getDouble("JCMC"));
                shpDTO.setTBLX(json.getJSONObject("properties").getString("TBLX"));
                shpDTO.setDDTC(json.getJSONObject("properties").getString("DDTC"));
                shpDTO.setHSX(json.getJSONObject("properties").getString("HSX"));
                shpDTO.setJCLX(json.getJSONObject("properties").getString("JCLX"));
                dtoList.add(shpDTO);
            }
            iterator.close();
            if ((json.getJSONObject("properties").getString("JCBH") != null)) {
                shpDTO.setDKBH(json.getJSONObject("properties").getString("JCBH"));
            }else {
                shpDTO.setDKBH(getNowDay());
            }
            if (json.getJSONObject("properties").getDouble("JCMC") != null) {
                shpDTO.setJCMJ(json.getJSONObject("properties").getDouble("JCMC"));
            }
            if (json.getJSONObject("properties").getString("TBLX") != null) {
                shpDTO.setTBLX(json.getJSONObject("properties").getString("TBLX"));
            }
            if (json.getJSONObject("properties").getString("DDTC") != null) {
                shpDTO.setDDTC(json.getJSONObject("properties").getString("DDTC"));
            }
            if (json.getJSONObject("properties").getString("HSX") != null) {
                shpDTO.setHSX(json.getJSONObject("properties").getString("HSX"));
            }
            if (json.getJSONObject("properties").getString("JCLX") != null) {
                shpDTO.setJCLX(json.getJSONObject("properties").getString("JCLX"));
            }
            dtoList.add(shpDTO);
        }
        iterator.close();
        return dtoList;
    }