AOSSIE-Org / AOSSIE-Org/PictoPy

Feat: Display local place name using image GPS (geocodes) in Memories section

Đang mở
#1,195 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
283
Fork
679
Merge trung bình
7 ngày 2 giờ
Pull request đã merge (30 ngày)
3

Mô tả

### Describe the feature

### Description
In the Memories section, location-type memories currently display plain geocodes when the image coordinates are not near any of the predefined popular places listed in `CITY_COORDINATES` within `memory_clustering.py`.

Instead of showing raw latitude/longitude values, the application can display the **nearest local place name** (city/town/village) derived from the image’s geocodes.

If the distance to the nearest locality exceeds a configurable threshold (default: **4.0 km**), only the **state name** should be displayed rather than plain geocodes.

### Current Problem
- When image geocodes do not match nearby entries in `CITY_COORDINATES`, the UI displays raw latitude/longitude values.
- Plain geocodes are not user-friendly and reduce the overall UX quality.
- Users cannot easily interpret the actual location represented by the coordinates.

### Expected Feature
- Determine the nearest locality (city/town/village) using reverse geocoding.
- Display the local place name instead of plain geocodes.
- If the nearest locality is farther than the threshold distance (default: 4.0 km):
- Display only the state name.
- Avoid showing raw coordinates.
- Determination of nearest locality using reverse geocoding should be offline.

## Implementation
### Backend
- Added `GeoCodes.db` file. It contains tables for all States and Union Territories, with approximately 500 cities/towns/villages per state. **(Currently India)**
-The database also includes a `classifier` table used to determine which state should be searched for a given set of geocodes. *(Example: For provided coordinates, the classifier predicts the most probable state where the location belongs.)*

- Table Columns:
- `states`: **place | latitude | Longitude**
- `classifier`: **state | latitude | Longitude**

- Implemented the Haversine formula to compute distances and identify the nearest locality (city/town/village) within the predicted state

- Updated return values of function `_reverse_geocode` in `memories_clustering.py` as:
```py
def _reverse_geocode(self, lat: float, lon: float) -> Optional[str]: # added optional return
"""Find nearest city within 50km"""
for city_name, (city_lat, city_lon) in self.CITY_COORDINATES.items():
distance = haversine_distance(lat, lon, city_lat, city_lon)
if distance < 50:
return city_name, True # True -> because city name found
return f"{lat:.4f}°, {lon:.4f}°", False # False -> because of formatted coordinates

```
- Updated return value in function `_create_simple_memory` in `memories_clustering.py` as:
```py
# Get actual location name using reverse geocoding
location_name, status = self._reverse_geocode(center_lat, center_lon) # status is true if nearest tourist place (actual location) is found
if not status:
# getting place name if no nearest tourist place found
place = get_location_by_geocode(latitude=center_lat, longitude=center_lon, offset=4.0)
else:
place = None

return {
"memory_id": memory_id,
"title": title,
"description": f"{len(images)} photos",
"location_name": location_name,
"place":place, # added key value pair for place
"date_start": date_start,
"date_end": date_end,
"image_count": len(images),
"images": sorted_images,
"thumbnail_image_id": sorted_images[0].get("id", ""),
"center_lat": center_lat,
"center_lon": center_lon,
"type": memory_type,
}

```

- Updated Memory Schemas in `routes/memories.py` for new key.

- added `!GeoCodes.db` in **.gitignore**

### Frontend

- Modified `memories.ts` to include the `place: string | null` field in the `Memory` interface
```tsx
place: string | null;
```

- Updated MemoryCard Component:
- Added logic in Memories/MemoryCard.tsx, to override the `displayTitle` with the value of `place` if it is available.
```tsx
// If "place" is provided (from backend), use it as the main title
if (memory.place) {
displayTitle = memory.place;
}
```
- Updated MemoryDetail Component:
- Updated the `tempMemory` object for the "On This Day" feature to include the `place` field.
- Synchronized the `displayTitle` logic in `MemoryDetail.tsx` with `MemoryCard.tsx` to ensure consistency between the list view and the detail view.

### Add ScreenShots

## Screenshots
### Before

![Image](https://github.com/user-attachments/assets/9353a07e-372d-4bf8-8ea6-c8477567b46a)

![Image](https://github.com/user-attachments/assets/0199b8b3-606d-4a39-a9b3-4b2e6aaa1a8b)

### After

![Image](https://github.com/user-attachments/assets/e1fdb372-c088-4bd5-9721-015a5bd34a35)

![Image](https://github.com/user-attachments/assets/8df10adc-24bf-4442-8d2f-9d404a5a74cc)

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.