rain
2024-03-28 a83ae77a98e235cdca07a1bb167a9a43479a2c9a
src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
@@ -11,7 +11,6 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
@@ -54,10 +53,11 @@
            Filter filter = Filter.INCLUDE;
            FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
            return collection;
        }catch (Exception e){
        } catch (Exception e) {
            throw e;
        }
    }
    /**
     * @param zipFile:
     * @return JSONObject
@@ -65,16 +65,17 @@
     * @description 通过shp压缩文件,将其转换为GeoJson格式
     * @date 2023/7/18 16:04
     */
    public static JSONObject shpToGeoJson(File zipFile) throws IOException {
    public static List<String> shpToGeoJson(File zipFile) throws IOException {
        FeatureJSON fjson = new FeatureJSON();
        JSONObject geoJsonObject=new JSONObject();
        geoJsonObject.put("type","FeatureCollection");
        JSONObject geoJsonObject = new JSONObject();
        geoJsonObject.put("type", "FeatureCollection");
        List<String> strings = new ArrayList<>();
        try {
            // 获取FeatureCollection
            FeatureCollection collection = getFeatureCollectionByShpFile(zipFile);
            FeatureIterator iterator = collection.features();
            List<JSONObject> array  = new ArrayList<JSONObject>();
            List<JSONObject> array = new ArrayList<JSONObject>();
            //遍历feature转为json对象
            while (iterator.hasNext()) {
                SimpleFeature feature = (SimpleFeature) iterator.next();
@@ -84,17 +85,19 @@
                byte[] b = temp.getBytes("iso8859-1");
                temp = new String(b, "gbk");
                JSONObject json = JSONObject.parseObject(temp);
                String str2 = json.getJSONObject("geometry").get("coordinates").toString();
                strings.add(str2);
                array.add(json);
            }
            iterator.close();
            //添加到geojsonObject
            geoJsonObject.put("features",array);
            geoJsonObject.put("features", array);
            iterator.close();
        }catch (Exception e){
        } catch (Exception e) {
            throw e;
        }
        return geoJsonObject;
        return strings;
    }
}