BUG: Clip not return GeoDataFrame or GeoSeries
See original GitHub issue-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of geopandas.
-
(optional) I have confirmed this bug exists on the master branch of geopandas.
Example code to reproduce the bug
import geopandas as gpd
from shapely.geometry import Polygon
GEOPACKAGE = r'C:\temp\test.gpkg'
crs = 31982
layer_name_mask = 'polygon_area'
layer_name_toclip = 'polygon_to_clip'
def create_polygons():
polygon_data = Polygon([
(581762.720, 7276585.620),
(581762.720, 7186208.392),
(490411.599, 7186208.392),
(490411.599, 7276585.620)
])
polygon_gpd = gpd.GeoDataFrame(geometry=[polygon_data])
polygon_gpd.to_file(GEOPACKAGE, layer=layer_name_mask, crs=crs,
driver='GPKG')
pol_to_clip_data = Polygon([
(552576.412, 7214657.225),
(552576.412, 7257625.935),
(595472.170, 7257625.935),
(595472.170, 7214657.225)
])
pol_to_clip_gpd = gpd.GeoDataFrame(geometry=[pol_to_clip_data])
pol_to_clip_gpd.to_file(GEOPACKAGE, layer=layer_name_toclip, crs=crs,
driver='GPKG')
if __name__ == '__main__':
create_polygons()
layer_mask = gpd.read_file(GEOPACKAGE, layer=layer_name_mask)
layer_toclip = gpd.read_file(GEOPACKAGE, layer=layer_name_toclip)
# Here not return data and/or any error
results = gpd.clip(layer_toclip, layer_mask)
print(results)
results.to_file(GEOPACKAGE, layer='results', crs=crs, driver='GPKG')
Problem description
I was writing some tests and I found this problem. If execute the code above, the expected output was a polygon results between the layer_mask and layer_toclip.
For my real data the code works fine, but I don’t sure I will have problems for future data. I tested with shapefile format and I haven’t sucess too, but the both cases (from Geopackage and shapefile) I can success cliping in QGis software.
Expected Output
Output of geopandas.show_versions()
SYSTEM INFO
python : 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] executable : D:\Desenvolvimento\Python\vantia\backend\venv\Scripts\python.exe machine : Windows-10-10.0.17134-SP0
GEOS, GDAL, PROJ INFO
GEOS : None GEOS lib : None GDAL : 3.1.2 GDAL data dir: None PROJ : 7.0.1 PROJ data dir: D:\Desenvolvimento\Python\vantia\backend\venv\lib\site-packages\pyproj\proj_dir\share\proj
PYTHON DEPENDENCIES
geopandas : 0.8.1 pandas : 1.1.0 fiona : 1.8.13 numpy : 1.19.1 shapely : 1.7.0 rtree : 0.9.4 pyproj : 2.6.1.post1 matplotlib : None mapclassify: None geopy : None psycopg2 : None geoalchemy2: None pyarrow : None
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
This seems to be fixed now, likely in rtree. The Colab notebook now works as expected even when executed second time. Feel free to reopen the issue if that is not the case.
I investigated further and I think that the problem can be Rtree package, when configuring the spatial index.
I created an example on Google Colab (Link below).
When I execute the code in the first time the results from clip it’s ok, but, I execute in the second time the same code, the kernel crash.
https://colab.research.google.com/drive/1zK7nBQ9bfYD62M-gXYmeGfZAlWzuu1uE?usp=sharing