wmts 수정

This commit is contained in:
2026-01-30 14:10:22 +09:00
parent 29556b6a05
commit d95dc364aa
4 changed files with 462 additions and 289 deletions

View File

@@ -37,65 +37,63 @@ public class GukYuinApiController {
private final GukYuinApiService gukYuinApiService;
/**
* 탐지결과 등록
*/
/** 탐지결과 등록 */
@Operation(summary = "탐지결과 등록", description = "탐지결과 등록")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = DetectMastReq.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = DetectMastReq.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/chn/mast/regist")
public ApiResponseDto<ChngDetectMastDto.RegistResDto> regist(
@RequestBody @Valid ChngDetectMastDto.ChnDetectMastReqDto chnDetectMastReq) {
@RequestBody @Valid ChngDetectMastDto.ChnDetectMastReqDto chnDetectMastReq) {
return ApiResponseDto.ok(gukYuinApiService.regist(chnDetectMastReq));
}
@Operation(summary = "탐지결과 삭제", description = "탐지결과 삭제")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ChnDetectMastReqDto.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ChnDetectMastReqDto.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/chn/mast/remove")
public ApiResponseDto<ResReturn> remove(
@RequestBody @Valid ChngDetectMastDto.ChnDetectMastReqDto chnDetectMastReq) {
@RequestBody @Valid ChngDetectMastDto.ChnDetectMastReqDto chnDetectMastReq) {
return ApiResponseDto.ok(gukYuinApiService.remove(chnDetectMastReq));
}
@Operation(summary = "탐지결과 등록목록 조회(년도,차수 조회)", description = "탐지결과 등록목록 조회")
@GetMapping("/chn/mast")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectMastDto.ResultDto> selectChangeDetectionList(
@RequestParam(required = false) String cprsYr,
@RequestParam(required = false) String crtrYr,
@RequestParam(required = false) String chnDtctSno) {
@RequestParam(required = false) String cprsYr,
@RequestParam(required = false) String crtrYr,
@RequestParam(required = false) String chnDtctSno) {
ChngDetectMastSearchDto searchDto = new ChngDetectMastSearchDto();
searchDto.setCprsYr(cprsYr);
searchDto.setCrtrYr(crtrYr);
@@ -106,149 +104,149 @@ public class GukYuinApiController {
@Operation(summary = "탐지결과 등록목록 조회(회차uid)", description = "탐지결과 등록목록 조회")
@GetMapping("/chn/mast/{chnDtctId}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectMastDto.ResultDto> selectChangeDetectionDtctIdList(
@RequestParam(required = false) String chnDtctId) {
@RequestParam(required = false) String chnDtctId) {
return ApiResponseDto.ok(gukYuinApiService.listChnDtctId(chnDtctId));
}
@Operation(summary = "탐지결과 등록목록 조회(1건 조회)", description = "탐지결과 등록목록 조회")
@GetMapping("/chn/mast/list/{chnDtctMstId}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectMastDto.ResultDto> selectChangeDetectionDetail(
@PathVariable String chnDtctMstId) {
@PathVariable String chnDtctMstId) {
return ApiResponseDto.ok(gukYuinApiService.detail(chnDtctMstId));
}
@Operation(summary = "국유in연동 가능여부 확인", description = "국유in연동 가능여부 확인")
@GetMapping("/is-link/{uuid}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema =
@Schema(
implementation = GukYuinLinkableRes.class,
description = "TRUE:연동가능, FALSE:연동 불가능"))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema =
@Schema(
implementation = GukYuinLinkableRes.class,
description = "TRUE:연동가능, FALSE:연동 불가능"))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<GukYuinLinkableRes> getIsLinkGukYuin(
@Parameter(description = "uuid", example = "5799eb21-4780-48b0-a82e-e58dcbb8806b")
@PathVariable
UUID uuid) {
@Parameter(description = "uuid", example = "5799eb21-4780-48b0-a82e-e58dcbb8806b")
@PathVariable
UUID uuid) {
return ApiResponseDto.ok(gukYuinApiService.getIsLinkGukYuin(uuid));
}
@Operation(summary = "탐지객체 조회 (탐지객체)", description = "탐지객체 조회 (탐지객체)")
@GetMapping("/chn/cont/{chnDtctId}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectContDto.ResultContDto> findChnContList(
@PathVariable String chnDtctId,
@RequestParam(defaultValue = "0") Integer pageIndex,
@RequestParam(defaultValue = "10") Integer pageSize) {
@PathVariable String chnDtctId,
@RequestParam(defaultValue = "0") Integer pageIndex,
@RequestParam(defaultValue = "10") Integer pageSize) {
return ApiResponseDto.ok(gukYuinApiService.findChnContList(chnDtctId, pageIndex, pageSize));
}
@Operation(summary = "탐지객체 조회 (PNU에 해당하는 탐지객체)", description = "탐지객체 조회 (PNU에 해당하는 탐지객체)")
@GetMapping("/chn/cont/{chnDtctId}/pnu/{pnu}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectContDto.ResultContDto> findChnPnuToContList(
@PathVariable String chnDtctId, @PathVariable String pnu) {
@PathVariable String chnDtctId, @PathVariable String pnu) {
return ApiResponseDto.ok(gukYuinApiService.findChnPnuToContList(chnDtctId, pnu));
}
@Operation(summary = "탐지객체 조회 (탐지객체와 교차하는 PNU)", description = "탐지객체 조회 (탐지객체와 교차하는 PNU)")
@GetMapping("/chn/pnu/{chnDtctId}/objt/{chnDtctObjtId}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "200",
description = "목록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<ChngDetectContDto.ResultPnuDto> findPnuObjMgmtList(
@PathVariable String chnDtctId, @PathVariable String chnDtctObjtId) {
@PathVariable String chnDtctId, @PathVariable String chnDtctObjtId) {
return ApiResponseDto.ok(gukYuinApiService.findPnuObjMgmtList(chnDtctId, chnDtctObjtId));
}
@Operation(summary = "라벨여부 수정", description = "라벨여부 수정")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = DetectMastReq.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
value = {
@ApiResponse(
responseCode = "201",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = DetectMastReq.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/rlb/objt/{chnDtctObjtId}/lbl/{lblYn}")
public ApiResponseDto<ResReturn> updateChnDtctObjtLabelingYn(
@PathVariable String chnDtctObjtId, @PathVariable String lblYn) {
@PathVariable String chnDtctObjtId, @PathVariable String lblYn) {
return ApiResponseDto.ok(gukYuinApiService.updateChnDtctObjtLabelingYn(chnDtctObjtId, lblYn));
}
@Operation(summary = "국유in연동 등록", description = "국유in연동 등록")
@PostMapping("/mast/reg/{uuid}")
public ApiResponseDto<ResponseObj> connectChnMastRegist(
@Parameter(description = "uuid", example = "7a593d0e-76a8-4b50-8978-9af1fbe871af")
@PathVariable
UUID uuid) {
@Parameter(description = "uuid", example = "7a593d0e-76a8-4b50-8978-9af1fbe871af")
@PathVariable
UUID uuid) {
return ApiResponseDto.ok(gukYuinApiService.connectChnMastRegist(uuid));
}
}

View File

@@ -75,7 +75,7 @@ public class GukYuinApiService {
ChngDetectMastDto.RegistResDto.class);
ChngDetectMastDto.RegistResDto resultBody = result.body();
Boolean success = null;
Boolean success = false;
if (resultBody != null) {
ChngDetectMastDto.Basic registRes = resultBody.getResult();
// 추론 회차에 applyStatus, applyStatusDttm 업데이트

View File

@@ -1,6 +1,5 @@
package com.kamco.cd.kamcoback.layer.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
@@ -13,9 +12,32 @@ public class WmtsLayerInfo {
public List<String> keywords = new ArrayList<>();
public BoundingBox boundingBox;
public List<String> formats = new ArrayList<>();
public List<String> tileMatrixSetLinks = new ArrayList<>();
public List<TileMatrixSetLink> tileMatrixSetLinks = new ArrayList<>();
public List<ResourceUrl> resourceUrls = new ArrayList<>();
public List<Style> styles = new ArrayList<>();
// add
public List<String> matrixIds = new ArrayList<>(); // 20250130
public String workspace; // 20250130
public void addMatrixId(String matrixId) {
this.matrixIds.add(matrixId);
}
public List<String> getMatrixIds() {
return matrixIds;
}
public void setWorkspace(String workspace) {
this.workspace = workspace;
}
public String getWorkspace() {
return workspace;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public void setTitle(String title) {
this.title = title;
@@ -64,7 +86,7 @@ public class WmtsLayerInfo {
this.formats.add(format);
}
public void addTileMatrixSetLink(String tileMatrixSetLink) {
public void addTileMatrixSetLink(TileMatrixSetLink tileMatrixSetLink) {
this.tileMatrixSetLinks.add(tileMatrixSetLink);
}
@@ -222,8 +244,6 @@ public class WmtsLayerInfo {
private String identifier;
private String title;
@JsonProperty("default")
private boolean isDefault;
public Style() {}
@@ -273,4 +293,52 @@ public class WmtsLayerInfo {
+ '}';
}
}
/** TileMatrixSetLink 정보를 담는 내부 클래스 */
public static class TileMatrixSetLink {
private String tileMatrixSet;
private List<String> zoomLevels;
public TileMatrixSetLink() {
this.zoomLevels = new ArrayList<>();
}
public TileMatrixSetLink(String tileMatrixSet, List<String> zoomLevels) {
this.tileMatrixSet = tileMatrixSet;
this.zoomLevels = zoomLevels != null ? zoomLevels : new ArrayList<>();
}
// Getters and Setters
public String getTileMatrixSet() {
return tileMatrixSet;
}
public void setTileMatrixSet(String tileMatrixSet) {
this.tileMatrixSet = tileMatrixSet;
}
public List<String> getZoomLevels() {
return zoomLevels;
}
public void setZoomLevels(List<String> zoomLevels) {
this.zoomLevels = zoomLevels;
}
public void addZoomLevel(String zoomLevel) {
this.zoomLevels.add(zoomLevel);
}
@Override
public String toString() {
return "TileMatrixSetLink{"
+ "tileMatrixSet='"
+ tileMatrixSet
+ '\''
+ ", zoomLevels="
+ zoomLevels
+ '}';
}
}
}

View File

@@ -50,7 +50,14 @@ public class WmtsService {
return getLayerInfoByTitle(geoserverUrl, workspace, tile);
}
private List<WmtsLayerInfo> getAllLayers(String geoserverUrl, String workspace) {
/**
* WMTS Capabilities URL에서 모든 레이어 정보를 가져옵니다.
*
* @param geoserverUrl 예: http://localhost:8080
* @param workspace 워크스페이스 이름
* @return 모든 레이어 정보 리스트
*/
public List<WmtsLayerInfo> getAllLayers(String geoserverUrl, String workspace) {
List<WmtsLayerInfo> layers = new ArrayList<>();
try {
// 1. XML 문서 로드 및 파싱
@@ -75,7 +82,7 @@ public class WmtsService {
String title = getChildValue(layerNode, "Title");
if (title != null && !title.trim().isEmpty()) {
WmtsLayerInfo layerInfo = parseLayerNode(layerNode, title);
WmtsLayerInfo layerInfo = parseLayerNode(workspace, layerNode, title);
layers.add(layerInfo);
}
}
@@ -88,151 +95,6 @@ public class WmtsService {
return layers;
}
// 특정 노드 아래의 자식 태그 값 추출 (예: <Title>값)
private String getChildValue(Node parent, String childName) {
Node child = findChildNode(parent, childName);
return (child != null) ? child.getTextContent() : null;
}
// 이름으로 자식 노드 찾기 (Local Name 기준)
private Node findChildNode(Node parent, String localName) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
// 네임스페이스 접두사(ows:, wmts:)를 무시하고 태그 이름 확인
if (node.getNodeName().endsWith(":" + localName) || node.getNodeName().equals(localName)) {
return node;
}
}
return null;
}
// 레이어 노드를 Java 객체로 변환
private WmtsLayerInfo parseLayerNode(Node layerNode, String title) {
WmtsLayerInfo info = new WmtsLayerInfo();
info.title = title;
info.identifier = getChildValue(layerNode, "Identifier");
info.abstractText = getChildValue(layerNode, "Abstract");
// Keywords 파싱
// 구조: <ows:Keywords><ows:Keyword>...</ows:Keyword></ows:Keywords>
info.keywords = getChildValues(layerNode, "Keywords", "Keyword");
// BoundingBox 파싱 (WGS84BoundingBox 기준)
info.boundingBox = parseBoundingBox(layerNode);
// Formats 파싱
info.formats = getChildValuesDirect(layerNode, "Format");
// TileMatrixSetLink 파싱
// 구조: <TileMatrixSetLink><TileMatrixSet>...</TileMatrixSet></TileMatrixSetLink>
info.tileMatrixSetLinks = getChildValues(layerNode, "TileMatrixSetLink", "TileMatrixSet");
// ResourceURL 파싱
info.resourceUrls = parseResourceUrls(layerNode);
// Styles 파싱
info.styles = parseStyles(layerNode);
return info;
}
// 특정 노드 아래의 반복되는 자식 구조 값 추출 (예: Keywords -> Keyword)
private List<String> getChildValues(Node parent, String wrapperName, String childName) {
List<String> results = new ArrayList<>();
Node wrapper = findChildNode(parent, wrapperName);
if (wrapper != null) {
NodeList children = wrapper.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith(childName)) {
results.add(node.getTextContent());
}
}
}
return results;
}
private WmtsLayerInfo.BoundingBox parseBoundingBox(Node layerNode) {
// 보통 <ows:WGS84BoundingBox>를 찾음
Node bboxNode = findChildNode(layerNode, "WGS84BoundingBox");
if (bboxNode == null) bboxNode = findChildNode(layerNode, "BoundingBox");
if (bboxNode != null) {
WmtsLayerInfo.BoundingBox bbox = new WmtsLayerInfo.BoundingBox();
bbox.crs = getAttributeValue(bboxNode, "crs"); // WGS84는 보통 CRS 속성이 없을 수 있음(Default EPSG:4326)
String lowerCorner = getChildValue(bboxNode, "LowerCorner");
String upperCorner = getChildValue(bboxNode, "UpperCorner");
if (lowerCorner != null) {
String[] coords = lowerCorner.split(" ");
bbox.lowerCornerX = Double.parseDouble(coords[0]);
bbox.lowerCornerY = Double.parseDouble(coords[1]);
}
if (upperCorner != null) {
String[] coords = upperCorner.split(" ");
bbox.upperCornerX = Double.parseDouble(coords[0]);
bbox.upperCornerY = Double.parseDouble(coords[1]);
}
return bbox;
}
return null;
}
private String getAttributeValue(Node node, String attrName) {
if (node.hasAttributes()) {
Node attr = node.getAttributes().getNamedItem(attrName);
if (attr != null) return attr.getNodeValue();
}
return null;
}
// Wrapper 없이 바로 반복되는 값 추출 (예: Format)
private List<String> getChildValuesDirect(Node parent, String childName) {
List<String> results = new ArrayList<>();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith(childName)) {
results.add(node.getTextContent());
}
}
return results;
}
private List<WmtsLayerInfo.ResourceUrl> parseResourceUrls(Node layerNode) {
List<WmtsLayerInfo.ResourceUrl> list = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().contains("ResourceURL")) { // local-name check simplification
WmtsLayerInfo.ResourceUrl url = new WmtsLayerInfo.ResourceUrl();
url.setFormat(getAttributeValue(node, "format"));
url.setResourceType(getAttributeValue(node, "resourceType"));
url.setTemplate(getAttributeValue(node, "template"));
list.add(url);
}
}
return list;
}
private List<WmtsLayerInfo.Style> parseStyles(Node layerNode) {
List<WmtsLayerInfo.Style> styles = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith("Style")) {
WmtsLayerInfo.Style style = new WmtsLayerInfo.Style();
style.setDefault(Boolean.parseBoolean(getAttributeValue(node, "isDefault")));
style.setIdentifier(getChildValue(node, "Identifier"));
style.setTitle(getChildValue(node, "Title"));
styles.add(style);
}
}
return styles;
}
/**
* WMTS Capabilities URL에서 특정 타이틀의 레이어 정보를 가져옵니다. // * @param capabilitiesUrl 예:
* http://localhost:8080/geoserver/gwc/service/wmts?REQUEST=GetCapabilities
@@ -268,7 +130,7 @@ public class WmtsService {
// 타이틀이 일치하면 객체 매핑 시작
if (title != null && title.trim().equals(targetTitle)) {
return parseLayerNode(layerNode, title);
return parseLayerNode(workspace, layerNode, title);
}
}
@@ -279,4 +141,249 @@ public class WmtsService {
return null; // 찾지 못한 경우
}
// 레이어 노드를 Java 객체로 변환 20250130
private WmtsLayerInfo parseLayerNode(String workspace, Node layerNode, String title) {
WmtsLayerInfo info = new WmtsLayerInfo();
info.workspace = workspace; // 20250130
info.title = title;
info.identifier = getChildValue(layerNode, "Identifier");
info.abstractText = getChildValue(layerNode, "Abstract");
// Keywords 파싱
// 구조: <ows:Keywords><ows:Keyword>...</ows:Keyword></ows:Keywords>
info.keywords = getChildValues(layerNode, "Keywords", "Keyword");
// BoundingBox 파싱 (WGS84BoundingBox 기준)
info.boundingBox = parseBoundingBox(layerNode);
// Formats 파싱
info.formats = getChildValuesDirect(layerNode, "Format");
// TileMatrixSetLink 파싱 (TileMatrixSet + Zoom Levels)
info.tileMatrixSetLinks = parseTileMatrixSetLinks(layerNode);
// TileMatrixSetLimits에서 줌 레벨 추출 (개별 zoom 리스트)
info.matrixIds = parseMatrixIds(layerNode); // 20260130
// ResourceURL 파싱
info.resourceUrls = parseResourceUrls(layerNode);
// Styles 파싱
info.styles = parseStyles(layerNode);
return info;
}
// --- Helper Methods ---
private WmtsLayerInfo.BoundingBox parseBoundingBox(Node layerNode) {
// 보통 <ows:WGS84BoundingBox>를 찾음
Node bboxNode = findChildNode(layerNode, "WGS84BoundingBox");
if (bboxNode == null) bboxNode = findChildNode(layerNode, "BoundingBox");
if (bboxNode != null) {
WmtsLayerInfo.BoundingBox bbox = new WmtsLayerInfo.BoundingBox();
bbox.crs = getAttributeValue(bboxNode, "crs"); // WGS84는 보통 CRS 속성이 없을 수 있음(Default EPSG:4326)
String lowerCorner = getChildValue(bboxNode, "LowerCorner");
String upperCorner = getChildValue(bboxNode, "UpperCorner");
if (lowerCorner != null) {
String[] coords = lowerCorner.split(" ");
bbox.lowerCornerX = Double.parseDouble(coords[0]);
bbox.lowerCornerY = Double.parseDouble(coords[1]);
}
if (upperCorner != null) {
String[] coords = upperCorner.split(" ");
bbox.upperCornerX = Double.parseDouble(coords[0]);
bbox.upperCornerY = Double.parseDouble(coords[1]);
}
return bbox;
}
return null;
}
private List<WmtsLayerInfo.ResourceUrl> parseResourceUrls(Node layerNode) {
List<WmtsLayerInfo.ResourceUrl> list = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().contains("ResourceURL")) { // local-name check simplification
WmtsLayerInfo.ResourceUrl url = new WmtsLayerInfo.ResourceUrl();
url.setFormat(getAttributeValue(node, "format"));
url.setResourceType(getAttributeValue(node, "resourceType"));
url.setTemplate(getAttributeValue(node, "template"));
list.add(url);
}
}
return list;
}
private List<WmtsLayerInfo.Style> parseStyles(Node layerNode) {
List<WmtsLayerInfo.Style> styles = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith("Style")) {
WmtsLayerInfo.Style style = new WmtsLayerInfo.Style();
style.setDefault(Boolean.parseBoolean(getAttributeValue(node, "isDefault")));
style.setIdentifier(getChildValue(node, "Identifier"));
style.setTitle(getChildValue(node, "Title"));
styles.add(style);
}
}
return styles;
}
/**
* TileMatrixSetLimits에서 줌 레벨을 추출합니다. 예: "EPSG:4326:0" → "0", "EPSG:4326:1" → "1"
*
* @param layerNode Layer 노드
* @return 줌 레벨 문자열 리스트
*/
private List<String> parseMatrixIds(Node layerNode) {
List<String> matrixIds = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
// 모든 TileMatrixSetLink 찾기
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().contains("TileMatrixSetLink")) {
// TileMatrixSetLimits 찾기
Node limitsNode = findChildNode(node, "TileMatrixSetLimits");
if (limitsNode != null) {
NodeList limitsList = limitsNode.getChildNodes();
// 각 TileMatrixLimits 처리
for (int j = 0; j < limitsList.getLength(); j++) {
Node limitNode = limitsList.item(j);
if (limitNode.getNodeName().contains("TileMatrixLimits")) {
// TileMatrix 또는 Identifier 값 추출
String identifier = getChildValue(limitNode, "TileMatrix");
if (identifier == null) {
identifier = getChildValue(limitNode, "Identifier");
}
// 마지막 콜론 이후 값(줌 레벨) 추출
if (identifier != null && identifier.contains(":")) {
String[] parts = identifier.split(":");
String zoomLevel = parts[parts.length - 1];
matrixIds.add(zoomLevel);
}
}
}
}
}
}
return matrixIds;
}
/**
* TileMatrixSetLink 정보를 파싱합니다. 각 TileMatrixSetLink에서 TileMatrixSet 이름과 줌 레벨들을 추출합니다.
*
* @param layerNode Layer 노드
* @return TileMatrixSetLink 객체 리스트
*/
private List<WmtsLayerInfo.TileMatrixSetLink> parseTileMatrixSetLinks(Node layerNode) {
List<WmtsLayerInfo.TileMatrixSetLink> links = new ArrayList<>();
NodeList children = layerNode.getChildNodes();
// 모든 TileMatrixSetLink 찾기
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().contains("TileMatrixSetLink")) {
// TileMatrixSet 이름 추출
String tileMatrixSet = getChildValue(node, "TileMatrixSet");
// 줌 레벨들 추출
List<String> zoomLevels = new ArrayList<>();
Node limitsNode = findChildNode(node, "TileMatrixSetLimits");
if (limitsNode != null) {
NodeList limitsList = limitsNode.getChildNodes();
for (int j = 0; j < limitsList.getLength(); j++) {
Node limitNode = limitsList.item(j);
if (limitNode.getNodeName().contains("TileMatrixLimits")) {
// TileMatrix 또는 Identifier 값 추출
String identifier = getChildValue(limitNode, "TileMatrix");
if (identifier == null) {
identifier = getChildValue(limitNode, "Identifier");
}
// 마지막 콜론 이후 값(줌 레벨) 추출
if (identifier != null && identifier.contains(":")) {
String[] parts = identifier.split(":");
String zoomLevel = parts[parts.length - 1];
zoomLevels.add(zoomLevel);
}
}
}
}
// TileMatrixSetLink 객체 생성 및 추가
if (tileMatrixSet != null) {
WmtsLayerInfo.TileMatrixSetLink link =
new WmtsLayerInfo.TileMatrixSetLink(tileMatrixSet, zoomLevels);
links.add(link);
}
}
}
return links;
}
// 특정 노드 아래의 자식 태그 값 추출 (예: <Title>값)
private String getChildValue(Node parent, String childName) {
Node child = findChildNode(parent, childName);
return (child != null) ? child.getTextContent() : null;
}
// 특정 노드 아래의 반복되는 자식 구조 값 추출 (예: Keywords -> Keyword)
private List<String> getChildValues(Node parent, String wrapperName, String childName) {
List<String> results = new ArrayList<>();
Node wrapper = findChildNode(parent, wrapperName);
if (wrapper != null) {
NodeList children = wrapper.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith(childName)) {
results.add(node.getTextContent());
}
}
}
return results;
}
// Wrapper 없이 바로 반복되는 값 추출 (예: Format)
private List<String> getChildValuesDirect(Node parent, String childName) {
List<String> results = new ArrayList<>();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeName().endsWith(childName)) {
results.add(node.getTextContent());
}
}
return results;
}
// 이름으로 자식 노드 찾기 (Local Name 기준)
private Node findChildNode(Node parent, String localName) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
// 네임스페이스 접두사(ows:, wmts:)를 무시하고 태그 이름 확인
if (node.getNodeName().endsWith(":" + localName) || node.getNodeName().equals(localName)) {
return node;
}
}
return null;
}
private String getAttributeValue(Node node, String attrName) {
if (node.hasAttributes()) {
Node attr = node.getAttributes().getNamedItem(attrName);
if (attr != null) return attr.getNodeValue();
}
return null;
}
}