Tif, Twf, GdalInfo 파일 체크 공통 추가
This commit is contained in:
10
build.gradle
10
build.gradle
@@ -23,6 +23,7 @@ configurations {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven { url "https://repo.osgeo.org/repository/release/" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -40,6 +41,11 @@ dependencies {
|
|||||||
implementation 'org.locationtech.jts.io:jts-io-common:1.20.0'
|
implementation 'org.locationtech.jts.io:jts-io-common:1.20.0'
|
||||||
implementation 'org.locationtech.jts:jts-core:1.19.0'
|
implementation 'org.locationtech.jts:jts-core:1.19.0'
|
||||||
implementation 'org.hibernate:hibernate-spatial:6.2.7.Final'
|
implementation 'org.hibernate:hibernate-spatial:6.2.7.Final'
|
||||||
|
implementation 'org.geotools:gt-main:30.0'
|
||||||
|
implementation("org.geotools:gt-geotiff:30.0") {
|
||||||
|
exclude group: "javax.media", module: "jai_core"
|
||||||
|
}
|
||||||
|
implementation 'org.geotools:gt-epsg-hsql:30.0'
|
||||||
|
|
||||||
// QueryDSL JPA
|
// QueryDSL JPA
|
||||||
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
|
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
|
||||||
@@ -75,6 +81,10 @@ dependencies {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurations.configureEach {
|
||||||
|
exclude group: 'javax.media', module: 'jai_core'
|
||||||
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
package com.kamco.cd.kamcoback.common.utils;
|
package com.kamco.cd.kamcoback.common.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import org.geotools.coverage.grid.GridCoverage2D;
|
||||||
|
import org.geotools.gce.geotiff.GeoTiffReader;
|
||||||
|
|
||||||
public class FIleChecker {
|
public class FIleChecker {
|
||||||
|
|
||||||
@@ -64,4 +72,87 @@ public class FIleChecker {
|
|||||||
return actualHash.equalsIgnoreCase(expectedHash);
|
return actualHash.equalsIgnoreCase(expectedHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean checkTfw(File file) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 파일의 모든 라인을 읽어옴
|
||||||
|
List<Double> lines = new ArrayList<>();
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if (!line.trim().isEmpty()) { // 빈 줄 제외
|
||||||
|
lines.add(Double.parseDouble(line.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (IOException ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 6줄이 맞는지 확인
|
||||||
|
if (lines.size() < 6) {
|
||||||
|
//System.out.println("유효하지 않은 TFW 파일입니다. (데이터 부족)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkGeoTiff(File file) {
|
||||||
|
GeoTiffReader reader = null;
|
||||||
|
try {
|
||||||
|
// 1. 파일 포맷 및 헤더 확인
|
||||||
|
reader = new GeoTiffReader(file);
|
||||||
|
|
||||||
|
// 2. 실제 데이터 로딩 (여기서 파일 깨짐 여부 확인됨)
|
||||||
|
// null을 넣으면 전체 영역을 읽지 않고 메타데이터 위주로 체크하여 빠름
|
||||||
|
GridCoverage2D coverage = reader.read(null);
|
||||||
|
|
||||||
|
if (coverage == null) return false;
|
||||||
|
|
||||||
|
// 3. GIS 필수 정보(좌표계)가 있는지 확인
|
||||||
|
//if (coverage.getCoordinateReferenceSystem() == null) {
|
||||||
|
// GeoTIFF가 아니라 일반 TIFF일 수도 있음(이미지는 정상이지만, 좌표계(CRS) 정보가 없습니다.)
|
||||||
|
//}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("손상된 TIF 파일입니다: " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
// 리소스 해제 (필수)
|
||||||
|
if (reader != null) reader.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String cmmndGdalInfo(String filePath) {
|
||||||
|
|
||||||
|
String resStr = "";
|
||||||
|
boolean hasDriver = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 리눅스/맥용
|
||||||
|
ProcessBuilder pb = new ProcessBuilder("sh", "-c", "gdalinfo "+filePath+" | grep -i 'Geo'");
|
||||||
|
//윈도우용
|
||||||
|
//ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "gdalinfo " + filePath + " | findstr /i \"Geo\"");
|
||||||
|
Process process = pb.start();
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (line.contains("Driver: GTiff")) hasDriver = true;
|
||||||
|
//if (line.contains("Size is")) hasSize = true;
|
||||||
|
//if (line.contains("FAILURE:")) hasFailure = true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasDriver;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user