미사용 유틸 삭제

This commit is contained in:
2026-01-22 16:55:49 +09:00
parent f735712f92
commit 9708868699
5 changed files with 0 additions and 227 deletions

View File

@@ -1,48 +0,0 @@
package com.kamco.cd.kamcoback.gukyuin.utils;
import com.fasterxml.jackson.databind.JsonNode;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LinearRing;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Polygon;
public class GeoJsonGeometryConverter {
private static final GeometryFactory GF = new GeometryFactory();
public static Geometry toGeometry(JsonNode geomNode) {
String type = geomNode.path("type").asText();
if ("Polygon".equals(type)) {
return toPolygon(geomNode.path("coordinates"));
}
if ("MultiPolygon".equals(type)) {
return toMultiPolygon(geomNode.path("coordinates"));
}
return null;
}
private static Polygon toPolygon(JsonNode coords) {
LinearRing shell = GF.createLinearRing(toCoords(coords.get(0)));
return GF.createPolygon(shell);
}
private static MultiPolygon toMultiPolygon(JsonNode coords) {
Polygon[] polys = new Polygon[coords.size()];
for (int i = 0; i < coords.size(); i++) {
polys[i] = toPolygon(coords.get(i));
}
return GF.createMultiPolygon(polys);
}
private static Coordinate[] toCoords(JsonNode ring) {
Coordinate[] c = new Coordinate[ring.size() + 1];
for (int i = 0; i < ring.size(); i++) {
c[i] = new Coordinate(ring.get(i).get(0).asDouble(), ring.get(i).get(1).asDouble());
}
c[c.length - 1] = c[0];
return c;
}
}

View File

@@ -1,44 +0,0 @@
package com.kamco.cd.kamcoback.gukyuin.utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GeoJsonLoader {
private final ObjectMapper om = new ObjectMapper();
public GeoJsonFile load(File geoJsonFile) throws Exception {
JsonNode root = om.readTree(geoJsonFile);
long mapId = root.path("properties").path("map_id").asLong(-1);
if (mapId <= 0) {
throw new IllegalStateException(
"GeoJSON top-level properties.map_id 없음: " + geoJsonFile.getName());
}
List<JsonNode> features = new ArrayList<>();
root.path("features").forEach(features::add);
return new GeoJsonFile(mapId, features);
}
/** ✅ feature에서 polygon_id 추출 */
public static String polygonId(JsonNode feature) {
return feature.path("properties").path("polygon_id").asText(null);
}
public static class GeoJsonFile {
public final long mapId;
public final List<JsonNode> features;
public GeoJsonFile(long mapId, List<JsonNode> features) {
this.mapId = mapId;
this.features = features;
}
}
}

View File

@@ -1,17 +0,0 @@
package com.kamco.cd.kamcoback.gukyuin.utils;
public class MapIdUtils {
private MapIdUtils() {
// util class
}
/** map_id → 시도코드 예: 34602060 → "34" */
public static String sidoCodeFromMapId(long mapId) {
String s = String.valueOf(mapId);
if (s.length() < 2) {
throw new IllegalArgumentException("잘못된 map_id: " + mapId);
}
return s.substring(0, 2);
}
}

View File

@@ -1,76 +0,0 @@
package com.kamco.cd.kamcoback.gukyuin.utils;
import java.io.File;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.geotools.api.data.DataStore;
import org.geotools.api.data.DataStoreFinder;
import org.geotools.api.data.SimpleFeatureSource;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.index.strtree.STRtree;
public class ShpIndexManager {
private static final String SHP_ROOT = "/shp";
private static final String SHP_YYYYMM = "202512";
private static final String PNU_FIELD = "PNU";
private final Map<String, STRtree> cache = new ConcurrentHashMap<>();
public STRtree getIndex(String sidoCode) {
return cache.computeIfAbsent(sidoCode, this::loadIndex);
}
private STRtree loadIndex(String sidoCode) {
try {
String path = SHP_ROOT + "/LSMD_CONT_LDREG_" + sidoCode + "_" + SHP_YYYYMM + ".shp";
File shp = new File(path);
if (!shp.exists()) {
return null;
}
STRtree index = new STRtree(10);
DataStore store = DataStoreFinder.getDataStore(Map.of("url", shp.toURI().toURL()));
String typeName = store.getTypeNames()[0];
SimpleFeatureSource source = store.getFeatureSource(typeName);
SimpleFeatureCollection col = source.getFeatures();
try (SimpleFeatureIterator it = col.features()) {
while (it.hasNext()) {
SimpleFeature f = it.next();
Geometry geom = (Geometry) f.getDefaultGeometry();
String pnu = Objects.toString(f.getAttribute(PNU_FIELD), null);
if (geom != null && pnu != null) {
index.insert(geom.getEnvelopeInternal(), new ShpRow(geom, pnu));
}
}
}
index.build();
store.dispose();
return index;
} catch (Exception e) {
return null;
}
}
/** SHP 한 row */
public static class ShpRow {
public final Geometry geom;
public final String pnu;
public ShpRow(Geometry geom, String pnu) {
this.geom = geom;
this.pnu = pnu;
}
}
}

View File

@@ -1,42 +0,0 @@
package com.kamco.cd.kamcoback.gukyuin.utils;
import java.util.List;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.index.strtree.STRtree;
public class ShpPnuMatcher {
public static String pickByIntersectionMax(STRtree index, Geometry target) {
Envelope env = target.getEnvelopeInternal();
@SuppressWarnings("unchecked")
List<ShpIndexManager.ShpRow> rows = index.query(env);
double best = 0;
String bestPnu = null;
for (ShpIndexManager.ShpRow row : rows) {
PreparedGeometry prep = PreparedGeometryFactory.prepare(row.geom);
if (prep.contains(target) || prep.covers(target)) {
return row.pnu;
}
if (!prep.intersects(target)) {
continue;
}
double area = row.geom.intersection(target).getArea();
if (area > best) {
best = area;
bestPnu = row.pnu;
}
}
return bestPnu;
}
}