//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();
|
// }
|
// }
|
//
|
// }
|
//
|
//}
|