Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public static String convertDoubleToLineStringWTK(List<double[]> co){
return writer.write(lineString);
}

public static String makeSquarePolygonString(double leftUpLng, double leftUpLat, double rightDownLng, double rightDownLat){
return String.format("Polygon((%f %f, %f %f, %f %f, %f %f, %f %f))"
, leftUpLng,leftUpLat
Comment on lines +46 to +48
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polygon 과 envelop 에 대해 덕분에 잘 알게 되었습니다!! 감사합니다 :)

, leftUpLng,rightDownLat
, rightDownLng, rightDownLat
, rightDownLng, leftUpLat
, leftUpLng, leftUpLat);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public interface BuildingRepository extends JpaRepository<Building, Long>, Build
JOIN FETCH Node n ON b.nodeId = n.id
WHERE b.univId = :univId
AND b.level >= :level
AND ST_Within(n.coordinates, ST_MakeEnvelope(:lux, :luy, :rdx, :rdy, 4326))
AND ST_Within(n.coordinates, ST_PolygonFromText((:polygon),4326))
""")
List<BuildingNode> findByUnivIdAndLevelWithNode(Long univId, int level, double lux , double luy, double rdx , double rdy);
List<BuildingNode> findByUnivIdAndLevelWithNode(Long univId, int level, String polygon);

@Query("""
SELECT new com.softeer5.uniro_backend.node.dto.BuildingNode(b, n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import lombok.RequiredArgsConstructor;

import static com.softeer5.uniro_backend.common.utils.GeoUtils.makeSquarePolygonString;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -26,8 +28,8 @@ public List<GetBuildingResDTO> getBuildings(
Long univId, int level,
double leftUpLng, double leftUpLat, double rightDownLng , double rightDownLat) {

List<BuildingNode> buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode(
univId, level, leftUpLng, leftUpLat, rightDownLng, rightDownLat);
String polygon = makeSquarePolygonString(leftUpLng, leftUpLat, rightDownLng, rightDownLat);
List<BuildingNode> buildingNodes = buildingRepository.findByUnivIdAndLevelWithNode(univId, level, polygon);

return buildingNodes.stream()
.map(buildingNode -> GetBuildingResDTO.of(buildingNode.getBuilding(), buildingNode.getNode()))
Expand Down