diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/trainingdata/TrainingDataLabelRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/trainingdata/TrainingDataLabelRepositoryImpl.java index 0107e0cc..4cceef1b 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/trainingdata/TrainingDataLabelRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/trainingdata/TrainingDataLabelRepositoryImpl.java @@ -14,9 +14,13 @@ import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.ChangeDetect import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.ClassificationInfo; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.DetailRes; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.GeoFeatureRequest.Properties; +import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.InferenceDataGeometry; +import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.InferenceDataGeometry.InferenceProperties; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.InspectionResultInfo; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingGeometryInfo; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LabelingListDto; +import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LearnDataGeometry; +import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.LearnDataGeometry.LearnProperties; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.SummaryRes; import com.kamco.cd.kamcoback.trainingdata.dto.TrainingDataLabelDto.searchReq; import com.querydsl.core.types.Projections; @@ -456,29 +460,23 @@ public class TrainingDataLabelRepositoryImpl extends QuerydslRepositorySupport .build(); // 6. Geometry를 GeoJSON으로 변환 - JsonNode geomJson = null; - if (mapSheetAnalDataInferenceGeomEntityEntity.getGeom() != null) { - try { - String geomString = - queryFactory - .select( + InferenceDataGeometry inferData = + queryFactory + .select( + Projections.constructor( + InferenceDataGeometry.class, + Expressions.stringTemplate("{0}", "Feature"), Expressions.stringTemplate( - "ST_AsGeoJSON({0})", mapSheetAnalDataInferenceGeomEntity.geom)) - .from(mapSheetAnalDataInferenceGeomEntity) - .where( - mapSheetAnalDataInferenceGeomEntity.geoUid.eq( - mapSheetAnalDataInferenceGeomEntityEntity.getGeoUid())) - .fetchOne(); - - if (geomString != null) { - ObjectMapper mapper = new ObjectMapper(); - geomJson = mapper.readTree(geomString); - } - } catch (Exception e) { - System.err.println("GeoJSON parsing error: " + e.getMessage()); - // JSON 파싱 실패 시 null 유지 - } - } + "ST_AsGeoJSON({0})", mapSheetAnalDataInferenceGeomEntity.geom), + Projections.constructor( + InferenceProperties.class, + mapSheetAnalDataInferenceGeomEntity.classBeforeCd, + mapSheetAnalDataInferenceGeomEntity.classAfterCd))) + .from(mapSheetAnalDataInferenceGeomEntity) + .where( + mapSheetAnalDataInferenceGeomEntity.geoUid.eq( + mapSheetAnalDataInferenceGeomEntityEntity.getGeoUid())) + .fetchOne(); // 도엽 bbox json으로 가져오기 JsonNode mapBbox = null; @@ -500,37 +498,33 @@ public class TrainingDataLabelRepositoryImpl extends QuerydslRepositorySupport } // 7. 라벨링 저장한 Geometry를 GeoJSON으로 변환 - JsonNode learnJson = null; - try { - String learnString = - queryFactory - .select( - Expressions.stringTemplate( - "ST_AsGeoJSON({0})", mapSheetLearnDataGeomEntity.geom)) - .from(mapSheetLearnDataGeomEntity) - .where( - mapSheetLearnDataGeomEntity.geoUid.eq( - mapSheetAnalDataInferenceGeomEntityEntity.getGeoUid())) - .fetchOne(); - - if (learnString != null) { - ObjectMapper mapper = new ObjectMapper(); - learnJson = mapper.readTree(learnString); - } - } catch (Exception e) { - System.err.println("learnJson parsing error: " + e.getMessage()); - // JSON 파싱 실패 시 null 유지 - } + LearnDataGeometry learnData = + queryFactory + .select( + Projections.constructor( + LearnDataGeometry.class, + Expressions.stringTemplate("{0}", "Feature"), + Expressions.stringTemplate( + "ST_AsGeoJSON({0})", mapSheetLearnDataGeomEntity.geom), + Projections.constructor( + LearnProperties.class, + mapSheetLearnDataGeomEntity.classBeforeCd, + mapSheetLearnDataGeomEntity.classAfterCd))) + .from(mapSheetLearnDataGeomEntity) + .where( + mapSheetLearnDataGeomEntity.geoUid.eq( + mapSheetAnalDataInferenceGeomEntityEntity.getGeoUid())) + .fetchOne(); return DetailRes.builder() .assignmentUid(assignmentUid) .changeDetectionInfo(changeDetectionInfo) .inspectionResultInfo(inspectionResultInfo) - .geom(geomJson) + .geom(inferData) .beforeCogUrl(beforeCogUrl) .afterCogUrl(afterCogUrl) .mapBox(mapBbox) - .learnGeometry(learnJson) + .learnGeometry(learnData) .build(); } catch (Exception e) { diff --git a/src/main/java/com/kamco/cd/kamcoback/trainingdata/dto/TrainingDataLabelDto.java b/src/main/java/com/kamco/cd/kamcoback/trainingdata/dto/TrainingDataLabelDto.java index 278cfa20..e56f647e 100644 --- a/src/main/java/com/kamco/cd/kamcoback/trainingdata/dto/TrainingDataLabelDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/trainingdata/dto/TrainingDataLabelDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.kamco.cd.kamcoback.common.utils.geometry.GeometryDeserializer; import io.swagger.v3.oas.annotations.media.Schema; import java.util.UUID; @@ -159,6 +160,91 @@ public class TrainingDataLabelDto { } } + @Schema(name = "InferenceDataGeometry", description = "InferenceDataGeometry") + @Getter + @Setter + @NoArgsConstructor + public static class InferenceDataGeometry { + + private String type; + @JsonIgnore private String learnGeomString; + private JsonNode geometry; + private InferenceProperties properties; + + public InferenceDataGeometry( + String type, String learnGeomString, InferenceProperties properties) { + this.type = type; + this.properties = properties; + ObjectMapper mapper = new ObjectMapper(); + JsonNode inferenceJson; + try { + inferenceJson = mapper.readTree(learnGeomString); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + this.geometry = inferenceJson; + + if (inferenceJson.isObject()) { + ((ObjectNode) inferenceJson).remove("crs"); + } + } + + @Getter + @Setter + @NoArgsConstructor + @AllArgsConstructor + public static class InferenceProperties { + + @Schema(description = "beforeClass", example = "WASTE") + private String beforeClass; + + @Schema(description = "afterClass", example = "LAND") + private String afterClass; + } + } + + @Schema(name = "LearnDataGeometry", description = "LearnDataGeometry") + @Getter + @Setter + @NoArgsConstructor + public static class LearnDataGeometry { + + private String type; + @JsonIgnore private String learnGeomString; + private JsonNode geometry; + private LearnProperties properties; + + public LearnDataGeometry(String type, String learnGeomString, LearnProperties properties) { + this.type = type; + this.properties = properties; + ObjectMapper mapper = new ObjectMapper(); + JsonNode learnJson; + try { + learnJson = mapper.readTree(learnGeomString); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + this.geometry = learnJson; + + if (learnJson.isObject()) { + ((ObjectNode) learnJson).remove("crs"); + } + } + + @Getter + @Setter + @NoArgsConstructor + @AllArgsConstructor + public static class LearnProperties { + + @Schema(description = "beforeClass", example = "WASTE") + private String beforeClass; + + @Schema(description = "afterClass", example = "LAND") + private String afterClass; + } + } + @Schema(name = "searchReq", description = "검색 요청") @Getter @Setter @@ -201,7 +287,7 @@ public class TrainingDataLabelDto { private InspectionResultInfo inspectionResultInfo; @Schema(description = "Geometry (GeoJSON)") - private JsonNode geom; + private InferenceDataGeometry geom; @Schema(description = "변화 전 COG 이미지 URL") private String beforeCogUrl; @@ -213,7 +299,7 @@ public class TrainingDataLabelDto { private JsonNode mapBox; @Schema(description = "라벨링 툴에서 그린 폴리곤") - private JsonNode learnGeometry; + private LearnDataGeometry learnGeometry; } @Schema(name = "ChangeDetectionInfo", description = "변화탐지정보")