This post is another Spatial Thoughts Academy Weekly Challenge solutions. The challenge is to find the edge of the polygon in a set of building footprints whose center point is closest to a street and then connect it with the nearest point on the street. Shapely and Fiona were of course up to the challenge. The basic algorithm is to grab the exterior-most ring of the building footprints, break out the edges, determine the midpoint of each edge, measure the distance to each road until the shortest distance is found, then grab the nearest point on the road, and finally draw a line between the edge midpoint and the nearest road point. Shapely's nearest_points() method is really versatile here because you can throw any two geometries at it even if they are different types. Fiona is used to read and write geopackages which I'm really liking lately as more an more people are using them finally. Here's the code:
No comments:
Post a Comment