2

I have the following GeoSeries:

print(zambia_grid)

voltage_kV, geometry, buffer_value                                                             
88.0,        MULTILINESTRING ((662448.559 8288872.590, 6625...,  660.0   
132.0,       MULTILINESTRING ((662368.932 8288816.909, 6623...,  142.0   
220.0,       MULTILINESTRING ((632159.980 8609158.729, 6321...,  990.0   
330.0,       MULTILINESTRING ((662612.310 8288970.288, 6626...,  220.0 

I have tried creating a buffer:

zambia_grid_buffer = zambia_grid.buffer(distance = zambia_grid['buffer_value'])

However when I try to plot this, I get the following error:

'Polygon' object is not subscriptable

... is it possible to have varying buffers in geopandas?

four_loops
  • 235
  • 1
  • 2
  • 9

1 Answers1

3

Starting from GeoPandas version 0.5, you should be able to pass an array of series of values to buffer for the distance argument, to have varying buffer sizes.

Using the built-in countries dataset as dummy example:

>>> df = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
>>> df
    pop_est      continent       name iso_a3  gdp_md_est                                           geometry
0    920938        Oceania       Fiji    FJI      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1  53950935         Africa   Tanzania    TZA    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2    603253         Africa  W. Sahara    ESH       906.5  POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3  35623680  North America     Canada    CAN   1674000.0  MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
..      ...            ...        ...    ...         ...                                             

>>> df.buffer(distance=df['pop_est'])
0      POLYGON ((-920362.560 -15501.816, -921118.000 ...
1      POLYGON ((-1110993.428 53939492.982, 4253453.0...
2      POLYGON ((-8.666 603280.656, 58859.799 600401....
3      POLYGON ((-35623475.484 26100.474, -35623805.6...
...
joris
  • 133,120
  • 36
  • 247
  • 202