변화탐지 polygon, point 4326 으로 변환

This commit is contained in:
2025-12-01 11:06:02 +09:00
parent c40b3015c6
commit cf33d7378f
7 changed files with 136 additions and 51 deletions

View File

@@ -75,7 +75,7 @@ public class ChangeDetectionApiController {
@Operation(summary = "변화탐지 결과 Polygon", description = "변화탐지 결과 Polygon")
@GetMapping("/polygon")
public ApiResponseDto<List<ChangeDetectionDto.PolygonGeometry>> getChangeDetectionPolygonList(
public ApiResponseDto<ChangeDetectionDto.PolygonFeatureList> getChangeDetectionPolygonList(
@Parameter(description = "년도목록 id", example = "1") @RequestParam Long analUid,
@Parameter(description = "도엽번호", example = "34602060") @RequestParam String mapSheetNum) {
return ApiResponseDto.ok(
@@ -84,7 +84,7 @@ public class ChangeDetectionApiController {
@Operation(summary = "변화탐지 결과 Point", description = "변화탐지 결과 Point")
@GetMapping("/point")
public ApiResponseDto<List<ChangeDetectionDto.PointGeometry>> getChangeDetectionPointList(
public ApiResponseDto<List<ChangeDetectionDto.PointFeature>> getChangeDetectionPointList(
@Parameter(description = "년도목록 id", example = "1") @RequestParam Long analUid,
@Parameter(description = "도엽번호", example = "34602060") @RequestParam String mapSheetNum) {
return ApiResponseDto.ok(

View File

@@ -1,6 +1,7 @@
package com.kamco.cd.kamcoback.changedetection.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -78,31 +79,54 @@ public class ChangeDetectionDto {
private String alias;
}
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
@Schema(name = "PolygonFeatureList", description = "Geometry 리턴 객체")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PointGeometry {
private Long geoUid;
private Geometry geometry; // Point 값
public static class PolygonFeatureList {
private String type;
private List<PolygonFeature> features; // Point 값
private String classCd; // after 분류
}
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
@Schema(name = "PolygonFeature", description = "Geometry 리턴 객체")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PolygonGeometry {
public static class PolygonFeature {
private String type;
private Geometry geometry; // after 분류
private PolygonProperties properties; // Point 값
}
@Schema(name = "PointFeature", description = "Geometry 리턴 객체")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PointFeature {
private String type;
private Geometry geometry; // point
private PointProperties properties; // Point 정보
}
@Schema(name = "PointProperties", description = "폴리곤 리턴 객체")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PointProperties {
private Long geoUid;
private Geometry geometry; // Polygon 값
private PolygonProperties properties;
private String classCd; // after 분류
}
@Schema(name = "PolygonProperties", description = "폴리곤 정보")
@Getter
@AllArgsConstructor
public static class PolygonProperties {
private Long geoUid;
private Double area; // 면적
private Integer beforeYear; // 기준년도
private Double beforeConfidence; // 기준 신뢰도(확률)

View File

@@ -34,12 +34,12 @@ public class ChangeDetectionService {
return changeDetectionCoreService.getChangeDetectionYearList();
}
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
public ChangeDetectionDto.PolygonFeatureList getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return changeDetectionCoreService.getChangeDetectionPolygonList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
public List<ChangeDetectionDto.PointFeature> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return changeDetectionCoreService.getChangeDetectionPointList(analUid, mapSheetNum);
}

View File

@@ -31,10 +31,10 @@ public class ErrorLogApiController {
@RequestParam(required = false) LocalDate endDate,
@RequestParam int page,
@RequestParam(defaultValue = "20") int size) {
ErrorLogDto.ErrorSearchReq searchReq =
new ErrorLogDto.ErrorSearchReq(
logErrorLevel, eventType, startDate, endDate, page, size, "created_dttm,desc");
Page<ErrorLogDto.Basic> result = errorLogService.findLogByError(searchReq);
return ApiResponseDto.ok(result);
ErrorLogDto.ErrorSearchReq searchReq =
new ErrorLogDto.ErrorSearchReq(
logErrorLevel, eventType, startDate, endDate, page, size, "created_dttm,desc");
Page<ErrorLogDto.Basic> result = errorLogService.findLogByError(searchReq);
return ApiResponseDto.ok(result);
}
}

View File

@@ -76,12 +76,12 @@ public class ChangeDetectionCoreService {
return changeDetectionRepository.getChangeDetectionYearList();
}
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
public ChangeDetectionDto.PolygonFeatureList getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return changeDetectionRepository.getChangeDetectionPolygonList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
public List<ChangeDetectionDto.PointFeature> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return changeDetectionRepository.getChangeDetectionPointList(analUid, mapSheetNum);
}

View File

@@ -15,10 +15,10 @@ public interface ChangeDetectionRepositoryCustom {
List<ChangeDetectionDto.AnalYearList> getChangeDetectionYearList();
List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
ChangeDetectionDto.PolygonFeatureList getChangeDetectionPolygonList(
Long analUid, String mapSheetNum);
List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
List<ChangeDetectionDto.PointFeature> getChangeDetectionPointList(
Long analUid, String mapSheetNum);
List<ChangeDetectionDto.MapSheetList> getChangeDetectionMapSheetList(Long analUid);

View File

@@ -10,6 +10,9 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalSttcEntity.map
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataGeomEntity;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.Expressions;
@@ -17,6 +20,9 @@ import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.stream.Collectors;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.geojson.GeoJsonReader;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
@@ -105,43 +111,79 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
}
@Override
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
public ChangeDetectionDto.PolygonFeatureList getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.PolygonGeometry.class,
List<Tuple> list =
queryFactory
.select(
Expressions.stringTemplate(
"ST_AsGeoJSON(ST_Transform({0}, 4326))", mapSheetAnalDataGeomEntity.geom),
mapSheetAnalDataGeomEntity.id,
mapSheetAnalDataGeomEntity.geom, // polygon
Projections.constructor(
ChangeDetectionDto.PolygonProperties.class,
mapSheetAnalDataGeomEntity.area,
mapSheetAnalDataGeomEntity.compareYyyy,
mapSheetAnalDataGeomEntity.classBeforeProb,
mapSheetAnalDataGeomEntity.classBeforeCd.toUpperCase(),
mapSheetAnalDataGeomEntity.targetYyyy,
mapSheetAnalDataGeomEntity.classAfterProb,
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase())))
.from(mapSheetAnalDataGeomEntity)
.where(
mapSheetAnalDataGeomEntity.dataUid.in(
JPAExpressions.select(mapSheetAnalDataEntity.id)
.from(mapSheetAnalDataEntity)
.where(mapSheetAnalDataEntity.analUid.eq(analUid))),
mapSheetAnalDataGeomEntity.mapSheetNum.eq(Long.valueOf(mapSheetNum)))
.fetch();
mapSheetAnalDataGeomEntity.area,
mapSheetAnalDataGeomEntity.compareYyyy,
mapSheetAnalDataGeomEntity.classBeforeProb,
mapSheetAnalDataGeomEntity.classBeforeCd.toUpperCase(),
mapSheetAnalDataGeomEntity.targetYyyy,
mapSheetAnalDataGeomEntity.classAfterProb,
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase())
.from(QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity)
.where(
QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity.dataUid.in(
JPAExpressions.select(QMapSheetAnalDataEntity.mapSheetAnalDataEntity.id)
.from(QMapSheetAnalDataEntity.mapSheetAnalDataEntity)
.where(QMapSheetAnalDataEntity.mapSheetAnalDataEntity.analUid.eq(analUid))),
QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity.mapSheetNum.eq(
Long.valueOf(mapSheetNum)))
.fetch();
GeoJsonReader reader = new GeoJsonReader();
List<ChangeDetectionDto.PolygonFeature> result =
list.stream()
.map(
tuple -> {
String geojson = tuple.get(0, String.class);
Geometry geom;
try {
geom = reader.read(geojson);
} catch (Exception ex) {
throw new RuntimeException("GeoJSON -> Geometry 변환 실패", ex);
}
ChangeDetectionDto.PolygonProperties properties =
new ChangeDetectionDto.PolygonProperties(
tuple.get(mapSheetAnalDataGeomEntity.id).longValue(),
tuple.get(mapSheetAnalDataGeomEntity.area).doubleValue(),
tuple.get(mapSheetAnalDataGeomEntity.compareYyyy).intValue(),
tuple.get(mapSheetAnalDataGeomEntity.classBeforeProb).doubleValue(),
tuple
.get(mapSheetAnalDataGeomEntity.classBeforeCd.toUpperCase())
.toString(),
tuple.get(mapSheetAnalDataGeomEntity.targetYyyy).intValue(),
tuple.get(mapSheetAnalDataGeomEntity.classAfterProb).doubleValue(),
tuple
.get(mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase())
.toString());
return new ChangeDetectionDto.PolygonFeature("Feature", geom, properties);
})
.collect(Collectors.toList());
ChangeDetectionDto.PolygonFeatureList polygonList = new ChangeDetectionDto.PolygonFeatureList();
polygonList.setType("FeatureCollection");
polygonList.setFeatures(result);
return polygonList;
}
@Override
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
public List<ChangeDetectionDto.PointFeature> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return queryFactory
List<Tuple> list = queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.PointGeometry.class,
mapSheetAnalDataGeomEntity.id,
mapSheetAnalDataGeomEntity.geomCenter, // point
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase()))
Expressions.stringTemplate(
"ST_AsGeoJSON(ST_Transform({0}, 4326))", mapSheetAnalDataGeomEntity.geomCenter),
mapSheetAnalDataGeomEntity.id,
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase()
)
.from(mapSheetAnalDataGeomEntity)
.where(
mapSheetAnalDataGeomEntity.dataUid.in(
@@ -150,6 +192,25 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
.where(mapSheetAnalDataEntity.analUid.eq(analUid))),
mapSheetAnalDataGeomEntity.mapSheetNum.eq(Long.valueOf(mapSheetNum)))
.fetch();
GeoJsonReader reader = new GeoJsonReader();
return list.stream()
.map(
tuple -> {
String geojson = tuple.get(0, String.class);
Geometry geom;
try {
geom = reader.read(geojson);
} catch (Exception ex) {
throw new RuntimeException("GeoJSON -> Geometry 변환 실패", ex);
}
Long geoUid = tuple.get(mapSheetAnalDataGeomEntity.id).longValue();
String classCd = tuple.get(mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase()).toString();
return new ChangeDetectionDto.PointFeature("Feature", geom, new ChangeDetectionDto.PointProperties(geoUid, classCd));
}
).collect(Collectors.toList());
}
@Override