from matplotlib import pyplot as plt
from matplotlib.path import Path
from matplotlib.patches import PathPatch

import numpy
import geopandas as gpd
from shapely.wkt import loads
import cartagen as c4

roads = [
    loads('LINESTRING (326314.98785256611881778 6260562.55106664914637804, 326358.22554529475746676 6260556.94618055410683155, 326390.25346583453938365 6260532.92524014972150326, 326413.4737082258798182 6260503.29941365029662848, 326434.29185657668858767 6260472.87288913782685995, 326466.31977711647050455 6260441.64566661138087511, 326491.1414155347738415 6260416.02333017904311419, 326523.16933607449755073 6260392.00238977465778589, 326564.80563277617329732 6260369.58284539729356766, 326608.04332550487015396 6260363.97795930225402117, 326650.48032021999824792 6260359.17377122119069099, 326693.71801294869510457 6260365.57935532927513123, 326752.1689679337432608 6260376.78912751842290163, 326789.80177456792443991 6260392.80308778770267963, 326825.03248716169036925 6260408.81704805791378021)'),
    loads('LINESTRING (326327.39867177529959008 6260442.44636462442576885, 326343.41263204516144469 6260447.25055270548909903, 326368.2342704635229893 6260452.85543879959732294, 326392.65555987507104874 6260454.05648582056164742, 326423.08208438783185557 6260450.8536937665194273, 326455.11000492755556479 6260434.83973349630832672, 326476.72885129193309695 6260414.02158514503389597, 326498.74804666300769895 6260386.79785268660634756, 326534.37910826341249049 6260345.56190499197691679, 326565.60633078968385234 6260327.14585068169981241, 326604.84053345088614151 6260314.33468246553093195, 326642.47334008506732062 6260306.32770233042538166, 326692.91731493518454954 6260306.32770233042538166, 326749.76687389326980338 6260309.53049438446760178, 326796.20735867589246482 6260319.93956856057047844, 326838.64435339107876644 6260334.35213280282914639)')
]

fig = plt.figure(1, (12, 12))

sub1 = fig.add_subplot(111)
sub1.set_aspect('equal')
sub1.axes.get_xaxis().set_visible(False)
sub1.axes.get_yaxis().set_visible(False)

for road in roads:
    path = Path(numpy.asarray(road.coords)[:, :2])
    sub1.add_patch(PathPatch(path, facecolor="none", edgecolor='gray', linewidth=1))
    sub1.autoscale_view()

displaced = c4.beams_displacement(gpd.GeoDataFrame(geometry=roads, crs=3857), 50, iterations=30)

for road in displaced.geometry:
    path = Path(numpy.asarray(road.coords)[:, :2])
    sub1.add_patch(PathPatch(path, facecolor="none", edgecolor='red', linewidth=1))
    sub1.autoscale_view()

plt.show()