shp 파일 생성 수정
This commit is contained in:
@@ -55,7 +55,7 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
* <p>- geometry 타입은 첫 번째 유효 geometry 기준으로 스키마를 생성한다. - 좌표계는 EPSG:5186으로 설정하며, .prj 파일을 직접 생성한다.
|
||||
*
|
||||
* @param shpBasePath 확장자를 제외한 SHP 파일 기본 경로
|
||||
* @param rows 동일 그룹(stage, mapId, input1, input2)의 데이터 목록
|
||||
* @param rows 동일 그룹(stage, mapId, input1, input2)의 데이터 목록
|
||||
* @return 이번 호출로 write(생성/덮어쓰기)가 수행된 파일 개수
|
||||
*/
|
||||
@Override
|
||||
@@ -123,11 +123,10 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
* 생성된다. - geometry는 GeoTools GeometryJSON을 사용하여 직렬화한다.
|
||||
*
|
||||
* <p>GeoJSON 구조 예: { "type": "FeatureCollection", "name": "stage_input1_input2_mapId", "crs": {
|
||||
* "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::5186" } }, "properties": { ...
|
||||
* }, "features": [ ... ] }
|
||||
* "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::5186" } }, "properties": { ... }, "features": [ ... ] }
|
||||
*
|
||||
* @param geoJsonPath 생성할 GeoJSON 파일의 전체 경로 (.geojson 포함)
|
||||
* @param rows 동일 그룹(stage, mapId, input1, input2)의 데이터 목록
|
||||
* @param rows 동일 그룹(stage, mapId, input1, input2)의 데이터 목록
|
||||
* @return 이번 호출로 write(생성/덮어쓰기)가 수행된 파일 개수
|
||||
*/
|
||||
@Override
|
||||
@@ -153,9 +152,9 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
|
||||
// name: stage_input1_input2_mapId
|
||||
String name =
|
||||
String.format(
|
||||
"%d_%d_%d_%d",
|
||||
first.getStage(), first.getInput1(), first.getInput2(), first.getMapId());
|
||||
String.format(
|
||||
"%d_%d_%d_%d",
|
||||
first.getStage(), first.getInput1(), first.getInput2(), first.getMapId());
|
||||
root.put("name", name);
|
||||
|
||||
// CRS (EPSG:5186)
|
||||
@@ -226,7 +225,7 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
|
||||
// 파일 쓰기
|
||||
try (OutputStreamWriter w =
|
||||
new OutputStreamWriter(new FileOutputStream(geoJsonFile), GEOJSON_CHARSET)) {
|
||||
new OutputStreamWriter(new FileOutputStream(geoJsonFile), GEOJSON_CHARSET)) {
|
||||
om.writerWithDefaultPrettyPrinter().writeValue(w, root);
|
||||
}
|
||||
|
||||
@@ -250,7 +249,7 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
}
|
||||
|
||||
private SimpleFeatureType createSchema(
|
||||
Class<? extends Geometry> geomType, CoordinateReferenceSystem crs) {
|
||||
Class<? extends Geometry> geomType, CoordinateReferenceSystem crs) {
|
||||
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
|
||||
b.setName("inference_result");
|
||||
b.setCRS(crs);
|
||||
@@ -273,14 +272,25 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
return b.buildFeatureType();
|
||||
}
|
||||
|
||||
/**
|
||||
* .shp .shx .dbf .fix 파일 생성 (껍데기 생성)
|
||||
*
|
||||
* @param shpFile
|
||||
* @param schema
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private ShapefileDataStore createDataStore(File shpFile, SimpleFeatureType schema)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
|
||||
Map<String, Serializable> params = new HashMap<>();
|
||||
params.put("url", shpFile.toURI().toURL());
|
||||
params.put("create spatial index", Boolean.TRUE);
|
||||
|
||||
// .fix 파일 생성 Boolean.TRUE, 미생성 Boolean.FALSE
|
||||
params.put("create spatial index", Boolean.FALSE);
|
||||
|
||||
ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
|
||||
|
||||
ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(params);
|
||||
|
||||
dataStore.setCharset(DBF_CHARSET);
|
||||
@@ -290,7 +300,7 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
}
|
||||
|
||||
private DefaultFeatureCollection buildFeatureCollection(
|
||||
SimpleFeatureType schema, List<InferenceResultShpDto.Basic> rows) {
|
||||
SimpleFeatureType schema, List<InferenceResultShpDto.Basic> rows) {
|
||||
DefaultFeatureCollection collection = new DefaultFeatureCollection();
|
||||
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
|
||||
|
||||
@@ -308,10 +318,10 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
builder.add(dto.getArea() != null ? dto.getArea().doubleValue() : null);
|
||||
builder.add(dto.getBeforeClass());
|
||||
builder.add(
|
||||
dto.getBeforeProbability() != null ? dto.getBeforeProbability().doubleValue() : null);
|
||||
dto.getBeforeProbability() != null ? dto.getBeforeProbability().doubleValue() : null);
|
||||
builder.add(dto.getAfterClass());
|
||||
builder.add(
|
||||
dto.getAfterProbability() != null ? dto.getAfterProbability().doubleValue() : null);
|
||||
dto.getAfterProbability() != null ? dto.getAfterProbability().doubleValue() : null);
|
||||
|
||||
SimpleFeature feature = builder.buildFeature(null);
|
||||
collection.add(feature);
|
||||
@@ -322,7 +332,7 @@ public class GeoToolsShpWriter implements ShpWriter {
|
||||
}
|
||||
|
||||
private void writeFeatures(ShapefileDataStore dataStore, DefaultFeatureCollection collection)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
|
||||
String typeName = dataStore.getTypeNames()[0];
|
||||
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
|
||||
|
||||
@@ -16,7 +16,9 @@ public class InferenceResultShpService {
|
||||
private final InferenceResultShpCoreService coreService;
|
||||
private final ShpWriter shpWriter;
|
||||
|
||||
/** inference_results 테이블을 기준으로 분석 결과 테이블과 도형 테이블을 최신 상태로 반영한다. */
|
||||
/**
|
||||
* inference_results 테이블을 기준으로 분석 결과 테이블과 도형 테이블을 최신 상태로 반영한다.
|
||||
*/
|
||||
@Transactional
|
||||
public InferenceResultShpDto.InferenceCntDto saveInferenceResultData() {
|
||||
return coreService.buildInferenceData();
|
||||
@@ -33,6 +35,7 @@ public class InferenceResultShpService {
|
||||
@Transactional
|
||||
public InferenceResultShpDto.FileCntDto createShpFile() {
|
||||
|
||||
// TODO 파일 경로는 정해지면 수정, properties 사용
|
||||
String baseDir = System.getProperty("user.home") + "/export";
|
||||
|
||||
int batchSize = 100;
|
||||
@@ -47,7 +50,7 @@ public class InferenceResultShpService {
|
||||
// 재생성을 위한 생성 상태 초기화
|
||||
coreService.resetForRegenerate(dataUid);
|
||||
|
||||
// 도형 데이터 조회
|
||||
// 추론 데이터 조회
|
||||
List<InferenceResultShpDto.Basic> dtoList = coreService.loadGeomDtos(dataUid, geomLimit);
|
||||
if (dtoList.isEmpty()) {
|
||||
continue;
|
||||
@@ -56,15 +59,15 @@ public class InferenceResultShpService {
|
||||
// 파일명 생성 (stage_mapSheet_compare_target)
|
||||
InferenceResultShpDto.Basic first = dtoList.get(0);
|
||||
String baseName =
|
||||
String.format(
|
||||
"%d_%d_%d_%d",
|
||||
first.getStage(), first.getMapId(), first.getInput1(), first.getInput2());
|
||||
String.format(
|
||||
"%d_%d_%d_%d",
|
||||
first.getStage(), first.getMapId(), first.getInput1(), first.getInput2());
|
||||
|
||||
String shpBasePath = baseDir + "/shp/" + baseName;
|
||||
String geoJsonPath = baseDir + "/geojson/" + baseName + ".geojson";
|
||||
|
||||
try {
|
||||
// 폴더 안 파일을 세지 않고, Writer가 "이번 호출에서 write한 개수"를 반환
|
||||
// Writer가 "이번 호출에서 write한 개수"를 반환
|
||||
total = total.plus(shpWriter.writeShp(shpBasePath, dtoList));
|
||||
total = total.plus(shpWriter.writeGeoJson(geoJsonPath, dtoList));
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
public interface ShpWriter {
|
||||
|
||||
// SHP (.shp/.shx/.dbf)
|
||||
// SHP (.shp/.shx/.dbf/.fix)
|
||||
WriteCnt writeShp(String shpBasePath, List<InferenceResultShpDto.Basic> rows);
|
||||
|
||||
// GeoJSON (.geojson)
|
||||
|
||||
Reference in New Issue
Block a user