Spaces:
Running
Running
3857
Browse files
app.py
CHANGED
|
@@ -301,22 +301,19 @@ async def generate_i3s(request: GenerateI3SRequest):
|
|
| 301 |
if not coords or len(coords) < 9: # At least 3 points (3 * 3)
|
| 302 |
raise HTTPException(status_code=400, detail="Invalid coordinates. Need at least 3 points (lon, lat, alt).")
|
| 303 |
|
| 304 |
-
# 1.
|
| 305 |
-
#
|
| 306 |
-
|
| 307 |
-
|
|
|
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
utm_epsg = (32600 if is_north else 32700) + zone
|
| 312 |
|
| 313 |
-
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
# 2. Project Points to UTM
|
| 318 |
-
# coords is [lon, lat, alt, lon, lat, alt...]
|
| 319 |
-
utm_coords = []
|
| 320 |
num_points = len(coords) // 3
|
| 321 |
|
| 322 |
for i in range(num_points):
|
|
@@ -326,15 +323,14 @@ async def generate_i3s(request: GenerateI3SRequest):
|
|
| 326 |
cz = coords[idx+2]
|
| 327 |
|
| 328 |
ux, uy = transformer.transform(cx, cy)
|
| 329 |
-
# Z stays same (Alt in meters)
|
| 330 |
utm_coords.extend([ux, uy, cz])
|
| 331 |
|
| 332 |
-
# 3. Calculate Anchor (
|
| 333 |
anchor_x = utm_coords[0]
|
| 334 |
anchor_y = utm_coords[1]
|
| 335 |
anchor_z = utm_coords[2]
|
| 336 |
|
| 337 |
-
# 4. Localize
|
| 338 |
local_coords = []
|
| 339 |
for i in range(num_points):
|
| 340 |
idx = i * 3
|
|
@@ -355,16 +351,13 @@ async def generate_i3s(request: GenerateI3SRequest):
|
|
| 355 |
os.makedirs(output_dir, exist_ok=True)
|
| 356 |
|
| 357 |
enc_options = {
|
| 358 |
-
'sceneType': 'Global',
|
| 359 |
-
'sceneWkid':
|
| 360 |
'baseName': 'SceneLayer',
|
| 361 |
'sceneName': 'SceneLayer',
|
| 362 |
'writePackage': False,
|
| 363 |
'compression': False,
|
| 364 |
'outputPath': output_dir,
|
| 365 |
-
|
| 366 |
-
# Critical: Tell Encoder the offset we subtracted
|
| 367 |
-
# For I3S/PyPRT, globalOffset matches the sceneWkid coordinate system
|
| 368 |
'globalOffset': [anchor_x, anchor_y, anchor_z]
|
| 369 |
}
|
| 370 |
|
|
|
|
| 301 |
if not coords or len(coords) < 9: # At least 3 points (3 * 3)
|
| 302 |
raise HTTPException(status_code=400, detail="Invalid coordinates. Need at least 3 points (lon, lat, alt).")
|
| 303 |
|
| 304 |
+
# 1. Project to Web Mercator (EPSG:3857)
|
| 305 |
+
# Why?
|
| 306 |
+
# - It uses Meters (good for CGA generation/scaling).
|
| 307 |
+
# - It is standard for Web Maps/I3S supported by Cesium.
|
| 308 |
+
# - Avoids complexity of dynamic UTM zones.
|
| 309 |
|
| 310 |
+
target_epsg = 3857
|
| 311 |
+
logger.info(f"Projecting I3S geometry to EPSG:{target_epsg} (Web Mercator)")
|
|
|
|
| 312 |
|
| 313 |
+
transformer = pyproj.Transformer.from_crs("EPSG:4326", f"EPSG:{target_epsg}", always_xy=True)
|
| 314 |
|
| 315 |
+
# 2. Project Points
|
| 316 |
+
utm_coords = [] # Variable name kept for minimal diff, but now it's Web Mercator
|
|
|
|
|
|
|
|
|
|
| 317 |
num_points = len(coords) // 3
|
| 318 |
|
| 319 |
for i in range(num_points):
|
|
|
|
| 323 |
cz = coords[idx+2]
|
| 324 |
|
| 325 |
ux, uy = transformer.transform(cx, cy)
|
|
|
|
| 326 |
utm_coords.extend([ux, uy, cz])
|
| 327 |
|
| 328 |
+
# 3. Calculate Anchor (Mercator)
|
| 329 |
anchor_x = utm_coords[0]
|
| 330 |
anchor_y = utm_coords[1]
|
| 331 |
anchor_z = utm_coords[2]
|
| 332 |
|
| 333 |
+
# 4. Localize
|
| 334 |
local_coords = []
|
| 335 |
for i in range(num_points):
|
| 336 |
idx = i * 3
|
|
|
|
| 351 |
os.makedirs(output_dir, exist_ok=True)
|
| 352 |
|
| 353 |
enc_options = {
|
| 354 |
+
'sceneType': 'Global',
|
| 355 |
+
'sceneWkid': str(target_epsg), # 3857
|
| 356 |
'baseName': 'SceneLayer',
|
| 357 |
'sceneName': 'SceneLayer',
|
| 358 |
'writePackage': False,
|
| 359 |
'compression': False,
|
| 360 |
'outputPath': output_dir,
|
|
|
|
|
|
|
|
|
|
| 361 |
'globalOffset': [anchor_x, anchor_y, anchor_z]
|
| 362 |
}
|
| 363 |
|