3

Given a set of points I would like to have the boundary given by the outtermost points of the set. For example: if I have 11 points, 10 being on the perimeter of a circle (each one at 2*pi/10 radians) and some in the center (or "inside" of the other set of points) corners of a given circle:

n_points_on_circle = 10
theta = np.linspace(0, 2 * np.pi, n_points_on_circle + 1, endpoint=True)
x = np.cos(theta)
y = np.sin(theta)

n_rand = 300
r_rand = .92 * np.sqrt(np.random.random(n_rand))
theta_rand =  2 * np.pi *np.random.random(n_rand)
x_rand = r_rand * np.cos(theta_rand)
y_rand = r_rand * np.sin(theta_rand)


plt.plot(x,y, marker='o')
plt.scatter(x_rand, y_rand, marker='o', c='r')
ax = plt.gca()
ax.set_aspect('equal')

Returns the following image

enter image description here

And making a geodataframe with it:

all_y = np.concatenate([y, y_rand])
all_x = np.concatenate([x, x_rand])
gdf = gpd.GeoDataFrame(data=dict(lat=all_y, lon=all_x, geometry=gpd.points_from_xy(all_x, all_y)))
gdf.plot()

we have the following:

enter image description here

So the question ends up being. Given a geodataframe like gdf, how can I recover the blue polygon shown in the first figure?

This seems so simple I can't believe I would need to work it out. I think there must be a method to do it automatically.

3

1 Answer 1

5

You can use gdf.unary_union.convex_hull.

unary_union makes a multipoint geometry from points, and convex_hull gives you the polygon you want to recover.

enter image description here

1
  • yeah, this is definitely what I wanted. I knew it had to be simple,.Thanks! Feb 22 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.