6

I have a shapefile with a number of points. Using GeoPandas, I am trying to create a convex hull around the set of points. However, my output layer returns the same points as were fed in. My understanding is that convex hull would take the points and return smallest convex Polygon containing all the points. But that doesn't seem to be happening. I feel like I am missing a basic concept here, but I cannot figure it out. What am I missing?

Here is my code:

import pandas as pd
import shapely
import geopandas as gpd

node_shp = gpd.read_file(node_path)

within_15mins = node_shp.loc[node_shp["within15"]>0].copy()
within_15_hull = within_15mins.convex_hull

node_shp looks like:

      ID    within15    geometry
0   960233     0           POINT (537654.434909813 4812991.530337551)
1   960234     0           POINT (538582.515799641 4812470.00595164)
2   960236     0           POINT (545187.4344721519 4807876.94211408)
3   960237     0           POINT (549496.7740777618 4806878.272506691)
4   960238     0           POINT (551647.5381420769 4805487.459653219)

within_15_hull results are:

139        POINT (610977.628373108 4842383.41564639)
143                           POINT (614301 4841063)
146                           POINT (613955 4842000)
147                           POINT (613825 4842422)
148                           POINT (614790 4842672)
                            ...                     
26499    POINT (617182.5693036331 4851689.407768221)
26695     POINT (608644.0917927549 4851434.42780789)
26696     POINT (608679.5770971529 4851538.48593273)
26700     POINT (612368.671008331 4838778.938846011)
26702      POINT (609655.111841024 4849233.53601891)
Length: 1467, dtype: object
  • Geopandas takes the convex hull for each geometry. So it takes the convex hull of each separate point. – Dataform Apr 23 '20 at 21:17
  • following on the advice from @Dataform, try first making a Polygon from your Points – Charlie Parr Apr 23 '20 at 21:42
9

If you want a single geometry representing the whole dataframe, this should do it:

within_15_hull = within_15mins.unary_union.convex_hull

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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