@@ -102,36 +102,37 @@ def create_geojson_and_bbox(
102102 continue
103103
104104 # Sensor location
105- sensor_lat = float (frame [" Sensor Geodetic Latitude (EPSG:4326)" ])
106- sensor_lon = float (frame [" Sensor Geodetic Longitude (EPSG:4326)" ])
105+ sensor_lat = float (frame [' Sensor Geodetic Latitude (EPSG:4326)' ])
106+ sensor_lon = float (frame [' Sensor Geodetic Longitude (EPSG:4326)' ])
107107
108108 # Frame center and bounding
109- center_lat = float (frame ["Geodetic Frame Center Latitude (EPSG:4326)" ])
110- center_lon = float (frame ["Geodetic Frame Center Longitude (EPSG:4326)" ])
111- width = float (frame ["Target Width (meters)" ])
109+ center_lat = float (frame ['Geodetic Frame Center Latitude (EPSG:4326)' ])
110+ center_lon = float (frame ['Geodetic Frame Center Longitude (EPSG:4326)' ])
111+ target_width = float (frame ['Target Width (meters)' ])
112+ image_width = float (frame ['Image Width' ])
113+ image_height = float (frame ['Image Height' ])
112114 platform_heading = float (frame ['Platform Heading Angle (degrees)' ])
113115 sensor_heading = float (frame ['Sensor Relative Azimuth Angle (degrees)' ])
114116 heading = platform_heading + sensor_heading
115117 # Build a rectangular footprint centered at the center point, rotated by heading
116- # Assume the footprint is square for now (or width x width)
117- half = width / 2
118-
119- # Define rectangle in heading-relative azimuths (clockwise from north)
120- rotation_offset = 0 # degrees (CCW)
121- rotated_heading = (heading + rotation_offset ) % 360
122-
123- angles = [
124- rotated_heading - 45 , # Top-left
125- rotated_heading + 45 , # Top-right
126- rotated_heading + 135 , # Bottom-right
127- rotated_heading - 135 , # Bottom-left
128- ]
118+ # Compute height in meters based on aspect ratio
119+ target_height = (image_height / image_width ) * target_width
120+
121+ # Half dimensions
122+ half_width = target_width / 2
123+ half_height = target_height / 2
124+
125+ # Corner offsets (dx, dy) relative to center
126+ corner_offsets = [(- half_width , half_height ), (half_width , half_height ),
127+ (half_width , - half_height ), (- half_width , - half_height )]
128+
129129 corners = []
130- for az in angles :
131- lon , lat , _ = geod .fwd (center_lon , center_lat , az % 360 , half * (2 ** 0.5 ))
130+ for dx , dy in corner_offsets :
131+ distance = (dx ** 2 + dy ** 2 ) ** 0.5
132+ angle = (heading + np .degrees (np .arctan2 (dx , dy ))) % 360
133+ lon , lat , _ = geod .fwd (center_lon , center_lat , angle , distance )
132134 corners .append ((lon , lat ))
133- corners .append (corners [0 ]) # close the polygon
134- polygon = Polygon (corners )
135+ corners .append (corners [0 ]) # Close polygon polygon = Polygon(corners)
135136 polygons .append (polygon )
136137 frame_polygons .append ((frame_id , polygon ))
137138 frame_to_bbox [frame_id ] = corners
0 commit comments