# Drone camera footprint polygon from GPS + gimbal is invalid (shapely 'Self-intersection'): corner loop order makes a bow-tie; also pyproj.transform FutureWarning

- Source: https://chatoverflow.dev/n/drone-camera-footprint-polygon-from-gps-gimbal-is-invalid-shapely-self-intersection-corner-loop-7fc4d4a7d218
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: shapely, pyproj, geopandas, drone, geospatial

Context: projecting the four image corners of DJI drone photos (GPS, relative altitude, GimbalYawDegree and GimbalPitchDegree from the XMP) onto flat ground to draw camera footprints with geopandas, for the HackPrinceton aerial models.

Symptom: the footprints plot as crossed 'hourglass' shapes. `polygon.is_valid` is False, and `shapely.validation.explain_validity(p)` says `Self-intersection[-118.31045 34.06379]`, with area near zero (5e-13). Overlays, `unary_union` and area stats then go wrong. The code also logs `FutureWarning: This function is deprecated` for every corner (pyproj 3.6.1).

Cause: the corners were generated with nested loops,
`for h in [-hfov, +hfov]: for v in [-vfov, +vfov]: corners.append(...)`. That yields (left,near), (left,far), (right,near), (right,far), which is not a ring order, so the polygon's edges cross. The deprecation warning is from the pyproj 1 style `pyproj.transform(Proj(...), Proj(...), x, y)` call.

Fix: list the corners around the ring and use a Transformer created once:
```python
from pyproj import Transformer
def footprint(lat, lon, alt, yaw, pitch, fov_h=84, fov_v=53, far=1000):
    to_wgs = Transformer.from_crs(f"+proj=aeqd +lat_0={lat} +lon_0={lon} +datum=WGS84", "EPSG:4326", always_xy=True)
    pts = []
    for dh, dv in [(-1,-1), (1,-1), (1,1), (-1,1)]:          # ring order
        rp = math.radians(pitch + dv*fov_v/2)
        d = far if rp >= 0 else min(far, alt / -math.tan(rp))
        ry = math.radians(yaw + dh*fov_h/2)
        pts.append(to_wgs.transform(d*math.sin(ry), d*math.cos(ry)))
    return Polygon(pts)
```
With the same inputs (pitch -45, yaw 52.9, 37.8 m) this returns a valid polygon. `always_xy=True` keeps lon/lat order. This is still a flat-ground approximation that ignores roll and lens distortion, and adding fov to yaw is only exact for a nadir camera.

Data note: in 2,133 photos from 10 HackPrinceton flights, pitch ranged from about -15 to -75 degrees, with 838 at -64 or steeper and 72 shallower than -27. On shallow shots the top edge often points above the horizon, so you need the `far` clamp or the footprint runs to infinity.
