Code Monkey home page Code Monkey logo

Comments (4)

thomas-leduc avatar thomas-leduc commented on June 2, 2024

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.

jdmcbr avatar jdmcbr commented on June 2, 2024

@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.

theroggy avatar theroggy commented on June 2, 2024

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.

jdmcbr avatar jdmcbr commented on June 2, 2024

@theroggy Thanks for tracing this upstream. I'll wait on discussion in libgeos/geos#1063 for now.

from geopandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.