Sorta working suspected locations

This commit is contained in:
stopflock
2025-10-06 21:07:08 -05:00
parent 904af42cbf
commit 4a44ab96d6
7 changed files with 316 additions and 104 deletions
+32 -8
View File
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:math' as math;
import 'package:latlong2/latlong.dart';
/// A suspected surveillance location from the CSV data
@@ -41,16 +42,39 @@ class SuspectedLocation {
// Parse GeoJSON if available
if (locationString != null && locationString.isNotEmpty) {
try {
print('[SuspectedLocation] Parsing GeoJSON for ticket ${row['ticket_no']}, length: ${locationString.length}');
// Only log first few entries to avoid spam
final ticketNo = row['ticket_no']?.toString() ?? 'unknown';
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
print('[SuspectedLocation] Raw location string for ticket $ticketNo: ${locationString.substring(0, math.min(100, locationString.length))}...');
}
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
if (centroid.latitude != 0 || centroid.longitude != 0) {
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
} else {
print('[SuspectedLocation] Parsed but got zero coordinates');
}
}
geoJson = jsonDecode(locationString) as Map<String, dynamic>;
final coordinates = _extractCoordinatesFromGeoJson(geoJson);
centroid = coordinates.centroid;
bounds = coordinates.bounds;
print('[SuspectedLocation] Successfully parsed, centroid: $centroid, bounds count: ${bounds.length}');
} catch (e, stackTrace) {
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
if (centroid.latitude != 0 || centroid.longitude != 0) {
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
} else {
print('[SuspectedLocation] Parsed but got zero coordinates');
}
}
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
if (centroid.latitude != 0 || centroid.longitude != 0) {
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
} else {
print('[SuspectedLocation] Parsed but got zero coordinates');
}
}
} catch (e) {
// If GeoJSON parsing fails, use default coordinates
print('[SuspectedLocation] Failed to parse GeoJSON for ticket ${row['ticket_no']}: $e');
print('[SuspectedLocation] Stack trace: $stackTrace');
print('[SuspectedLocation] Location string: $locationString');
}
}
@@ -74,17 +98,17 @@ class SuspectedLocation {
/// Extract coordinates from GeoJSON
static ({LatLng centroid, List<LatLng> bounds}) _extractCoordinatesFromGeoJson(Map<String, dynamic> geoJson) {
try {
final geometry = geoJson['geometry'] as Map<String, dynamic>?;
final coordinates = geometry?['coordinates'] as List?;
// The geoJson IS the geometry object (not wrapped in a 'geometry' property)
final coordinates = geoJson['coordinates'] as List?;
if (coordinates == null || coordinates.isEmpty) {
print('[SuspectedLocation] No coordinates found in GeoJSON');
return (centroid: const LatLng(0, 0), bounds: <LatLng>[]);
}
final List<LatLng> points = [];
// Handle different geometry types
final type = geometry?['type'] as String?;
final type = geoJson['type'] as String?;
switch (type) {
case 'Point':
if (coordinates.length >= 2) {