ywf 4 dias atrás
pai
commit
3f60e2a765

+ 13 - 1
onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/ParsingShpFileUtils.java

@@ -9,6 +9,7 @@ import org.geotools.data.simple.SimpleFeatureCollection;
 import org.geotools.data.simple.SimpleFeatureIterator;
 import org.geotools.data.simple.SimpleFeatureIterator;
 import org.geotools.data.simple.SimpleFeatureSource;
 import org.geotools.data.simple.SimpleFeatureSource;
 import org.geotools.geojson.GeoJSONUtil;
 import org.geotools.geojson.GeoJSONUtil;
+import org.geotools.geojson.geom.GeometryJSON;
 import org.geotools.geojson.feature.FeatureJSON;
 import org.geotools.geojson.feature.FeatureJSON;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONArray;
@@ -192,7 +193,7 @@ public class ParsingShpFileUtils {
      * @return
      * @return
      */
      */
     public static String shape2Geojson(String shpPath, String jsonPath) {
     public static String shape2Geojson(String shpPath, String jsonPath) {
-        FeatureJSON fjson = new FeatureJSON();
+        FeatureJSON fjson = new FeatureJSON(new GeometryJSON(7));
         StringBuffer sb = new StringBuffer();
         StringBuffer sb = new StringBuffer();
         try {
         try {
             sb.append("{\"type\": \"FeatureCollection\",\"features\": ");
             sb.append("{\"type\": \"FeatureCollection\",\"features\": ");
@@ -207,6 +208,17 @@ public class ParsingShpFileUtils {
                 StringWriter writer = new StringWriter();
                 StringWriter writer = new StringWriter();
                 fjson.writeFeature(feature, writer);
                 fjson.writeFeature(feature, writer);
                 JSONObject json = JSONObject.parseObject(writer.toString());
                 JSONObject json = JSONObject.parseObject(writer.toString());
+                JSONObject geometry = json.getJSONObject("geometry");
+                if (geometry != null) {
+                    String type = geometry.getString("type");
+                    if ("MultiPolygon".equals(type)) {
+                        com.alibaba.fastjson.JSONArray coordinates = geometry.getJSONArray("coordinates");
+                        if (coordinates != null && coordinates.size() == 1) {
+                            geometry.put("type", "Polygon");
+                            geometry.put("coordinates", coordinates.get(0));
+                        }
+                    }
+                }
                 array.add(json);
                 array.add(json);
             }
             }
             itertor.close();
             itertor.close();