get closest point to a line

Here’s Ruby disguised as Pseudo-Code, assuming Point objects each have a x and y field. def GetClosestPoint(A, B, P) a_to_p = [P.x – A.x, P.y – A.y] # Storing vector A->P a_to_b = [B.x – A.x, B.y – A.y] # Storing vector A->B atb2 = a_to_b[0]**2 + a_to_b[1]**2 # **2 means “squared” # Basically finding … Read more

How to calculate the area of a polygon on the earth’s surface using python?

Let’s say you have a representation of the state of Colorado in GeoJSON format {“type”: “Polygon”, “coordinates”: [[ [-102.05, 41.0], [-102.05, 37.0], [-109.05, 37.0], [-109.05, 41.0] ]]} All coordinates are longitude, latitude. You can use pyproj to project the coordinates and Shapely to find the area of any projected polygon: co = {“type”: “Polygon”, “coordinates”: … Read more