BUG: clip returns empty line strings
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. I suppose 0.8.2 is the latest
-
(optional) I have confirmed this bug exists on the master branch of geopandas.
Code Sample, a copy-pastable example
import geopandas as gpd
from shapely.geometry import LineString, Polygon
data = {'geometry': [LineString ([(13.68, 51.06), (13.69, 51.06)]), #<- clipped to empty
LineString ([(13.68, 51.06), (13.69, 51.07)]),
LineString ([(13.68, 51.06), (13.68, 51.07)])]} #<- clipped to empty
gdf = gpd.GeoDataFrame(data, geometry='geometry', crs='EPSG:4326')
poly = Polygon([[13, 51], [13, 52], [14, 52], [14, 51], [13, 51]])
clipped_gdf = gpd.clip(gdf, poly)
print(clipped_gdf)
Problem description
Clipping of LineString that have identical values for latitude or longiture returns empty geometries.
Expected Output
LineStrings should be preserved upon clipping if they are inside the given polygone
SYSTEM INFO
python : 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:04:36) [MSC v.1916 64 bit (AMD64)] executable : C:\Users[USERNAME]\anaconda3\envs\testenv\python.exe machine : Windows-10-10.0.19041-SP0
GEOS, GDAL, PROJ INFO
GEOS : None GEOS lib : None GDAL : 3.1.4 GDAL data dir: None PROJ : 7.2.0 PROJ data dir: C:\Users[USERNAME]\anaconda3\envs\testenv\Library\share\proj
PYTHON DEPENDENCIES
geopandas : 0.8.2 pandas : 1.2.1 fiona : 1.8.18 numpy : 1.20.0 shapely : 1.7.1 rtree : 0.9.7 pyproj : 3.0.0.post1 matplotlib : 3.3.4 mapclassify: 2.4.2 geopy : 2.1.0 psycopg2 : None geoalchemy2: None pyarrow : None
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
I think this is caused by a regression in GEOS 3.9.0, which is fixed in GEOS 3.9.1 (see https://lists.osgeo.org/pipermail/geos-devel/2021-February/010138.html and https://github.com/libgeos/geos/issues/408).
I indeed can reproduce it in an environment with GEOS 3.9.0, and it does no longer return empty linestrings in an environment with GEOS 3.9.1. And @Oi-sin’s output of
conda list
also shows 3.9.0 is being used.@Oi-sin I see you are using conda-forge. Shapely is normally already available for GEOS 3.9.1 as well, so if you do an update of those packages, the issue should be resolved.
So going to close this issue then, since it’s fixed in GEOS 3.9.1.