Skip to content

Commit

Permalink
M3-139 Refactor : 스크립트를 spatial point로 삽입하게끔 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
qjvk2880 committed Jun 26, 2024
1 parent 7e481f4 commit 879ba3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
9 changes: 4 additions & 5 deletions src/main/java/com/m3pro/groundflip/domain/entity/Pixel.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.m3pro.groundflip.domain.entity;

import org.locationtech.jts.geom.Point;

import com.m3pro.groundflip.domain.entity.global.BaseTimeEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
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;
Expand All @@ -16,7 +17,6 @@

@Getter
@Entity
@Table(name = "pixel")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
Expand All @@ -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;

Expand Down
18 changes: 4 additions & 14 deletions src/main/resources/static/pixel_insert.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use groundflip_develop;
DROP PROCEDURE IF EXISTS insertPixel;
DELIMITER $$
CREATE PROCEDURE insertPixel()
Expand All @@ -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();

0 comments on commit 879ba3d

Please sign in to comment.