LAPTOP-BJJ3IV5R\SIWEI 7 месяцев назад
Родитель
Сommit
708230de0c

+ 15 - 4
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/controller/ShpController.java

@@ -1,14 +1,14 @@
 package com.onemap.spatial.controller;
 
+import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.spatial.domain.ShpVo;
 import com.onemap.spatial.domain.WktsVo;
 import com.onemap.spatial.service.IImageService;
+import com.onemap.spatial.service.IShpFileSaveService;
 import com.onemap.spatial.service.IWriteShpServer;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
@@ -19,6 +19,8 @@ import java.util.Map;
 public class ShpController {
     @Resource
     private IWriteShpServer writeShpServer;
+    @Autowired
+    private IShpFileSaveService shpFileSaveService;
 
     @PostMapping("/write/ewkt")
     public RequestResult writeShpByEWkt(@RequestBody ShpVo shpVo) throws Exception {
@@ -36,4 +38,13 @@ public class ShpController {
         map.put("path", path.replace("\\", "/"));
         return RequestResult.success(map);
     }
+
+    @GetMapping("/read/file")
+    public RequestResult readFile(String filepath) {
+        if (StringUtils.isEmpty(filepath)) {
+            return RequestResult.error("filepath is null");
+        }
+        shpFileSaveService.readFile(filepath);
+        return RequestResult.success(0);
+    }
 }

+ 21 - 0
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/mapper/ShpFileMapper.java

@@ -0,0 +1,21 @@
+package com.onemap.spatial.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 数据层
+ *
+ * @author onemap
+ */
+@Mapper
+public interface ShpFileMapper {
+
+    void createTable(@Param("tableMap") List<Map<String, String>> tableList, @Param("tableName") String tableName);
+
+//    void insertTableData (Map<String, Object> tableDataMap);
+    void insertTableData (@Param("tableDataMap") List<Object> tableDataMap, @Param("tableName") String tableName, @Param("ewkt") String ewkt);
+}

+ 5 - 0
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/IShpFileSaveService.java

@@ -0,0 +1,5 @@
+package com.onemap.spatial.service;
+
+public interface IShpFileSaveService {
+    public void readFile(String filepath);
+}

+ 201 - 0
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ShpFileSaveServiceImpl.java

@@ -0,0 +1,201 @@
+package com.onemap.spatial.service.impl;
+
+import com.onemap.common.core.utils.StringUtils;
+import com.onemap.spatial.mapper.ShpFileMapper;
+import com.onemap.spatial.service.IShpFileSaveService;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
+import org.locationtech.jts.geom.Geometry;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.GeometryType;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.*;
+
+@Service
+public class ShpFileSaveServiceImpl implements IShpFileSaveService {
+
+    @Resource
+    private ShpFileMapper shpFileMapper;
+
+    @Override
+    public void readFile(String filepath) {
+        readShapeFile(new File(filepath));
+//        readShapeFile(new File("D:\\02DATA\\三亚\\甲方数据\\权属\\SHP\\国有使用权去掉.shp"));
+    }
+
+    public String convertShpFieldType2H2GISOrPG(Class value) throws Exception {
+        if (value == String.class) {//文本
+            return "varchar";
+        }
+        if (value == Integer.class) {//短整型
+            return "int";
+        }
+        if (value == Long.class) {//长整型
+            return "bigint";
+        }
+        if (value == Double.class || value == Float.class) {//浮点型 双精度 保留精度,比如在金币上运算更安全
+            return "numeric";
+        }
+        if (value == Date.class) {
+            return "timestamp without time zone";//日期, 使用包含时区的来处理
+        }
+        if (Geometry.class.isAssignableFrom(value)) {
+            return "public.geometry";
+        }
+        //除了上述,真不知道还会有啥了。除非arcgis的shp又增加了新类型?!那无能为力了,抛出异常吧
+        throw new Exception("不支持的类型!" + value.getName());
+    }
+
+
+    /**
+     * @param shpFile 传递的是shape文件中的.shp文件
+     */
+    private void readShapeFile(File shpFile) {
+        /**
+         * 直接使用shapefileDatastore,如果不知道,也可以使用工厂模式(见下个方法)
+         * 建议,如果确定是shape文件,就直使用shapefileDatastore
+         */
+        try {
+            ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
+            shapefileDataStore.setCharset(Charset.forName("UTF-8"));
+            //这个typeNamae不传递,默认是文件名称
+            FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
+
+            //获取当前数据的geometry类型(点、线、面)
+            GeometryType geometryType = featuresource.getSchema().getGeometryDescriptor().getType();
+            System.out.println(geometryType.getName());
+//            if ("Polygon".equals(geometryType.get) {
+//                tb.add("the_geom", Polygon.class);
+//            } else if ("MultiPolygon".equals(geomTypeData.getGeometryType())) {
+//                tb.add("the_geom", MultiPolygon.class);
+//            }
+            //读取要素
+            SimpleFeatureCollection simpleFeatureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
+            //获取当前矢量数据有哪些属性字段值
+
+            //获取字段列表
+            List<String> attributesList = new ArrayList<>();
+            List<Map<String, String>> tableCommsList = new ArrayList<>();
+            List<AttributeDescriptor> attributes = simpleFeatureCollection.getSchema().getAttributeDescriptors();
+            for (AttributeDescriptor h : attributes) {
+                String type = convertShpFieldType2H2GISOrPG(h.getType().getBinding());
+                attributesList.add(h.getLocalName());
+                Map<String, String> attributesMap = new LinkedHashMap<>();
+                if (!h.getLocalName().toLowerCase().equals("the_geom")) {
+                    attributesMap.put("key", h.getLocalName().toLowerCase());
+                    attributesMap.put("value", type);
+                    tableCommsList.add(attributesMap);
+                }
+            }
+            //添加ID
+            Map<String, String> attributesMap = new LinkedHashMap<>();
+            attributesMap.put("key", "id");
+            attributesMap.put("value", "varchar");
+            tableCommsList.add(attributesMap);
+
+            //添加ID
+            Map<String, String> attributesMap2 = new LinkedHashMap<>();
+            attributesMap2.put("key", "geom");
+            attributesMap2.put("value", "public.geometry");
+            tableCommsList.add(attributesMap2);
+
+            System.out.println(tableCommsList.toString());
+
+            String tableName = "temporary" + "_" + System.currentTimeMillis() + "_" + StringUtils.getUUID();
+            shpFileMapper.createTable(tableCommsList, tableName);
+
+            //获取属性
+            SimpleFeatureIterator simpleFeatureIterator = simpleFeatureCollection.features();
+            while (simpleFeatureIterator.hasNext()) {
+                Map<String, Object> pg_rk = new LinkedHashMap<>();
+                List<Object> pg_rk_list = new ArrayList<>();
+                SimpleFeature simpleFeature = simpleFeatureIterator.next();
+                int f_i = 0;
+                for (; f_i < attributesList.size(); f_i++) {
+                    if (!attributesList.get(f_i).toLowerCase().equals("the_geom")) {
+                        pg_rk.put("key_" + f_i, simpleFeature.getAttribute(attributesList.get(f_i)));
+                        pg_rk_list.add(simpleFeature.getAttribute(attributesList.get(f_i)));
+                    }
+                }
+                pg_rk_list.add(StringUtils.getUUID());
+                pg_rk.put("key_" + f_i, StringUtils.getUUID());
+
+                Geometry geometry = (Geometry) simpleFeature.getAttribute("the_geom");
+                String geom = geometry.toText();
+                String ewkt = "SRID=4326;" + geom;
+                ewkt = "public.st_transform(public.st_geomfromewkt('" + ewkt + "'), 4326)";
+                System.out.println(ewkt);
+                pg_rk.put("geom", simpleFeature.getAttribute("the_geom").toString());
+                shpFileMapper.insertTableData(pg_rk_list, tableName, ewkt);
+            }
+            simpleFeatureIterator.close();
+            shapefileDataStore.dispose();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+
+        }
+
+    }
+
+
+//    private static void readShapeFile(File shpFile) {
+//        /**
+//         * 直接使用shapefileDatastore,如果不知道,也可以使用工厂模式(见下个方法)
+//         * 建议,如果确定是shape文件,就直使用shapefileDatastore
+//         */
+//        try {
+//            ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
+//            shapefileDataStore.setCharset(Charset.forName("UTF-8"));
+//            //这个typeNamae不传递,默认是文件名称
+//            FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
+//            //读取bbox
+//            ReferencedEnvelope bbox = featuresource.getBounds();
+//            System.out.println(String.valueOf(bbox.getMaxX()) + ":" + String.valueOf(bbox.getMaxY()));
+//            //读取投影
+//            CoordinateReferenceSystem crs = featuresource.getSchema().getCoordinateReferenceSystem();
+//            System.out.println(crs.toWKT());
+//            //特征总数
+//            int count = featuresource.getCount(Query.ALL);
+//            System.out.println(count);
+//            //获取当前数据的geometry类型(点、线、面)
+//            GeometryType geometryType = featuresource.getSchema().getGeometryDescriptor().getType();
+//            System.out.println(geometryType);
+//            //读取要素
+//            SimpleFeatureCollection simpleFeatureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
+//            //获取当前矢量数据有哪些属性字段值
+//            List<AttributeDescriptor> attributes = simpleFeatureCollection.getSchema().getAttributeDescriptors();
+//            for (AttributeDescriptor h:attributes){
+//                String g = convertShpFieldType2H2GISOrPG(h.getType().getBinding());
+//                System.out.println(g);
+////                System.out.println(h.getLocalName()+"  "+h.getType().getBinding()+"  "+h.getDefaultValue());
+//            }
+////            System.out.println(attributes);
+//
+//            SimpleFeatureIterator simpleFeatureIterator = simpleFeatureCollection.features();
+//
+//            while(simpleFeatureIterator.hasNext()) {
+//                SimpleFeature simpleFeature = simpleFeatureIterator.next();
+//                attributes.stream().forEach((a) -> {
+//                    //依次读取这个shape中每一个属性值,当然这个属性值,可以处理其它业务
+//                    System.out.println(simpleFeature.getAttribute(a.getLocalName()));
+//                });
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+//
+//    }
+}

+ 360 - 0
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/util/ShapeFileUtil.java

@@ -0,0 +1,360 @@
+package com.onemap.spatial.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.geotools.data.DataStore;
+import org.geotools.data.DataStoreFinder;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.data.store.ContentFeatureCollection;
+import org.geotools.data.store.ContentFeatureSource;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.referencing.CRS;
+import org.locationtech.jts.geom.Envelope;
+import org.locationtech.jts.geom.Geometry;
+import org.opengis.feature.GeometryAttribute;
+import org.opengis.feature.Property;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class ShapeFileUtil {
+    /**
+     * convert shpFileType to db field type
+     * 备注:目前arcgis的字段类型有:短整型 长整型 浮点型 双精度 文本 日期
+     *
+     * @param value
+     * @return
+     */
+    public static String convertShpFieldType2H2GISOrPG(Class value) throws Exception {
+        if (value == String.class) {//文本
+            return "varchar";
+        }
+        if (value == Integer.class) {//短整型
+            return "int";
+        }
+        if (value == Long.class) {//长整型
+            return "bigint";
+        }
+        if (value == Double.class || value == Float.class) {//浮点型 双精度 保留精度,比如在金币上运算更安全
+            return "numeric";
+        }
+        if (value == Date.class) {
+            return "TIMESTAMP WITH TIME ZONE ";//日期, 使用包含时区的来处理
+        }
+        if (Geometry.class.isAssignableFrom(value)) {
+            return "geometry";
+        }
+        //除了上述,真不知道还会有啥了。除非arcgis的shp又增加了新类型?!那无能为力了,抛出异常吧
+        throw new Exception("不支持的类型!" + value.getName());
+        //
+//        if (value.getSuperclass().getName().equals(String.class))
+
+//        return null;
+    }
+
+    /**
+     * 读取shp的bbox并返回
+     *
+     * @param filePaths
+     * @return GeomAttrWrapper.bboxMap属性中存储每个shp对应的bbox
+     * @throws IOException
+     */
+    public static GeomAttrWrapper readBboxFromFile(List<String> filePaths) throws IOException {
+        Map<String, Envelope> bboxMap = new HashMap<>();
+        for (String filePath : filePaths) {
+            if (!filePath.endsWith(".shp")) {
+                continue;
+            }
+            File file = new File(filePath);
+            Map<String, Object> map = new HashMap<>();
+            map.put("url", file.toURI().toURL());
+
+            ShapefileDataStore dataStore = new ShapefileDataStore(file.toURI().toURL());//DataStoreFinder.getDataStore(map);
+            dataStore.setCharset(Charset.forName("GBK"));
+            String typeName = dataStore.getTypeNames()[0];
+
+            FeatureSource<SimpleFeatureType, SimpleFeature> source =
+                    dataStore.getFeatureSource(typeName);
+            Filter filter = Filter.INCLUDE; // ECQL.toFilter("BBOX(THE_GEOM, 10,20,30,40)")
+            FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
+            bboxMap.put(filePath, collection.getBounds());
+//            final CoordinateReferenceSystem coordinateReferenceSystem = collection.getBounds().getCoordinateReferenceSystem();
+//            final String crsCode = CRS.toSRS(coordinateReferenceSystem, true);
+            dataStore.dispose();
+        }
+
+        return new GeomAttrWrapper(null, null, bboxMap);
+    }
+
+    /**
+     * 从shp文件中读取geometry和属性字段数据
+     *
+     * @param filePaths      shp文件在磁盘下的绝对路径
+     * @param returnAllAttrs 若为true,则返回全部的属性;若为false,则提取filterAttrs中指定的属性和geometry;filterAttrs为null或者空,则只提取geometry
+     * @param filterAttrs    用于过滤出希望返回的属性
+     * @return GeomAttrWrapper
+     * @throws Exception
+     */
+    public static GeomAttrWrapper readShapeAndFieldsFromFile(List<String> filePaths, boolean returnAllAttrs, Set<String> filterAttrs) throws Exception {
+        Map<String, List<ShpGeomWithAttr>> geoMap = new HashMap<>();
+        Map<String, Envelope> bboxMap = new HashMap<>();
+        boolean getExpectedAttrs = filterAttrs != null && filterAttrs.size() > 0 ? true : false;
+        Map<String, Class> attrTypes = new HashMap<>();
+        for (String filePath : filePaths) {
+            if (!filePath.endsWith(".shp")) {
+                continue;
+            }
+            List<ShpGeomWithAttr> geometries = new ArrayList<>();
+            File file = new File(filePath);
+            Map<String, Object> map = new HashMap<>();
+            map.put("url", file.toURI().toURL());
+
+            ShapefileDataStore dataStore = new ShapefileDataStore(file.toURI().toURL());//DataStoreFinder.getDataStore(map);
+            dataStore.setCharset(Charset.forName("UTF-8"));
+            String typeName = dataStore.getTypeNames()[0];
+
+            FeatureSource<SimpleFeatureType, SimpleFeature> source =
+                    dataStore.getFeatureSource(typeName);
+            Filter filter = Filter.INCLUDE; // ECQL.toFilter("BBOX(THE_GEOM, 10,20,30,40)")
+            FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
+            bboxMap.put(filePath, collection.getBounds());
+            final CoordinateReferenceSystem coordinateReferenceSystem = collection.getBounds().getCoordinateReferenceSystem();
+            final String crsCode = CRS.toSRS(coordinateReferenceSystem, true);
+            int srid = 0;
+            try {
+                srid = Integer.parseInt(crsCode);
+            } catch (NumberFormatException e) {//有时候,prj文件中没有出现’AUTHORITY["EPSG",4326]‘,就会解不了srid的int出来,就会报错,此时就不管它了,没办法
+//                e.printStackTrace();
+            }
+            try (FeatureIterator<SimpleFeature> features = collection.features()) {
+                while (features.hasNext()) {
+                    SimpleFeature feature = features.next();
+                    final GeometryAttribute geometryProperty = feature.getDefaultGeometryProperty();
+                    Object value = geometryProperty.getValue();
+                    if (value instanceof Geometry) {
+                        Geometry geometry = (Geometry) value;
+                        geometry.setSRID(srid);
+                        Map<String, Object> properties = null;
+                        if (returnAllAttrs) {// 全都返回,则直接全都返回
+                            final Collection<Property> prps = feature.getProperties();
+                            properties = new HashMap<>(prps.size());
+                            for (Property prp : prps) {
+                                final String name = prp.getName().getLocalPart().toLowerCase(Locale.ROOT);
+                                properties.put(name, prp.getValue());
+                                final Class type = attrTypes.get(name);
+                                if (type == null) {
+                                    attrTypes.put(name, prp.getType().getBinding());
+                                }
+                            }
+                        } else if (getExpectedAttrs) {
+                            properties = new HashMap<>(filterAttrs.size());
+                            final Collection<Property> prps = feature.getProperties();
+                            for (Property prp : prps) {
+                                final String name = prp.getName().getLocalPart().toLowerCase(Locale.ROOT);
+                                if (filterAttrs.contains(name)) {
+                                    properties.put(name, prp.getValue());
+                                    final Class type = attrTypes.get(name);
+                                    if (type == null) {
+                                        attrTypes.put(name, prp.getType().getBinding());
+                                    }
+                                }
+                            }
+                        }
+                        ShpGeomWithAttr shpGeomWithAttr = new ShpGeomWithAttr(geometry, properties);
+                        geometries.add(shpGeomWithAttr);
+                    }
+                }
+            } catch (Exception e) {
+                //do nothing...
+            }
+            dataStore.dispose();
+            geoMap.put(filePath, geometries);
+        }
+
+        return new GeomAttrWrapper(geoMap, attrTypes, bboxMap);
+    }
+
+
+    /**
+     * 从shp文件中读取geometry数据
+     *
+     * @param filePaths shp文件在磁盘下的绝对路径
+     * @return
+     * @throws Exception
+     */
+    public static Map<String, List<Geometry>> readShapeFromFile(List<String> filePaths) throws Exception {
+        Map<String, List<Geometry>> geoMap = new HashMap<>();
+        for (String filePath : filePaths) {
+            if (!filePath.endsWith(".shp")) {
+                continue;
+            }
+            List<Geometry> geometries = new ArrayList<>();
+            File file = new File(filePath);
+            Map<String, Object> map = new HashMap<>();
+            map.put("url", file.toURI().toURL());
+
+            DataStore dataStore = DataStoreFinder.getDataStore(map);
+            String typeName = dataStore.getTypeNames()[0];
+
+            FeatureSource<SimpleFeatureType, SimpleFeature> source =
+                    dataStore.getFeatureSource(typeName);
+            Filter filter = Filter.INCLUDE; // ECQL.toFilter("BBOX(THE_GEOM, 10,20,30,40)")
+
+            FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
+            final CoordinateReferenceSystem coordinateReferenceSystem = collection.getBounds().getCoordinateReferenceSystem();
+            final String crsCode = CRS.toSRS(coordinateReferenceSystem, true);
+            int srid = 0;
+            try {
+                srid = Integer.parseInt(crsCode);
+            } catch (NumberFormatException e) {//有时候,prj文件中没有出现’AUTHORITY["EPSG",4326]‘,就会解不了srid的int出来,就会报错,此时就不管它了,没办法
+//                e.printStackTrace();
+            }
+
+            try (FeatureIterator<SimpleFeature> features = collection.features()) {
+                while (features.hasNext()) {
+                    SimpleFeature feature = features.next();
+//                    final Collection<Property> properties = feature.getProperties();
+//                    final Property name = feature.getProperty("Name");
+//                    final List<Object> attributes = feature.getAttributes();
+//                    final Object name1 = feature.getAttribute("Name");//value本身
+//                   Property  name.getType().getBinding().getName();//可以获取类型
+                    //name.getName();//获取字段名称
+                    //name.getValue();//获取值
+                    final GeometryAttribute geometryProperty = feature.getDefaultGeometryProperty();
+                    Object value = geometryProperty.getValue();
+                    if (value instanceof Geometry) {
+                        Geometry geometry = (Geometry) value;
+                        geometry.setSRID(srid);
+                        geometries.add(geometry);
+//                        Envelope geomEnvelope = geometry.getEnvelopeInternal();
+//                        envelope.expandToInclude(geomEnvelope);
+                    }
+                }
+            }
+            dataStore.dispose();
+
+            geoMap.put(filePath, geometries);
+        }
+
+        return geoMap;
+    }
+
+    /**
+     * @param baseDir shp文件(夹)的绝对路径
+     * @return 返回该文件(夹)的所有的shp的绝对路径
+     */
+    public static List<String> getShpFilePaths(String baseDir) {
+        if (baseDir.endsWith(".shp")) {
+            return new ArrayList<String>() {{
+                add(baseDir);
+            }};
+        }
+
+        File fileDir = new File(baseDir);
+        if (!fileDir.exists()) {
+            return null;
+        }
+        List<String> shpList = new ArrayList<>();
+        List<String> dirs = new ArrayList() {{
+            add(baseDir);
+        }};
+        while (true) {
+            List<String> newDirs = null;
+            if (dirs != null && dirs.size() > 0) {
+                for (String dir : dirs) {
+                    File file = new File(dir);
+                    final File[] files = file.listFiles();
+                    if (files != null && files.length > 0) {
+                        for (File aFile : files) {
+                            if (aFile.getName().endsWith(".shp")) {
+                                shpList.add(aFile.getAbsolutePath());
+                            } else if (aFile.isDirectory()) {
+                                newDirs = newDirs == null ? new ArrayList<>() : newDirs;
+                                newDirs.add(aFile.getAbsolutePath());
+                            }
+                        }
+                    }
+
+                }
+                dirs = newDirs;
+            } else {
+                break;
+            }
+        }
+        return shpList;
+    }
+
+    public static class ShpGeomWithAttr {
+        private Geometry geometry;
+        private Map<String, Object> properties;
+
+        public ShpGeomWithAttr(Geometry geometry, Map<String, Object> properties) {
+            this.geometry = geometry;
+            this.properties = properties;
+        }
+
+        public Geometry getGeometry() {
+            return geometry;
+        }
+
+        public void setGeometry(Geometry geometry) {
+            this.geometry = geometry;
+        }
+
+        public Map<String, Object> getProperties() {
+            return properties;
+        }
+
+        public void setProperties(Map<String, Object> properties) {
+            this.properties = properties;
+        }
+    }
+
+    public static class GeomAttrWrapper {
+        private Map<String, List<ShpGeomWithAttr>> geoMap;
+        private Map<String, Class> attrTypeMap;
+        private Map<String, Envelope> bboxMap;
+
+        public GeomAttrWrapper(Map<String, List<ShpGeomWithAttr>> geoMap, Map<String, Class> attrTypeMap, Map<String, Envelope> bboxMap) {
+            this.geoMap = geoMap;
+            this.attrTypeMap = attrTypeMap;
+            this.bboxMap = bboxMap;
+        }
+
+        public Map<String, List<ShpGeomWithAttr>> getGeoMap() {
+            return geoMap;
+        }
+
+        public void setGeoMap(Map<String, List<ShpGeomWithAttr>> geoMap) {
+            this.geoMap = geoMap;
+        }
+
+        public Map<String, Class> getAttrTypeMap() {
+            return attrTypeMap;
+        }
+
+        public void setAttrTypeMap(Map<String, Class> attrTypeMap) {
+            this.attrTypeMap = attrTypeMap;
+        }
+
+        public Map<String, Envelope> getBboxMap() {
+            return bboxMap;
+        }
+
+        public void setBboxMap(Map<String, Envelope> bboxMap) {
+            this.bboxMap = bboxMap;
+        }
+    }
+
+}

+ 24 - 0
onemap-modules/onemap-spatial/src/main/resources/mapper/postgresql/ShpFileMapper.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.onemap.spatial.mapper.ShpFileMapper">
+
+    <update id="createTable">
+        CREATE TABLE IF NOT EXISTS "${tableName}" (
+        <foreach collection="tableMap" item="item" separator=",">
+            "${item.key}" ${item.value}
+        </foreach>
+        )
+    </update>
+
+    <insert id="insertTableData">
+        insert into "${tableName}"
+        VALUES(
+        <foreach collection="tableDataMap" item="v">
+            #{v},
+        </foreach>
+        ${ewkt}
+        )
+    </insert>
+
+</mapper>