1

Operations in Shapely

Suppose I have these two line geometries:

import shapely 

link_12 = shapely.wkb.loads(b"\x01\x02\x00\x00\x00$\x00\x00\x00\xcc\xd4\x02\x96q\xb9-A\x8a+\xd1)\xda\x801A\xb1\xf3\x1d\xff\x00\xbe-A\xcd`\xf8]\x11\x811A\x12\xbb\x7fQ\xe0\xbe-A\xb6\xc1\xbd\xb8\x1c\x811A&\x0e\xb5\xdc\x86\xbf-A\x05J\x17t!\x811AWFS\xe9\x12\xc0-A*\xd3L\x9d\x1e\x811A\xb8#6\xe5|\xc0-AY\xb7H\x0b\x17\x811A\xaf6\xa3\x1f\xf4\xc0-A\xaa]\x81\xa2\x0c\x811A\xaf\xc3\x17@m\xc1-A|\x17\x8c\x8c\xfc\x801AB\xa5\xf6\xdd\x00\xc2-Ag\x97\t\xf2\xe3\x801A}E\xb7\xd9'\xcb-A\xf5\x11\x06gX\x7f1A\x01M\xa7\xad\xda\xcb-A\xb0\xc5\xbf\x12=\x7f1A\xe3!m/\x94\xcc-A\xfb\n\xf8\xd0(\x7f1A\x15\x07E@\x97\xd3-Ao\x87\xa0\xf0i~1A!~C\xc9r\xd4-A\xeeO1\x1fU~1A\xf56UL\xaa\xd6-AC\x89@3K~1AT2J\x89 \xd9-A\xb1\xf4)GA~1A\xd8\xe2\x83\xa1\x12\xda-A\xe9\xdd\xa1\xd5F~1A\x88\xc1/\x8e\xee\xda-A8S{\x7fN~1A4F\xd6\x0b\x07\xdf-AsG\x84\x92\x81~1A\xcd\xdce\x15\xb4\xdf-AX\x19g\x86\x87~1AN\x0e\x0c\x95]\xe0-A\x9d\xba0F\x87~1AaCIp\xc1\xe0-AzDn\x9e\x82~1A\xe3)\xb1a/\xe1-AP{\x91\x9fy~1A\xb8\x9d\x8c\xcf\xb5\xe1-A\x04\x9c\xdeai~1A%6\xefx6\xe4-An\xffFn\x0c~1A#s\x165\x02\xe6-A\xeb\xf0\xf6>\xc7}1A&\x00\xd2\xd4\xf8\xe8-A~\xa1\x97\xc6X}1A\x10\xee\xfc\xa5\x80\xed-A\x17L9L\xab|1A\x1c<\xac],\xef-A?\x9fs\xcam|1A\xcb\xeej\xf1\xe3\xef-A\x8f\x89\x1dKS|1A3AZ\x98\x88\xf0-A\x98\x1d\xd2y>|1A<Ge\x1b\x1e\xf1-As\xa90\x114|1A\x11\xf8\xee^\xa6\xf1-A\xb9\x01\x1bH0|1AQW\x8cG#\xf2-A*1\xa5,2|1A\x0e\xd7\xfe\xe5\xb6\xf2-A\x0c'\x1a\xda7|1A\x9f \x9c\x1f\x15\xf3-Ay\x86d\xe9@|1A")

link_13 = shapely.wkb.loads(b'\x01\x05\x00\x00\x00\x01\x00\x00\x00\x01\x02\x00\x00\x00$\x00\x00\x00\xf9\x91\xda\xbfq\xb9-A\x94\x0c\xce+\xda\x801A\xf2\xfc\x1d\xff\x00\xbe-A\xf6\xa1\xff]\x11\x811Ar\xc4\x7fQ\xe0\xbe-A\xf2\x02\xc5\xb8\x1c\x811AO\x0e\xb5\xdc\x86\xbf-A<J\x17t!\x811A\x8aOS\xe9\x12\xc0-AZ\x14T\x9d\x1e\x811A\xdc,6\xe5|\xc0-A\x9b\xf8O\x0b\x17\x811A\xd86\xa3\x1f\xf4\xc0-A\xe7]\x81\xa2\x0c\x811A\xe3\xc3\x17@m\xc1-A\xac\x17\x8c\x8c\xfc\x801A\x9e\xa5\xf6\xdd\x00\xc2-A\x98\x97\t\xf2\xe3\x801A\xab4\xb7\xd9\'\xcb-A\x16\x90\xf7fX\x7f1ASM\xa7\xad\xda\xcb-A\xe6\xc5\xbf\x12=\x7f1A\x84*m/\x94\xcc-A7L\xff\xd0(\x7f1AY\x0fE@\x97\xd3-A\xaa\xc8\xa7\xf0i~1A[\x86C\xc9r\xd4-A)\x918\x1fU~1A\x1e7UL\xaa\xd6-A\x80\x89@3K~1A}2J\x89 \xd9-A\xe8\xf4)GA~1A\x01\xe3\x83\xa1\x12\xda-A\x1a\xde\xa1\xd5F~1A\xbc\xc1/\x8e\xee\xda-AoS{\x7fN~1A\x0f\xf3\xc9\x0b\x07\xdf-A\xd4\t}\x92\x81~1A\x00\xdde\x15\xb4\xdf-A\x8f\x19g\x86\x87~1Aw\x0e\x0c\x95]\xe0-A\xd4\xba0F\x87~1A\x8aCIp\xc1\xe0-A\xb0Dn\x9e\x82~1A@*\xb1a/\xe1-A\x81{\x91\x9fy~1A\xe2\x9d\x8c\xcf\xb5\xe1-A5\x9c\xdeai~1A:\x82\xfbx6\xe4-A\x82\xfcFn\x0c~1AVs\x165\x02\xe6-A(\xf1\xf6>\xc7}1A\x8f\x0e\xd2\xd4\xf8\xe8-A\xb8#\xa6\xc6X}1A\x82\xe7\xfc\xa5\x80\xed-AI\x0b2L\xab|1AE<\xac],\xef-Ai\x9fs\xcam|1A(\xefj\xf1\xe3\xef-A\xba\x89\x1dKS|1AD\x8df\x98\x88\xf0-A\xdc\x1a\xd2y>|1A\xd8@e\x1b\x1e\xf1-A\x9fh)\x114|1A\xf4\xfe\xee^\xa6\xf1-A\xfaB"H0|1A\x84W\x8cG#\xf2-AH1\xa5,2|1Aj\xd7\xfe\xe5\xb6\xf2-AC\'\x1a\xda7|1Aa\xd6\xc25\x15\xf3-A\xec\xbe\x86\xeb@|1A')

These are two linestrings that are nearly identical to each other.

When performing the symmetric difference in shapely, I can establish a grid_size parameter that controls the general precision of the operation.

Here are some examples:

# Case 1: 
shapely.symmetric_difference(link_12,link_13, grid_size=0).wkt
# 'MULTILINESTRING ((974008.7929903506 1147098.163347932, 974592.49827539 1147153.3670711995, 974704.1591776332 1147164.7216454572, 974787.4310688421 1147169.453480364, 974857.455713461 1147166.6144535043, 974910.4476786768 1147159.0440783112, 974970.061792096 1147148.6347864666, 975030.6251813079 1147132.5490126302, 975104.4335223811 1147107.9454588534, 975104.5129703763 1147107.918633994), (975104.5129703763 1147107.918633994, 976275.9252263751 1146712.402436373, 976365.3329148015 1146685.075149693), (976365.3329148015 1146685.075149693, 976365.3391670288 1146685.0732387118, 976458.0926294889 1146664.8162848342, 977355.6255266393 1146473.9399494787, 977465.3930930534 1146453.1218461948, 977749.1490876364 1146443.200203494, 978064.2681442001 1146433.277983945, 978185.3154593362 1146438.834501142, 978295.2777080992 1146446.4979755413, 978295.3409053219 1146446.5041325002), (978295.3409053219 1146446.5041325002, 978819.5231191576 1146497.5723309189, 978906.0314821224 1146503.5243012698), (978906.0314821224 1146503.5243012698, 978906.0417927742 1146503.5250106659, 978990.791107604 1146503.274181045, 979040.7193089538 1146498.6188700483, 979095.6908047762 1146489.6233136244, 979162.9053696906 1146473.3823030004, 979483.2362000389 1146380.43077084, 979713.103686903 1146311.245955522, 980092.4156646773 1146200.7757512028, 980479.0495019233 1146085.1153288884), (980479.0495019233 1146085.1153288884, 980672.3241953272 1146027.2977492863, 980886.1614191708 1145965.797020478), (980886.1614191708 1145965.797020478, 980886.1829546723 1145965.7908267525, 980977.9715189574 1145939.293419454, 981060.2975635886 1145918.4758623596, 981068.0997621993 1145917.3895159513), (981068.0997621993 1145917.3895159513, 981135.0535070668 1145908.0671487718, 981169.1154306919 1145906.1746294152), (981169.1154306919 1145906.1746294152, 981203.1854169389 1145904.28166209, 981265.6397425925 1145906.1743956306, 981339.4492099003 1145911.851961556, 981386.5617380327 1145920.911690144), (974008.8747144333 1147098.1711128103, 974592.4982756658 1147153.3671818948, 974704.1591779126 1147164.721756157, 974787.4310688468 1147169.4534803769, 974857.4557137352 1147166.6145642013, 974910.4476789492 1147159.0441890124, 974970.0617921008 1147148.6347864808, 975030.625181314 1147132.5490126414, 975104.4335223918 1147107.9454588648, 975104.5129703763 1147107.918633994), (975104.5129703763 1147107.918633994, 976275.9252258738 1146712.402215009, 976365.3329148015 1146685.075149693), (976365.3329148015 1146685.075149693, 976365.3391670383 1146685.0732387244, 976458.0926297461 1146664.816395534, 977355.6255268856 1146473.9400601783, 977465.3930932985 1146453.1219568944, 977749.1490876412 1146443.2002035081, 978064.2681442049 1146433.277983958, 978185.3154593409 1146438.8345011533, 978295.2777081053 1146446.497975554, 978295.3409053219 1146446.5041325002), (978295.3409053219 1146446.5041325002, 978819.523025127 1146497.5722204344, 978906.0314821224 1146503.5243012698), (978906.0314821224 1146503.5243012698, 978906.0417927802 1146503.5250106787, 978990.7911076088 1146503.2741810577, 979040.7193089586 1146498.618870061, 979095.690804787 1146489.6233136358, 979162.9053696955 1146473.3823030118, 979483.2362938591 1146380.4307706659, 979713.103686909 1146311.2459555361, 980092.4156651067 1146200.775972588, 980479.0495019233 1146085.1153288884), (980479.0495019233 1146085.1153288884, 980672.3241951319 1146027.297638612, 980886.1614191708 1145965.797020478), (980886.1614191708 1145965.797020478, 980886.182954677 1145965.7908267623, 980977.9715189682 1145939.293419464, 981060.2976574083 1145918.4758621966, 981068.0997621993 1145917.3895159513), (981068.0997621993 1145917.3895159513, 981135.0535068763 1145908.0670380963, 981169.1154306919 1145906.1746294152), (981169.1154306919 1145906.1746294152, 981203.1854171441 1145904.281772791, 981265.6397425984 1145906.1743956376, 981339.449209911 1145911.8519615687, 981386.6050021165 1145920.9200248076))'

# Case 2: 
shapely.symmetric_difference(link_12,link_13, grid_size=0.1).wkt
# 'LINESTRING (974008.8 1147098.2, 974008.9 1147098.2)'

Notice how, in the first case, setting grid_size=0 makes shapely not "notice" that the two lines are almost identical, thus generating a big MultiLineString geometry.

However, when I set grid_size=0.1 in the second case, shapely is able to understand that the two geometries are really similar and only give me the actual symmetric difference between the two.

Operations in Geopandas

How can I use this grid_size parameter when performing the symmetric_difference operation using two GeoPandas GeoDataFrames?

Here's an example of it being used without the grid_size parameter:

import geopandas as gpd

df_12 = gpd.GeoDataFrame({'id_12':[0],
                          'geometry':[link_12]},
                         crs="epsg:3081")

df_13 = gpd.GeoDataFrame({'id_13':[1],
                          'geometry':[link_13]},
                         crs="epsg:3081")

gpd_diff = df_12.symmetric_difference(df_13)

gpd_diff.geometry.values[0].wkt
# 'MULTILINESTRING ((974008.7929903506 1147098.163347932, 974592.49827539 1147153.3670711995, 974704.1591776332 1147164.7216454572, 974787.4310688421 1147169.453480364, 974857.455713461 1147166.6144535043, 974910.4476786768 1147159.0440783112, 974970.061792096 1147148.6347864666, 975030.6251813079 1147132.5490126302, 975104.4335223811 1147107.9454588534, 975104.5129703763 1147107.918633994), (975104.5129703763 1147107.918633994, 976275.9252263751 1146712.402436373, 976365.3329148015 1146685.075149693), (976365.3329148015 1146685.075149693, 976365.3391670288 1146685.0732387118, 976458.0926294889 1146664.8162848342, 977355.6255266393 1146473.9399494787, 977465.3930930534 1146453.1218461948, 977749.1490876364 1146443.200203494, 978064.2681442001 1146433.277983945, 978185.3154593362 1146438.834501142, 978295.2777080992 1146446.4979755413, 978295.3409053219 1146446.5041325002), (978295.3409053219 1146446.5041325002, 978819.5231191576 1146497.5723309189, 978906.0314821224 1146503.5243012698), (978906.0314821224 1146503.5243012698, 978906.0417927742 1146503.5250106659, 978990.791107604 1146503.274181045, 979040.7193089538 1146498.6188700483, 979095.6908047762 1146489.6233136244, 979162.9053696906 1146473.3823030004, 979483.2362000389 1146380.43077084, 979713.103686903 1146311.245955522, 980092.4156646773 1146200.7757512028, 980479.0495019233 1146085.1153288884), (980479.0495019233 1146085.1153288884, 980672.3241953272 1146027.2977492863, 980886.1614191708 1145965.797020478), (980886.1614191708 1145965.797020478, 980886.1829546723 1145965.7908267525, 980977.9715189574 1145939.293419454, 981060.2975635886 1145918.4758623596, 981068.0997621993 1145917.3895159513), (981068.0997621993 1145917.3895159513, 981135.0535070668 1145908.0671487718, 981169.1154306919 1145906.1746294152), (981169.1154306919 1145906.1746294152, 981203.1854169389 1145904.28166209, 981265.6397425925 1145906.1743956306, 981339.4492099003 1145911.851961556, 981386.5617380327 1145920.911690144), (974008.8747144333 1147098.1711128103, 974592.4982756658 1147153.3671818948, 974704.1591779126 1147164.721756157, 974787.4310688468 1147169.4534803769, 974857.4557137352 1147166.6145642013, 974910.4476789492 1147159.0441890124, 974970.0617921008 1147148.6347864808, 975030.625181314 1147132.5490126414, 975104.4335223918 1147107.9454588648, 975104.5129703763 1147107.918633994), (975104.5129703763 1147107.918633994, 976275.9252258738 1146712.402215009, 976365.3329148015 1146685.075149693), (976365.3329148015 1146685.075149693, 976365.3391670383 1146685.0732387244, 976458.0926297461 1146664.816395534, 977355.6255268856 1146473.9400601783, 977465.3930932985 1146453.1219568944, 977749.1490876412 1146443.2002035081, 978064.2681442049 1146433.277983958, 978185.3154593409 1146438.8345011533, 978295.2777081053 1146446.497975554, 978295.3409053219 1146446.5041325002), (978295.3409053219 1146446.5041325002, 978819.523025127 1146497.5722204344, 978906.0314821224 1146503.5243012698), (978906.0314821224 1146503.5243012698, 978906.0417927802 1146503.5250106787, 978990.7911076088 1146503.2741810577, 979040.7193089586 1146498.618870061, 979095.690804787 1146489.6233136358, 979162.9053696955 1146473.3823030118, 979483.2362938591 1146380.4307706659, 979713.103686909 1146311.2459555361, 980092.4156651067 1146200.775972588, 980479.0495019233 1146085.1153288884), (980479.0495019233 1146085.1153288884, 980672.3241951319 1146027.297638612, 980886.1614191708 1145965.797020478), (980886.1614191708 1145965.797020478, 980886.182954677 1145965.7908267623, 980977.9715189682 1145939.293419464, 981060.2976574083 1145918.4758621966, 981068.0997621993 1145917.3895159513), (981068.0997621993 1145917.3895159513, 981135.0535068763 1145908.0670380963, 981169.1154306919 1145906.1746294152), (981169.1154306919 1145906.1746294152, 981203.1854171441 1145904.281772791, 981265.6397425984 1145906.1743956376, 981339.449209911 1145911.8519615687, 981386.6050021165 1145920.9200248076))'

Notice how this is the same output geometry as the one I got using shapely and grid_size=0.

Main question

How can I control GeoPandas' symmetric_differences method to use grid_size=0.1 or any other value instead of the default? Is that even possible?

1 Answer 1

1

I don't think it's possible to specify a grid_size or tolerance when using the geopandas symmetric_difference or overlay methods.

You could play with shapely.ops.snap to snap the geometries.

import geopandas as gpd
import shapely
from shapely.ops import snap

tol = 0.05

link_12 = shapely.wkb.loads(b"\x01\x02\x00\x00\x00$\x00\x00\x00\xcc\xd4\x02\x96q\xb9-A\x8a+\xd1)\xda\x801A\xb1\xf3\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1d\xd2y>|1A<Ge\x1b\x1e\xf1-As\xa90\x114|1A\x11\xf8\xee^\xa6\xf1-A\xb9\x01\x1bH0|1AQW\x8cG#\xf2-A*1\xa5,2|1A\x0e\xd7\xfe\xe5\xb6\xf2-A\x0c'\x1a\xda7|1A\x9f \x9c\x1f\x15\xf3-Ay\x86d\xe9@|1A")
link_13 = shapely.wkb.loads(b'\x01\x05\x00\x00\x00\x01\x00\x00\x00\x01\x02\x00\x00\x00$\x00\x00\x00\xf9\x91\xda\xbfq\xb9-A\x94\x0c\xce+\xda\x801A\xf2\xfc\x1d\xff\x00\xbe-A\xf6\xa1\xff]\x11\x811Ar\xc4\x7fQ\xe0\xbe-A\xf2\x02\xc5\xb8\x1c\x811AO\x0e\xb5\xdc\x86\xbf-A<J\x17t!\x811A\x8aOS\xe9\x12\xc0-AZ\x14T\x9d\x1e\x811A\xdc,6\xe5|\xc0-A\x9b\xf8O\x0b\x17\x811A\xd86\xa3\x1f\xf4\xc0-A\xe7]\x81\xa2\x0c\x811A\xe3\xc3\x17@m\xc1-A\xac\x17\x8c\x8c\xfc\x801A\x9e\xa5\xf6\xdd\x00\xc2-A\x98\x97\t\xf2\xe3\x801A\xab4\xb7\xd9\'\xcb-A\x16\x90\xf7fX\x7f1ASM\xa7\xad\xda\xcb-A\xe6\xc5\xbf\x12=\x7f1A\x84*m/\x94\xcc-A7L\xff\xd0(\x7f1AY\x0fE@\x97\xd3-A\xaa\xc8\xa7\xf0i~1A[\x86C\xc9r\xd4-A)\x918\x1fU~1A\x1e7UL\xaa\xd6-A\x80\x89@3K~1A}2J\x89 \xd9-A\xe8\xf4)GA~1A\x01\xe3\x83\xa1\x12\xda-A\x1a\xde\xa1\xd5F~1A\xbc\xc1/\x8e\xee\xda-AoS{\x7fN~1A\x0f\xf3\xc9\x0b\x07\xdf-A\xd4\t}\x92\x81~1A\x00\xdde\x15\xb4\xdf-A\x8f\x19g\x86\x87~1Aw\x0e\x0c\x95]\xe0-A\xd4\xba0F\x87~1A\x8aCIp\xc1\xe0-A\xb0Dn\x9e\x82~1A@*\xb1a/\xe1-A\x81{\x91\x9fy~1A\xe2\x9d\x8c\xcf\xb5\xe1-A5\x9c\xdeai~1A:\x82\xfbx6\xe4-A\x82\xfcFn\x0c~1AVs\x165\x02\xe6-A(\xf1\xf6>\xc7}1A\x8f\x0e\xd2\xd4\xf8\xe8-A\xb8#\xa6\xc6X}1A\x82\xe7\xfc\xa5\x80\xed-AI\x0b2L\xab|1AE<\xac],\xef-Ai\x9fs\xcam|1A(\xefj\xf1\xe3\xef-A\xba\x89\x1dKS|1AD\x8df\x98\x88\xf0-A\xdc\x1a\xd2y>|1A\xd8@e\x1b\x1e\xf1-A\x9fh)\x114|1A\xf4\xfe\xee^\xa6\xf1-A\xfaB"H0|1A\x84W\x8cG#\xf2-AH1\xa5,2|1Aj\xd7\xfe\xe5\xb6\xf2-AC\'\x1a\xda7|1Aa\xd6\xc25\x15\xf3-A\xec\xbe\x86\xeb@|1A')

df_12 = gpd.GeoDataFrame({'id_12':[0], 'geometry':[link_12]}, crs="epsg:3081")
df_13 = gpd.GeoDataFrame({'id_13':[1], 'geometry':[link_13]}, crs="epsg:3081")

df_12.geometry = df_12.geometry.apply(lambda line: snap(line, df_13.geometry.unary_union, tolerance=tol))

df_123 = df_12.overlay(df_13, how='symmetric_difference')

Or if you want to replicate what grid_size is doing, you could use shapely.set_precision, similar to this geopandas enhancement request:

import geopandas as gpd
import shapely

tol = 0.1

link_12 = shapely.wkb.loads(b"\x01\x02\x00\x00\x00$\x00\x00\x00\xcc\xd4\x02\x96q\xb9-A\x8a+\xd1)\xda\x801A\xb1\xf3\x1d\xff\x00\xbe-A\xcd`\xf8]\x11\x811A\x12\xbb\x7fQ\xe0\xbe-A\xb6\xc1\xbd\xb8\x1c\x811A&\x0e\xb5\xdc\x86\xbf-A\x05J\x17t!\x811AWFS\xe9\x12\xc0-A*\xd3L\x9d\x1e\x811A\xb8#6\xe5|\xc0-AY\xb7H\x0b\x17\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
link_13 = shapely.wkb.loads(b'\x01\x05\x00\x00\x00\x01\x00\x00\x00\x01\x02\x00\x00\x00$\x00\x00\x00\xf9\x91\xda\xbfq\xb9-A\x94\x0c\xce+\xda\x801A\xf2\xfc\x1d\xff\x00\xbe-A\xf6\xa1\xff]\x11\x811Ar\xc4\x7fQ\xe0\xbe-A\xf2\x02\xc5\xb8\x1c\x811AO\x0e\xb5\xdc\x86\xbf-A<J\x17t!\x811A\x8aOS\xe9\x12\xc0-AZ\x14T\x9d\x1e\x811A\xdc,6\xe5|\xc0-A\x9b\xf8O\x0b\x17\x811A\xd86\xa3\x1f\xf4\xc0-A\xe7]\x81\xa2\x0c\x811A\xe3\xc3\x17@m\xc1-A\xac\x17\x8c\x8c\xfc\x801A\x9e\xa5\xf6\xdd\x00\xc2-A\x98\x97\t\xf2\xe3\x801A\xab4\xb7\xd9\'\xcb-A\x16\x90\xf7fX\x7f1ASM\xa7\xad\xda\xcb-A\xe6\xc5\xbf\x12=\x7f1A\x84*m/\x94\xcc-A7L\xff\xd0(\x7f1AY\x0fE@\x97\xd3-A\xaa\xc8\xa7\xf0i~1A[\x86C\xc9r\xd4-A)\x918\x1fU~1A\x1e7UL\xaa\xd6-A\x80\x89@3K~1A}2J\x89 \xd9-A\xe8\xf4)GA~1A\x01\xe3\x83\xa1\x12\xda-A\x1a\xde\xa1\xd5F~1A\xbc\xc1/\x8e\xee\xda-AoS{\x7fN~1A\x0f\xf3\xc9\x0b\x07\xdf-A\xd4\t}\x92\x81~1A\x00\xdde\x15\xb4\xdf-A\x8f\x19g\x86\x87~1Aw\x0e\x0c\x95]\xe0-A\xd4\xba0F\x87~1A\x8aCIp\xc1\xe0-A\xb0Dn\x9e\x82~1A@*\xb1a/\xe1-A\x81{\x91\x9fy~1A\xe2\x9d\x8c\xcf\xb5\xe1-A5\x9c\xdeai~1A:\x82\xfbx6\xe4-A\x82\xfcFn\x0c~1AVs\x165\x02\xe6-A(\xf1\xf6>\xc7}1A\x8f\x0e\xd2\xd4\xf8\xe8-A\xb8#\xa6\xc6X}1A\x82\xe7\xfc\xa5\x80\xed-AI\x0b2L\xab|1AE<\xac],\xef-Ai\x9fs\xcam|1A(\xefj\xf1\xe3\xef-A\xba\x89\x1dKS|1AD\x8df\x98\x88\xf0-A\xdc\x1a\xd2y>|1A\xd8@e\x1b\x1e\xf1-A\x9fh)\x114|1A\xf4\xfe\xee^\xa6\xf1-A\xfaB"H0|1A\x84W\x8cG#\xf2-AH1\xa5,2|1Aj\xd7\xfe\xe5\xb6\xf2-AC\'\x1a\xda7|1Aa\xd6\xc25\x15\xf3-A\xec\xbe\x86\xeb@|1A')

df_12 = gpd.GeoDataFrame({'id_12':[0], 'geometry':[link_12]}, crs="epsg:3081")
df_13 = gpd.GeoDataFrame({'id_13':[1], 'geometry':[link_13]}, crs="epsg:3081")

df_12.geometry = df_12.geometry.apply(lambda line: shapely.set_precision(line, tol))
df_13.geometry = df_13.geometry.apply(lambda line: shapely.set_precision(line, tol))

df_123 = df_12.overlay(df_13, how='symmetric_difference')

1
  • This is exactly what I was looking for! Both solutions are great!!! Thank you!!!
    – Felipe D.
    Jun 27, 2023 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.