# Calculate field of view / angle of a point to a shapefile

I am trying to automate a calculation of the blocked fraction of a field of view from a point to a shapefile. I.e. find α in

, such that α / 360 gives me the fraction of the field of view covered by the shapefile in reference to the total field of view.

I know ArcGIS features a 'field of view' based on a DEM/raster (right?), but I am looking for a simpler application, between a simple point and polygon shape.

Is anyone aware of software / a function that is able to do this? It is very easy to do by hand, but I need to process roughly 250 cases, so I thought I'd better ask for other suggestions :)

In the python library pygeoops there is an implementation for this: pygeoops.view_angles

Sample code:

``````from matplotlib import pyplot as plt
import pygeoops
import shapely
import shapely.plotting as plotter

viewpoint = shapely.Point(0, 0)
visible_geom = shapely.box(1, 0, 2, 1)
start_angle, end_angle = pygeoops.view_angles(viewpoint, visible_geom)
print(f"{start_angle=}, {end_angle=}")
# start_angle=0.0, end_angle=45.0

plotter.plot_points(viewpoint, color="red")
plotter.plot_polygon(visible_geom)
plt.show()
``````

Disclaimer: I'm the developer of pygeoops.

There are three points you need the coordinates for:

• a = x,y of the viewer location
• b = x,y of where the view line meets the "top" of the polygon
• c = x,y of where the view line meets the "bottom" of the polygon

These form a triangle and the solution is just trigonometry:

``````angle alpha = cos^-1 ( ((b-c)^2+(c-a)^2-(c-b)^2))/(2*((c-b)^2)^(1/2)*((c-a)^2)^(1/2)
``````

*see SSS triangle solutions http://mathworld.wolfram.com/SSSTheorem.html

• I stumbled across this question whilst looking for an answer to the same question. Whilst this answer addresses the basics of calculating the angles it doesn't address how one derives point b and c in the first place Commented Nov 26, 2021 at 11:36