diff --git a/src/main/java/com/m3pro/groundflip/domain/dto/pixel/IndividualPixelResponse.java b/src/main/java/com/m3pro/groundflip/domain/dto/pixel/IndividualPixelResponse.java index d911b884..68b580a2 100644 --- a/src/main/java/com/m3pro/groundflip/domain/dto/pixel/IndividualPixelResponse.java +++ b/src/main/java/com/m3pro/groundflip/domain/dto/pixel/IndividualPixelResponse.java @@ -16,6 +16,7 @@ public class IndividualPixelResponse { private double y; public static IndividualPixelResponse from(Pixel pixel) { - return new IndividualPixelResponse(pixel.getLatitude(), pixel.getLongitude(), pixel.getX(), pixel.getY()); + return new IndividualPixelResponse(pixel.getCoordinate().getX(), pixel.getCoordinate().getY(), pixel.getX(), + pixel.getY()); } } diff --git a/src/main/java/com/m3pro/groundflip/domain/entity/Pixel.java b/src/main/java/com/m3pro/groundflip/domain/entity/Pixel.java index df7a4021..b9285a97 100644 --- a/src/main/java/com/m3pro/groundflip/domain/entity/Pixel.java +++ b/src/main/java/com/m3pro/groundflip/domain/entity/Pixel.java @@ -1,5 +1,7 @@ package com.m3pro.groundflip.domain.entity; +import org.locationtech.jts.geom.Point; + import com.m3pro.groundflip.domain.entity.global.BaseTimeEntity; import jakarta.persistence.Column; @@ -7,7 +9,6 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -16,7 +17,6 @@ @Getter @Entity -@Table(name = "pixel") @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder @@ -30,9 +30,8 @@ public class Pixel extends BaseTimeEntity { private Long y; - private double latitude; - - private double longitude; + @Column(columnDefinition = "POINT SRID 4326 NOT NULL") + private Point coordinate; private String address; diff --git a/src/main/resources/static/pixel_insert.sql b/src/main/resources/static/pixel_insert.sql index c9f608e9..57df1431 100644 --- a/src/main/resources/static/pixel_insert.sql +++ b/src/main/resources/static/pixel_insert.sql @@ -1,4 +1,3 @@ -use groundflip_develop; DROP PROCEDURE IF EXISTS insertPixel; DELIMITER $$ CREATE PROCEDURE insertPixel() @@ -13,33 +12,24 @@ BEGIN DECLARE j BIGINT DEFAULT 0; SET current_lat = upper_left_lat; SET current_lon = upper_left_lon; - START TRANSACTION; WHILE i < 7000 DO SET current_lat = upper_left_lat - (i * lat_per_pixel); SET j = 0; - SET @bulk_query = 'INSERT INTO pixel (latitude, longitude, x, y, created_at, modified_at) VALUES '; WHILE j < 4156 DO - SET @aaa = @aaa + 1; SET current_lon = upper_left_lon + (j * lon_per_pixel); - SET @bulk_query = CONCAT(@bulk_query, '(', current_lat, ', ', current_lon, ', ', i, ', ', j, - ', NOW(), NOW()) ,'); + INSERT INTO pixel (coordinate, x, y, created_at, modified_at) + VALUES (ST_GeomFromText(CONCAT('POINT(', current_lat, ' ', current_lon, ')'), 4326), i, j, NOW(), + NOW()); SET j = j + 1; END WHILE; - SET @bulk_query = SUBSTRING(@bulk_query, 1, length(@bulk_query) - 1); - - PREPARE stmt FROM @bulk_query; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET current_lon = upper_left_lon; -- Reset current longitude to the initial value SET i = i + 1; END WHILE; COMMIT; - END $$ DELIMITER ; - +-- Call the stored procedure to insert the coordinates CALL InsertPixel(); \ No newline at end of file