Comments (4)
Simpler code snippet:
from geopandas import GeoDataFrame
from shapely import LineString
gdf1 = GeoDataFrame([
{"geometry": LineString([ (355041.15, 6688781.25, 0), (355040.9629213488, 6688781.437078651, 9.7) ])},
{"geometry": LineString([ (355041.1500000001, 6688781.25, 0), (354841.1500000001, 6688781.25, 0) ])}
], crs="epsg:2154")
gdf2 = gdf1.dissolve()
assert (len(gdf2.loc[0, "geometry"].geoms) == len(gdf1)), "Bug"
from geopandas.
@thomas-leduc I took a quick look, and will aim to return later. It seems to be a rounding error happening somewhere, resulting in a tiny small extra snippet.
If I truncate the first 5 digits from the x/y coords of the line string:
gdf1 = GeoDataFrame([
{"geometry": LineString([ (1.15, 81.25, 0), (0.9629213488, 81.437078651, 9.7) ])},
{"geometry": LineString([ (1.1500000001, 1.25, 0), (1.1500000001, 81.25, 0) ])}
], crs="epsg:2154")
gdf2 = gdf1.dissolve()
print(len(gdf2.loc[0, "geometry"].geoms) == len(gdf1))
# True
With the original geometry where the bug occurs:
gdf3.geometry.length
gdf1 = GeoDataFrame([
{"geometry": LineString([ (355041.15, 6688781.25), (355040.9629213488, 6688781.437078651) ])},
{"geometry": LineString([ (355041.1500000001, 6688781.25), (354841.1500000001, 6688781.25) ])}
], crs="epsg:2154")
gdf2 = gdf1.dissolve()
gdf3 = gpd.GeoDataFrame(geometry=[g for g in gdf2.loc[0, 'geometry'].geoms])
print(gdf3.geometry.length)
0 2.645692e-01
1 5.820766e-11
2 2.000000e+02
dtype: float64
from geopandas.
The same behaviour as in shapely/shapely#2028 is happening here, because under the hood dissolve
also uses shapely.union_all
...
from geopandas import GeoDataFrame
import shapely
from shapely import LineString
gdf1 = GeoDataFrame([
{"geometry": LineString([ (355041.15, 6688781.25, 0), (355040.9629213488, 6688781.437078651, 9.7) ])},
{"geometry": LineString([ (355041.15, 6688781.25, 0), (354841.1500000001, 6688781.25, 0) ])}
], crs="epsg:2154")
gdf2 = gdf1.dissolve()
print(f"{gdf2.loc[0, 'geometry']=}")
# gdf2.loc[0, 'geometry']=<MULTILINESTRING Z ((355041.15 6688781.25 0, 355040.963 6688781.437 9.7), (3...>
merged = shapely.line_merge(gdf1.geometry)
print(f"{merged[0]=}")
# merged[0]=<LINESTRING Z (355041.15 6688781.25 0, 355040.963 6688781.437 9.7)>
from geopandas.
@theroggy Thanks for tracing this upstream. I'll wait on discussion in libgeos/geos#1063 for now.
from geopandas.
Related Issues (20)
- BUG: plotting_with_geoplot example is broken HOT 1
- ENH: Add a Voronoi Diagram algorithm HOT 1
- REGR: incorrect order of left sjoin with within predicate HOT 1
- BUG: wrong foxpro DBF file read HOT 7
- Fiona 1.10a2 issues HOT 2
- ENH: support writing + filtered reading from bbox columns in GeoParquet HOT 4
- ENH: support reading and writing the geoarrow-based encodings of GeoParquet
- API: Series alignment for non binary op methods HOT 5
- PERF: optimize `==` and `!=` for GeoSeries (`GeometryArray.__eq__`)
- numpy dependency missing & numpy 2.0 support status? HOT 3
- ENH: inplace=True for .dissolve and .explode? HOT 4
- BUG: `pyogrio` doesn't like io.BytesIO? HOT 10
- BUG: Issue with webpage code interp HOT 1
- ENH: sjoin() should allow to return the distance when using the dwithin predicate, just like sjoin_nearest() HOT 3
- BUG: set_precision() doesn't work HOT 1
- ENH: CRS from GeoDataFrame not passed on to individual geometry objects HOT 3
- BUG: Unable to open files with fiona where filepath contains a # character HOT 3
- BUG: GeoJSON file from URL not recognized as a supported file format HOT 17
- BUG: append new df to old GDB file failed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geopandas.