AbdelChoufani commited on
Commit
469395a
Β·
1 Parent(s): d40687b

Use HTTPS for Overpass + add debug prints + expose traceback

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -40,7 +40,7 @@ import time
40
 
41
 
42
  # OSM Overpass API URL
43
- OVERPASS_URL = "http://overpass-api.de/api/interpreter"
44
 
45
  def latlon_to_utm(lat: float, lon: float) -> Tuple[float, float]:
46
  """Convert WGS84 (lat/lon in degrees) to UTM (meters)."""
@@ -48,7 +48,7 @@ def latlon_to_utm(lat: float, lon: float) -> Tuple[float, float]:
48
  x, y = proj(lon, lat) # Note: pyproj uses (lon, lat) order
49
  return x, y
50
 
51
- def fetch_osm_data(lat: float, lon: float, radius: int = 500) -> Optional[Dict]:
52
  """Fetch OSM data for buildings within a given radius of a coordinate."""
53
  query = f"""
54
  [out:json];
@@ -69,7 +69,34 @@ def fetch_osm_data(lat: float, lon: float, radius: int = 500) -> Optional[Dict]:
69
  return None
70
  except Exception as e:
71
  print(f"Error fetching OSM data: {e}")
72
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  def parse_osm_data(osm_data: Dict) -> List[Dict]:
75
  """Extract building footprints and heights from OSM data."""
@@ -231,8 +258,12 @@ def generate_3d_model(latitude: float, longitude: float, radius: int) -> Tuple[s
231
  else:
232
  return None, "❌ Failed to save 3D model file.", ""
233
 
 
 
234
  except Exception as e:
235
- return None, f"❌ Unexpected error: {str(e)}", ""
 
 
236
 
237
 
238
 
 
40
 
41
 
42
  # OSM Overpass API URL
43
+ OVERPASS_URL = "https://overpass-api.de/api/interpreter"
44
 
45
  def latlon_to_utm(lat: float, lon: float) -> Tuple[float, float]:
46
  """Convert WGS84 (lat/lon in degrees) to UTM (meters)."""
 
48
  x, y = proj(lon, lat) # Note: pyproj uses (lon, lat) order
49
  return x, y
50
 
51
+ """def fetch_osm_data(lat: float, lon: float, radius: int = 500) -> Optional[Dict]:
52
  """Fetch OSM data for buildings within a given radius of a coordinate."""
53
  query = f"""
54
  [out:json];
 
69
  return None
70
  except Exception as e:
71
  print(f"Error fetching OSM data: {e}")
72
+ return None"""
73
+
74
+ def fetch_osm_data(lat: float, lon: float, radius: int = 500) -> Optional[Dict]:
75
+ query = f"""
76
+ [out:json];
77
+ (
78
+ way(around:{radius},{lat},{lon})[building];
79
+ );
80
+ out body;
81
+ >;
82
+ out skel qt;
83
+ """
84
+
85
+ try:
86
+ r = requests.get(OVERPASS_URL, params={"data": query}, timeout=30)
87
+ print(f"πŸ›°οΈ Overpass status code: {r.status_code}")
88
+ if r.status_code != 200:
89
+ print(f"🚨 Overpass error body: {r.text[:200]!r}")
90
+ return None
91
+
92
+ data = r.json()
93
+ print(f"βœ… Fetched {len(data.get('elements', []))} OSM elements")
94
+ return data
95
+
96
+ except Exception as e:
97
+ print(f"❌ Exception while fetching OSM data: {e}")
98
+ raise # re-raise so we see the traceback in the logs
99
+
100
 
101
  def parse_osm_data(osm_data: Dict) -> List[Dict]:
102
  """Extract building footprints and heights from OSM data."""
 
258
  else:
259
  return None, "❌ Failed to save 3D model file.", ""
260
 
261
+ """except Exception as e:
262
+ return None, f"❌ Unexpected error: {str(e)}", "" """
263
  except Exception as e:
264
+ import traceback
265
+ traceback.print_exc()
266
+ raise
267
 
268
 
269