yanghb
2024-12-24 fe6e43d5e1144156d0ca4e9d6080c9821c25d97c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//package com.zzg.common.utils;
//
//import org.geotools.data.DataStore;
//import org.geotools.data.DataStoreFinder;
//import org.geotools.data.simple.SimpleFeatureSource;
//import org.geotools.feature.FeatureIterator;
//import org.opengis.feature.simple.SimpleFeature;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 安全服务工具类
// *
// * @author ruoyi
// */
//public class ShpUtils {
//
//    public static void main(String[] args) {
//        File file = new File("D:/Work/青白江土地征收整改/shp数据/大弯/大弯街道.shp");
//
//        shpToPostgis(file);
//    }
//
//
//    public static void shpToPostgis(File file) {
//        DataStore dataStore = null;
//        try {
//            // 读取 shp 文件
//            Map map = new HashMap<>();
//            map.put("url", file.toURI().toURL());// 必须是URL类型
//            dataStore = DataStoreFinder.getDataStore(map);
//            SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
//
//            // 插入数据到数据库表
//            FeatureIterator<SimpleFeature> features = featureSource.getFeatures().features();
//            while (features.hasNext()) {
//                SimpleFeature feature = features.next();
//                System.out.println("getDefaultGeometry:" + feature.getDefaultGeometry());
//                System.out.println("getAttribute:" + feature.getAttribute("other_column"));
//            }
//            features.close();
//            System.out.println("Shp file imported successfully!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            // 关闭连接和数据存储
//            if (dataStore != null) {
//                dataStore.dispose();
//            }
//        }
//
//    }
//
//}