PolygonData -> JsonNode 변환 예제 커밋
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package com.kamco.cd.kamcoback.changedetection;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
|
||||
import com.kamco.cd.kamcoback.changedetection.service.ChangeDetectionService;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "변화탐지", description = "변화탐지 API")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@@ -20,8 +23,19 @@ public class ChangeDetectionApiController {
|
||||
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
|
||||
@Hidden
|
||||
@Deprecated
|
||||
@GetMapping
|
||||
public ApiResponseDto<List<ChangeDetectionDto>> getPolygonToPoint() {
|
||||
public ApiResponseDto<List<ChangeDetectionDto.TestDto>> getPolygonToPoint() {
|
||||
return ApiResponseDto.ok(changeDetectionService.getPolygonToPoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* PolygonData -> JsonNode 변환 예제
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/json-data")
|
||||
public ApiResponseDto<List<JsonNode>> getPolygonToJson(){
|
||||
return ApiResponseDto.ok(changeDetectionService.getPolygonToJson());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,74 @@
|
||||
package com.kamco.cd.kamcoback.changedetection.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
public record ChangeDetectionDto(Long id, Geometry polygon, double centroidX, double centroidY) {}
|
||||
public class ChangeDetectionDto{
|
||||
|
||||
@Schema(name = "TestDto", description = "테스트용")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TestDto {
|
||||
private Long id;
|
||||
private Geometry polygon;
|
||||
private Double centroidX;;
|
||||
private Double centroidY;
|
||||
}
|
||||
|
||||
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PointGeometry{
|
||||
private Long geoUid;
|
||||
private String type; // "Point"
|
||||
private Geometry coordinates; //Point 값
|
||||
private String before_class; //기준 분류
|
||||
private String after_class; //비교 분류
|
||||
}
|
||||
|
||||
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PolygonGeometry{
|
||||
private Long geoUid;
|
||||
private String type; // "MultiPolygon"
|
||||
private Geometry coordinates; //Polygon 값
|
||||
private Double center_latitude; //폴리곤 중심 위도
|
||||
private Double center_longitude; //폴리곤 중심 경도
|
||||
}
|
||||
|
||||
@Schema(name = "CogURL", description = "COG URL")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class CogURL{
|
||||
private String before_cog_url; //기준 COG URL
|
||||
private String after_cog_url; //비교 COG URL
|
||||
}
|
||||
|
||||
@Schema(name = "PolygonProperties", description = "폴리곤 정보")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PolygonProperties{
|
||||
private Double area; //면적
|
||||
private String before_year; //기준년도
|
||||
private Double before_confidence; //기준 신뢰도(확률)
|
||||
private String before_class; //기준 분류
|
||||
private String after_year; //비교년도
|
||||
private Double after_confidence; //비교 신뢰도(확률)
|
||||
private String after_class; //비교 분류
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.changedetection.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.ChangeDetectionCoreService;
|
||||
import java.util.List;
|
||||
@@ -12,7 +13,11 @@ public class ChangeDetectionService {
|
||||
|
||||
private final ChangeDetectionCoreService changeDetectionCoreService;
|
||||
|
||||
public List<ChangeDetectionDto> getPolygonToPoint() {
|
||||
public List<ChangeDetectionDto.TestDto> getPolygonToPoint() {
|
||||
return changeDetectionCoreService.getPolygonToPoint();
|
||||
}
|
||||
|
||||
public List<JsonNode> getPolygonToJson(){
|
||||
return changeDetectionCoreService.getPolygonToJson();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.changedetection.ChangeDetectionRepository;
|
||||
@@ -16,7 +19,7 @@ public class ChangeDetectionCoreService {
|
||||
|
||||
private final ChangeDetectionRepository changeDetectionRepository;
|
||||
|
||||
public List<ChangeDetectionDto> getPolygonToPoint() {
|
||||
public List<ChangeDetectionDto.TestDto> getPolygonToPoint() {
|
||||
List<MapSheetAnalDataGeomEntity> list = changeDetectionRepository.findAll();
|
||||
|
||||
return list.stream()
|
||||
@@ -26,7 +29,23 @@ public class ChangeDetectionCoreService {
|
||||
// 중심 좌표 계산
|
||||
Point centroid = polygon.getCentroid();
|
||||
|
||||
return new ChangeDetectionDto(p.getId(), polygon, centroid.getX(), centroid.getY());
|
||||
return new ChangeDetectionDto.TestDto(p.getId(), polygon, centroid.getX(), centroid.getY());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<JsonNode> getPolygonToJson() {
|
||||
List<String> list = changeDetectionRepository.findPolygonJson();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
return list.stream()
|
||||
.map(
|
||||
s -> {
|
||||
try {
|
||||
return mapper.readTree(s);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChangeDetectionRepositoryCustom {
|
||||
|
||||
String getPolygonToPoint();
|
||||
|
||||
List<String> findPolygonJson();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
@@ -23,9 +24,13 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MapSheetAnalDataGeomEntity> findAll() {
|
||||
@Override
|
||||
public List<String> findPolygonJson(){
|
||||
return queryFactory
|
||||
.selectFrom(mapSheetAnalDataGeomEntity)
|
||||
.select(
|
||||
Expressions.stringTemplate("ST_AsGeoJSON({0})", mapSheetAnalDataGeomEntity.geom)
|
||||
)
|
||||
.from(mapSheetAnalDataGeomEntity)
|
||||
.orderBy(mapSheetAnalDataGeomEntity.id.desc())
|
||||
.fetch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user