# Calculate Azimuth from polygon in GeoPandas

Is there a simple way / ready-to-go function to calculate the azimuth of 2D-polygons in a GeoPandas DataFrame? My goal is to eventually compute azimuth angles of building footprints.

Most of the functions I have found explicitly calculate the azimuth for a line, which is not what I am looking for. I have been thinking along the following lines to calculate the azimuth of a polygon using its normal vector (2 dimensions). Is my approach going into the right directions? I am a bit unsure how to adjust for the quadrants, also my results seem a bit odd.

``````azimuth = 90 - math.degrees(math.atan2(normal, normal))
if azimuth >= 360.0:
azimuth -= 360.0
elif azimuth < 0.0:
azimuth += 360.0
``````
• How is the normal defined for the polygon? Depending on that algorithm, (first three points?) using the 2 component defining the normal could give you arbitrary azimuths? Nov 29 '20 at 14:15
• You don't provide the inputs or outputs, or what you expected, but bearing calculations don't work on angular units (geographic coordinate system). Instead you need a function which solves the second (aka Inverse, aka Reverse) Problem of Geodesy Nov 29 '20 at 14:17
• What have you tried so far using geopandas? Could you add your code attempts? How do you use a footprint in the script? You can calculate four different azimuths for a footprint which has four edges Nov 29 '20 at 14:27
• Can you add a screenshot/drawing of what you want to calculate?
– BERA
Nov 29 '20 at 15:15

You could try something like this:

``````import geopandas as gpd
import shapely
import math 