Skip to main content
Tweeted twitter.com/StackGIS/status/1046052357556109313
Mod Moved Comments To Chat
added 1321 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71

I would like to perform the following operation using geopandas.

enter image description here [![enter image description here][1]][1]

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

EDIT Unfortunately I cannot get this to work for more complicated geometries such as

ORIGINAL_LINES

                                            geometry property
0  (LINESTRING (0 0, 6.656423206909781 4.43757029...        a
1  (LINESTRING (6.656423206909781 4.4375702913320...        b
2  (LINESTRING (8.070636769282876 5.8517838537051...        c
3  (LINESTRING (6.656423206909781 4.4375702913320...        d
4  (LINESTRING (10.98655022583197 1.9375702913320...        e
5  (LINESTRING (13.68293236472948 0.6224568509648...        a
6  (LINESTRING (17.54663566988575 -0.412819329445...        a

SPLIT_LINES

                                            geometry  susc
0  LINESTRING (0 0, 4.160264504318614 2.773481432...     1
1  LINESTRING (4.160264504318614 2.77348143208253...     2
2  LINESTRING (6.656423206909781 4.43757029133205...     3
3  LINESTRING (9.950815132334437 8.18950268263064...     4
4  LINESTRING (13.08444573742037 12.0857007308397...     5
5  LINESTRING (6.656423206909781 4.43757029133205...     4
6  LINESTRING (10.98655022583197 1.93757029133205...     3
7  LINESTRING (15.61478401730761 0.10481876075978...     2

The output seem to be a 1D line... which is incorrect for this application. [1]: https://i.sstatic.net/rtcuE.png

I would like to perform the following operation using geopandas.

enter image description here

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

I would like to perform the following operation using geopandas.

[![enter image description here][1]][1]

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

EDIT Unfortunately I cannot get this to work for more complicated geometries such as

ORIGINAL_LINES

                                            geometry property
0  (LINESTRING (0 0, 6.656423206909781 4.43757029...        a
1  (LINESTRING (6.656423206909781 4.4375702913320...        b
2  (LINESTRING (8.070636769282876 5.8517838537051...        c
3  (LINESTRING (6.656423206909781 4.4375702913320...        d
4  (LINESTRING (10.98655022583197 1.9375702913320...        e
5  (LINESTRING (13.68293236472948 0.6224568509648...        a
6  (LINESTRING (17.54663566988575 -0.412819329445...        a

SPLIT_LINES

                                            geometry  susc
0  LINESTRING (0 0, 4.160264504318614 2.773481432...     1
1  LINESTRING (4.160264504318614 2.77348143208253...     2
2  LINESTRING (6.656423206909781 4.43757029133205...     3
3  LINESTRING (9.950815132334437 8.18950268263064...     4
4  LINESTRING (13.08444573742037 12.0857007308397...     5
5  LINESTRING (6.656423206909781 4.43757029133205...     4
6  LINESTRING (10.98655022583197 1.93757029133205...     3
7  LINESTRING (15.61478401730761 0.10481876075978...     2

The output seem to be a 1D line... which is incorrect for this application. [1]: https://i.sstatic.net/rtcuE.png

deleted 12 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Intersecting MultiLinestring based geodataframes with geopandas?

I would like to perform the following operation using geopandas.

enter image description here

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

Thanks

Intersecting MultiLinestring based geodataframes with geopandas

I would like to perform the following operation using geopandas.

enter image description here

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

Thanks

Intersecting MultiLinestring based geodataframes with geopandas?

I would like to perform the following operation using geopandas.

enter image description here

The segments are delimited by red points and the blue items are attribute information. My inputs are the first and second line segments and my output is the third line segment.

Initially I thought this would be an intersection operation, but I soon learned that geopandas can only intersect polygons, therefore something like:

intersection = geopandas.overlay(split_lines, original_lines, how='intersection')

returns the following error:

raise TypeError("overlay only takes GeoDataFrames with (multi)polygon "
TypeError: overlay only takes GeoDataFrames with (multi)polygon

This to me looks like a standard geoprocessing operation and I really hope I won't have to code this up from scratch. Are there any simplified ways to come up with the following result without having to code a custom function?

deleted 957 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71

[![enter image description here][1]][1]enter image description here

Thanks

EDIT

Using @Jon's script I get the following result

                    geometry property
0    (LINESTRING (0 0, 7 0))        a
1   (LINESTRING (7 0, 13 0))        b
2  (LINESTRING (13 0, 15 0))        c
3  (LINESTRING (15 0, 19 0))        d
                        geometry  susc
0          LINESTRING (0 0, 5 0)     1
1    LINESTRING (5 0, 7 0, 10 0)     2
2  LINESTRING (10 0, 13 0, 15 0)     3
3        LINESTRING (15 0, 19 0)     4
                  geometry  attrib_1 attrib_2
0    LINESTRING (0 0, 5 0)         1        a
1    LINESTRING (5 0, 7 0)         1        a
2   LINESTRING (7 0, 10 0)         2        a
3  LINESTRING (10 0, 13 0)         2        a
4  LINESTRING (13 0, 15 0)         3        b
5  LINESTRING (15 0, 19 0)         3        c

The attribute a seems to be carried over until x=13, which does not fit with the illustration above [1]: https://i.sstatic.net/rtcuE.png

[![enter image description here][1]][1]

Thanks

EDIT

Using @Jon's script I get the following result

                    geometry property
0    (LINESTRING (0 0, 7 0))        a
1   (LINESTRING (7 0, 13 0))        b
2  (LINESTRING (13 0, 15 0))        c
3  (LINESTRING (15 0, 19 0))        d
                        geometry  susc
0          LINESTRING (0 0, 5 0)     1
1    LINESTRING (5 0, 7 0, 10 0)     2
2  LINESTRING (10 0, 13 0, 15 0)     3
3        LINESTRING (15 0, 19 0)     4
                  geometry  attrib_1 attrib_2
0    LINESTRING (0 0, 5 0)         1        a
1    LINESTRING (5 0, 7 0)         1        a
2   LINESTRING (7 0, 10 0)         2        a
3  LINESTRING (10 0, 13 0)         2        a
4  LINESTRING (13 0, 15 0)         3        b
5  LINESTRING (15 0, 19 0)         3        c

The attribute a seems to be carried over until x=13, which does not fit with the illustration above [1]: https://i.sstatic.net/rtcuE.png

enter image description here

Thanks

added 760 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading
deleted 475 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading
added 696 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading
added 484 characters in body
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading
Source Link
user32882
  • 3.6k
  • 2
  • 32
  • 71
Loading