'Why is my geodataframe failing to reproject or buffer?

PROBLEM: I am attempting to fill the extent of a shapefile with h3 polygons (resolution 4). Polyfill was giving us the incorrect amount of polygons (was only including polygons whose geographic center was within the shapefile), and so I needed another way to do this.

The solution we came up with was to read and buffer the shapefile using geopandas, then run the polyfill using h3pandas, and finally intersect the h3 layer with the original extent to retrieve any polygons of any depth we needed. However, whenever I run a buffer on a geographic-CRS extent, the buffer causes my RAM usage to exceed the 32gb I have available and the script crashes. The buffer works in a projected CRS, but if I reproject to a geographic CRS, the same thing happens where I run out of RAM.

STEPS: I have a shapefile that's being read as a geodataframe. The shapefile contains the borders of Latin America, so I'm setting the coordinate reference system to EPSG:31983. Next, I run a buffer on the file. This is where the script fails.

aoi = gpd.read_file("path/to/my/shapefile.shp") # Read shapefile
aoi = aoi.to_crs("EPSG:31983") # Set CRS
aoi_buff = aoi.buffer(3300) # Buffer gdf to 3.3km

FIXES TRIED: I thought perhaps the dataset itself was faulty, but verified it's not the dataset using QGIS and ArcMap. Next, I thought other parts of my code was wrong, but the code works fine against a smaller extent (Ukraine versus Latin America)... Ukraine works just fine. We tried not setting a CRS at all and having it set in QGIS before it ever got read into geopandas, but this didn't help. We also tried to simplify geometry to ease the strain of the buffer around Argentina:

aoi = gpd.read_file("path/to/my/shapefile.shp") # Read shapefile
aoi = aoi.to_crs("EPSG:31983") # Set CRS
aoi_simp = aoi.simplify(0.1, preserve_topology=False) # Simplify geometry
aoi_buff = aoi_simp.buffer(3300) # Buffer gdf to 3.3km

...but this didn't work either and yielded the same results.

Whats going on here? What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source