question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jorisvandenbosschecommented, Feb 23, 2021

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.

1reaction
jorisvandenbosschecommented, Mar 5, 2021

So going to close this issue then, since it’s fixed in GEOS 3.9.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EmptyLines removes empty lines from heredoc strings #815
Seems that the tokens in the source are mixed up, which is causing the problem. The newline on the first line appear in...
Read more >
Remove blank lines with grep - Stack Overflow
So the command grep -v will print all the lines that do not match this pattern (No characters between ^ and $). This...
Read more >
grep with colored output returns several empty lines
The reason it is printing empty lines is the carriage return ( \r ). You are asking grep to find the string spacer">...
Read more >
JDK-4189266 component should not paint under its border
To get it, I overrode the paint method and set a clip rect. That work-around broke the empty border, as evidenced by the...
Read more >
How do I print an empty line in Python? - Quora
This implies that if an empty line is read the function will convert it to a string, strip away the trailing newline, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found