|
@@ -1,7 +1,10 @@
|
|
package com.shkpr.service.alambizplugin.commtools;
|
|
package com.shkpr.service.alambizplugin.commtools;
|
|
|
|
|
|
|
|
+import com.global.base.log.LogLevelFlag;
|
|
|
|
+import com.global.base.log.LogPrintMgr;
|
|
import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
|
|
import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
|
|
|
|
+import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
import org.geotools.data.Transaction;
|
|
import org.geotools.data.Transaction;
|
|
import org.geotools.data.collection.ListFeatureCollection;
|
|
import org.geotools.data.collection.ListFeatureCollection;
|
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
|
@@ -11,7 +14,7 @@ import org.geotools.feature.simple.SimpleFeatureBuilder;
|
|
import org.opengis.feature.simple.SimpleFeatureType;
|
|
import org.opengis.feature.simple.SimpleFeatureType;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.Serializable;
|
|
|
|
|
|
+import java.nio.charset.Charset;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -27,8 +30,19 @@ import java.util.stream.Collectors;
|
|
* @since 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
*/
|
|
public class ShapeUtils {
|
|
public class ShapeUtils {
|
|
- //缓存库工厂
|
|
|
|
|
|
+ /**
|
|
|
|
+ * log
|
|
|
|
+ */
|
|
|
|
+ private static final String mStrClassName = "ShapeUtils";
|
|
|
|
+ private static final String mBizType = LogFlagBusiType.BUSI_GIS_SURVEY.toStrValue();
|
|
|
|
+ /**
|
|
|
|
+ * 缓存库工厂
|
|
|
|
+ */
|
|
private static final ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
|
|
private static final ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
|
|
|
|
+ /**
|
|
|
|
+ * 编码
|
|
|
|
+ */
|
|
|
|
+ private static final Charset charset = Charset.forName("GB18030");
|
|
|
|
|
|
/**
|
|
/**
|
|
* 输出shape文件
|
|
* 输出shape文件
|
|
@@ -79,11 +93,17 @@ public class ShapeUtils {
|
|
* @throws IOException io异常
|
|
* @throws IOException io异常
|
|
*/
|
|
*/
|
|
public static void writeShape(final SimpleFeatureType TYPE, List<Map<String, Object>> data, Path filePath) throws IOException {
|
|
public static void writeShape(final SimpleFeatureType TYPE, List<Map<String, Object>> data, Path filePath) throws IOException {
|
|
- //特征构建
|
|
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
|
|
+ , String.format(
|
|
|
|
+ "开始构建特征,类型:%s========>"
|
|
|
|
+ , TYPE.getTypeName()
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ //根据类型创建特征构建器
|
|
final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
|
|
final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
|
|
//特征集合
|
|
//特征集合
|
|
ListFeatureCollection collection = new ListFeatureCollection(TYPE);
|
|
ListFeatureCollection collection = new ListFeatureCollection(TYPE);
|
|
- //遍历数据
|
|
|
|
|
|
+ //遍历数据,构建特征集合
|
|
data.forEach(it -> {
|
|
data.forEach(it -> {
|
|
//设置geom
|
|
//设置geom
|
|
featureBuilder.set(GisSurveyExcelDefine.FILE.THE_GEOM, it.get(GisSurveyExcelDefine.FILE.THE_GEOM));
|
|
featureBuilder.set(GisSurveyExcelDefine.FILE.THE_GEOM, it.get(GisSurveyExcelDefine.FILE.THE_GEOM));
|
|
@@ -93,15 +113,25 @@ public class ShapeUtils {
|
|
});
|
|
});
|
|
collection.add(featureBuilder.buildFeature(null));
|
|
collection.add(featureBuilder.buildFeature(null));
|
|
});
|
|
});
|
|
|
|
+ //释放数据
|
|
|
|
+ data.clear();
|
|
|
|
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
|
|
+ , String.format(
|
|
|
|
+ "开启shapefile缓存库,开始写入,类型:%s========>"
|
|
|
|
+ , TYPE.getTypeName()
|
|
|
|
+ )
|
|
|
|
+ );
|
|
//从文件构建数据缓存库
|
|
//从文件构建数据缓存库
|
|
- Map<String, Serializable> params = new HashMap<>();
|
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
params.put(ShapefileDataStoreFactory.URLP.key, filePath.toUri().toURL());
|
|
params.put(ShapefileDataStoreFactory.URLP.key, filePath.toUri().toURL());
|
|
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
|
|
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
|
|
- params.put(ShapefileDataStoreFactory.DBFCHARSET.key, "GB18030");
|
|
|
|
|
|
+ params.put(ShapefileDataStoreFactory.MEMORY_MAPPED.key, Boolean.TRUE);
|
|
|
|
|
|
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createDataStore(params);
|
|
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createDataStore(params);
|
|
dataStore.createSchema(TYPE);
|
|
dataStore.createSchema(TYPE);
|
|
|
|
+ dataStore.setCharset(charset);
|
|
|
|
+ dataStore.setTryCPGFile(true);
|
|
|
|
|
|
//启动事务
|
|
//启动事务
|
|
try (Transaction transaction = Transaction.AUTO_COMMIT) {
|
|
try (Transaction transaction = Transaction.AUTO_COMMIT) {
|
|
@@ -113,5 +143,15 @@ public class ShapeUtils {
|
|
//写入特征集合
|
|
//写入特征集合
|
|
featureStore.addFeatures(collection);
|
|
featureStore.addFeatures(collection);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //释放资源
|
|
|
|
+ collection.clear();
|
|
|
|
+ dataStore.dispose();
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
|
|
|
|
+ , String.format(
|
|
|
|
+ "释放shapefile缓存库,结束写入,类型:%s========>"
|
|
|
|
+ , TYPE.getTypeName()
|
|
|
|
+ )
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|