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
from shapely import Point, Polygon
import cartagen as c4

from cartagen.utils.debug import plot_debug

# mountain = gpd.GeoDataFrame().from_file('test/mountain.geojson')

# width = 80

# lines, coals = c4.coalescence_splitting(mountain.geometry[0], width)
# galbed = c4.galbe(mountain, width)

# splitted = gpd.GeoDataFrame([{'coalescence': coals[i], 'geometry': g} for i, g in enumerate(lines)], crs = 3857)

# splitted.to_file('test/split.geojson')
# galbed.to_file('test/galbed.geojson')





# 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 i, l in enumerate(lines):
#     path3 = Path(numpy.asarray(l.coords)[:, :2])
#     sub1.add_patch(PathPatch(path3, facecolor="none", edgecolor='red', linewidth=width[coal[i]]))

# sub1.autoscale_view()
# plt.show()

# lines = [
#     loads('LINESTRING (-188576.50116454227827489 5357038.11717060580849648, -188568.81977856467710808 5357058.24138782359659672, -188562.01184532378101721 5357079.04958384297788143, -188555.70302793246810324 5357100.24862489476799965, -188549.5189895035000518 5357121.54537720233201981, -188543.08539314975496382 5357142.64670699369162321, -188536.02790198411094025 5357163.25948049873113632, -188527.97217911930056289 5357183.09056394174695015, -188518.54388766823103651 5357201.84682355262339115, -188507.36869074372225441 5357219.23512555658817291, -188494.07225145856500603 5357234.96233617886900902, -188476.57934188813669607 5357251.0307760126888752, -188456.14319089212222025 5357266.69844977185130119, -188433.38756187079707161 5357281.63780568260699511, -188408.93621822423301637 5357295.52129196561872959, -188383.41292335261823609 5357308.0213568489998579, -188357.44144065617001615 5357318.81044855620712042, -188331.64553353504743427 5357327.56101531069725752, -188306.64896538946777582 5357333.94550533778965473, -188283.07549961950280704 5357337.63636686000972986, -188261.54889962539891712 5357338.30604810453951359, -188245.61580801362288184 5357335.7480606883764267, -188230.46766633220249787 5357330.07718733325600624, -188215.93322458767215721 5357321.99727062415331602, -188201.84123278659535572 5357312.21215315442532301, -188188.02044093539007008 5357301.42567750997841358, -188174.29959904070710763 5357290.34168628230690956, -188160.50745710905175656 5357279.66402205917984247, -188146.47276514698751271 5357270.09652742929756641, -188132.02427316099056043 5357262.34304498229175806, -188116.99073115768260323 5357257.10741730593144894, -188101.1217681551061105 5357253.67263043485581875, -188084.05978312451043166 5357250.80733799003064632, -188066.23920401325449347 5357248.63034739159047604, -188048.09445876890094951 5357247.26046604849398136, -188030.05997533857589588 5357246.81650137528777122)'),
#     loads('LINESTRING (-188030.05997533857589588 5357246.81650137528777122, -188012.57018166987108998 5357247.41726079024374485, -187996.05950571005814709 5357249.18155170511454344, -187980.96237540661240928 5357252.22818153258413076, -187967.71321870695101097 5357256.67595768999308348, -187956.74646355837467127 5357262.64368759002536535, -187949.84877067938214168 5357269.51456126291304827, -187944.18133839030633681 5357279.00279429368674755, -187939.55005613854154944 5357290.31297818943858147, -187935.76081337183131836 5357302.64970446564257145, -187932.61949953739531338 5357315.21756462939083576, -187929.93200408288976178 5357327.22115019336342812, -187927.50421645576716401 5357337.86505266837775707, -187925.14202610345091671 5357346.35386356618255377, -187922.65132247353903949 5357351.89217439573258162, -187919.83799501342582516 5357353.6845766669139266, -187915.99913517676759511 5357348.15063739009201527, -187912.76486279122764245 5357333.95104226935654879, -187909.98230609204620123 5357313.25872099213302135, -187907.49859331449260935 5357288.24660325609147549, -187905.16085269383620471 5357261.08761875052005053, -187902.81621246528811753 5357233.95469716936349869, -187900.31180086408858187 5357209.02076820470392704, -187897.49474612562335096 5357188.45876155234873295, -187894.21217648495803587 5357174.44160690065473318, -187890.31122017747838981 5357169.14223394263535738, -187884.59828180525801145 5357176.47255875170230865, -187877.98959533451125026 5357196.8191042710095644, -187870.70250806221156381 5357226.92494015116244555, -187862.95436728530330583 5357263.53313604556024075, -187854.96252030081814155 5357303.38676159828901291, -187846.94431440558400936 5357343.22888646461069584, -187839.1170968966325745 5357379.80258029047399759, -187831.69821507099550217 5357409.85091272927820683, -187824.90501622552983463 5357430.11695342697203159, -187818.95484765723813325 5357437.34377203602343798, -187813.60922283757827245 5357428.02456559427082539, -187809.21631924007670023 5357403.43118345737457275, -187805.53625986544648185 5357367.38192572630941868, -187802.3291677144006826 5357323.69509249925613403, -187799.3551657876232639 5357276.18898387998342514, -187796.37437708582729101 5357228.68189996760338545, -187793.14692460975493304 5357184.99214086309075356, -187789.43293136003194377 5357148.93800666742026806, -187784.99252033742959611 5357124.33779748436063528, -187779.58581454263185151 5357115.00981341022998095, -187773.42632903894991614 5357122.43167085945606232, -187766.31036396863055415 5357143.25199209526181221, -187758.49474848533282056 5357174.1243920074775815, -187750.23631174286128953 5357211.70248548872768879, -187741.7918828948168084 5357252.6398874269798398, -187733.418291095062159 5357293.59021271672099829, -187725.37236549725639634 5357331.20707624964416027, -187717.91093525517499074 5357362.14409291557967663, -187711.2908295223605819 5357383.05487760528922081, -187705.76887745273415931 5357390.59304521232843399, -187703.10938356330734678 5357387.34919028542935848, -187701.77801509614801034 5357378.72513846307992935, -187701.31380716597777791 5357365.81951195001602173, -187701.25579488746006973 5357349.73093295097351074, -187701.14301337534561753 5357331.55802366882562637, -187700.51449774432694539 5357312.39940630830824375, -187698.90928310918388888 5357293.35370307415723801, -187695.86640458455076441 5357275.51953617110848427, -187690.92489728520740755 5357259.99552780203521252, -187683.62379632575903088 5357247.88030017167329788, -187671.31301837824867107 5357236.17118908185511827, -187655.22293168070609681 5357224.84481241181492805, -187636.21524982279515825 5357214.23616491723805666, -187615.15168639470357448 5357204.68024136126041412, -187592.89395498629892245 5357196.51203650794923306, -187570.30376918776892126 5357190.06654511205852032, -187548.24284258886473253 5357185.67876193951815367, -187527.57288877971586771 5357183.68368174880743027)'),
#     loads('LINESTRING (-187527.57288877971586771 5357183.68368174880743027, -187509.15562135027721524 5357184.41629929933696985, -187493.85275389050366357 5357188.21160935517400503, -187483.05543300090357661 5357195.67145638167858124, -187474.41412154273712076 5357207.56374913267791271, -187467.38444687289302237 5357222.77343471348285675, -187461.42203634817269631 5357240.18546023033559322, -187455.98251732537755743 5357258.68477278668433428, -187450.52151716145453975 5357277.15631948783993721, -187444.4946632131759543 5357294.48504743725061417, -187437.35758283743052743 5357309.55590374022722244, -187428.56590339110698551 5357321.25383550114929676, -187417.57525223094853573 5357328.46378982625901699, -187401.76577611034736037 5357330.71160441357642412, -187383.77284723217599094 5357327.36438927613198757, -187363.96931211568880826 5357319.67681212723255157, -187342.72801728011108935 5357308.90354067925363779, -187320.42180924455169588 5357296.29924264457076788, -187297.42353452829411253 5357283.1185857355594635, -187274.10603965050540864 5357270.61623766273260117, -187250.84217113038175739 5357260.04686614219099283, -187228.00477548711933196 5357252.66513888258486986, -187205.96669923991430551 5357249.72572359722107649, -187183.85556180623825639 5357251.3313650032505393, -187161.58778502585482784 5357256.26505106501281261, -187139.19877530791563913 5357263.78060743398964405, -187116.72393906160141341 5357273.13185976259410381, -187094.19868269603466615 5357283.57263369858264923, -187071.65841262036701664 5357294.35675489343702793, -187049.13853524386649951 5357304.73804899491369724, -187026.67445697559742257 5357313.97034165635704994, -187004.3015842247987166 5357321.30745852831751108, -186982.05532340056379326 5357326.00322525668889284, -186961.4786176317720674 5357328.17059058137238026, -186940.96656216646078974 5357329.01506579294800758, -186920.5077481274784077 5357328.77010208740830421, -186900.09076663784799166 5357327.66915066167712212, -186879.70420882035978138 5357325.94566271081566811, -186859.33666579803684726 5357323.83308943267911673, -186838.9767286938149482 5357321.56488202512264252, -186818.61298863048432395 5357319.37449168134480715, -186798.23403673115535639 5357317.49536960106343031, -186777.82846411853097379 5357316.16096697747707367)')
# ]

# line1 = c4.accordion(lines[1], 50, 1, sigma=15)

# gdf = gpd.GeoDataFrame(geometry=lines, crs=3857)
# prop = c4.propagation_network(lines, 1, line1)

# plot_debug(lines, [c4.smooth_platre(l) for l in prop])



# line = loads('LINESTRING (-185917.45307590774609707 5359519.96712400764226913, -185906.58792992815142497 5359536.05370518565177917, -185893.80620369254029356 5359552.25418544840067625, -185887.90886122957454063 5359566.39120934344828129, -185885.35285018256399781 5359578.95104553364217281, -185884.88721718164742924 5359582.70110402628779411, -185883.26967515287105925 5359585.55454584211111069, -185881.11986165048438124 5359586.37161950673907995, -185879.31589350572903641 5359586.06521153543144464, -185876.33570159543887712 5359584.4500298760831356, -185875.3270068250130862 5359578.99531293008476496, -185876.16464832093333825 5359558.26562362816184759, -185883.3652206952101551 5359540.60454063676297665, -185887.55586268057231791 5359527.80976279824972153, -185887.6306337125133723 5359512.77799385320395231, -185878.28307507612043992 5359496.37601498980075121, -185864.64318611493217759 5359479.4019124461337924, -185839.60780946246813983 5359460.20974204689264297, -185825.6239662712905556 5359449.04638669732958078, -185820.45352325035491958 5359447.56134432647377253, -185808.8805949138768483 5359444.66444906033575535, -185792.19571216113399714 5359445.93143546115607023, -185780.69110210085636936 5359453.50812148209661245, -185779.44371457505621947 5359455.6501903859898448, -185778.43856906518340111 5359459.57010461390018463, -185778.22237475813017227 5359462.89169287960976362, -185782.39838781341677532 5359475.46500025037676096, -185794.12245631316909567 5359494.89673524629324675, -185796.70089550074771978 5359499.0173630453646183, -185795.71283400728134438 5359505.55571939516812563, -185787.83487047353992239 5359521.05105013027787209)')
# # line = loads('LINESTRING (-187133.6843829232675489 5358740.24988881684839725, -187140.64296457346063107 5358727.8420827379450202, -187143.44190161232836545 5358721.74763568677008152, -187147.17340091758524068 5358712.8405630849301815, -187148.23102621952421032 5358702.85208225715905428, -187147.43041390884900466 5358696.28278788831084967, -187145.3016120259417221 5358690.48187993746250868, -187141.79464649292640388 5358682.28170086443424225, -187137.16949667793232948 5358676.07807950954884291, -187117.79570931094349362 5358659.72466421592980623, -187109.09788425153237768 5358656.65853399503976107, -187085.23515185824362561 5358648.01650694757699966, -187059.65921167790656909 5358642.92277658544480801, -187038.42786031807190739 5358640.60085793398320675, -187029.87459020930691622 5358641.3868341064080596, -187020.85898117569740862 5358644.66944047156721354, -187010.82622650754638016 5358649.70893475227057934, -186979.13471526090870611 5358670.3176660193130374, -186962.29795583593659103 5358682.90814032591879368, -186953.09796594217186794 5358689.93504794593900442, -186937.66061172721674666 5358702.98532941471785307, -186933.24332087946822867 5358709.58960853144526482, -186930.72153019707184285 5358722.69801979046314955, -186930.80508941670996137 5358728.75862121302634478, -186931.21808514004806057 5358733.42107066418975592, -186932.41176921772421338 5358737.34776921011507511, -186933.89546087954659015 5358741.53291073720902205, -186936.03108103913837112 5358745.12782053649425507, -186939.02048142664716579 5358749.22331398725509644, -186951.95711180169018917 5358758.92998361028730869, -186974.41870098790968768 5358767.10450428444892168, -186993.22510919201886281 5358776.18590828031301498, -187003.75480277021415532 5358787.00084804184734821, -187009.69547757579130121 5358799.19190483074635267, -187011.23846463192603551 5358809.02560300193727016, -187011.65150662540690973 5358813.68809079844504595, -187011.52633418841287494 5358820.8640311798080802, -187011.30369359170435928 5358826.39151355903595686, -187009.65655670978594571 5358833.38238442223519087, -186998.65617140830727294 5358847.1337472228333354, -186978.99838291321066208 5358858.50565106235444546, -186971.55098026321502402 5358860.32766922563314438, -186965.2218280958768446 5358860.15311014652252197, -186946.9859903602336999 5358849.10759496875107288, -186932.02963657584041357 5358842.41603875625878572, -186912.81600903204525821 5358840.38931779004633427)')
# line = loads('LINESTRING (-185746.44424586402601562 5359655.44799901638180017, -185745.23733834514860064 5359658.27704177610576153, -185743.65129126963438466 5359659.33633125945925713, -185742.58042077987920493 5359659.81354742497205734, -185737.24055764352669939 5359657.78700889647006989, -185692.99677001620875672 5359611.05874184332787991, -185687.15713059311383404 5359607.54534002486616373, -185682.0676414284389466 5359607.43404213897883892, -185677.26983414878486656 5359612.26861297525465488, -185672.68436018313514069 5359625.36257639061659575, -185669.56032862153369933 5359649.26125307474285364, -185666.22226853464962915 5359660.21316453721374273, -185665.396973732043989 5359671.84304735157638788, -185664.07744648776133545 5359675.09237423446029425, -185662.95069300016621128 5359676.95157619565725327, -185660.03616374282864854 5359678.77909488324075937, -185652.74006279301829636 5359678.52310161013156176, -185643.87831003879546188 5359675.48722284566611052, -185630.44668216069112532 5359670.88576709479093552, -185616.12581449953722768 5359663.32637480925768614, -185608.71466287426301278 5359656.4595493758097291, -185602.4827399006462656 5359645.39728448167443275, -185601.3496646752464585 5359643.38596459571272135, -185595.53742685905308463 5359629.24329777900129557, -185595.14443877298617736 5359628.54978939238935709, -185594.58963206323096529 5359628.27238603681325912, -185593.91924062225734815 5359628.31861992925405502, -185593.38755085875163786 5359628.82719274703413248, -185593.04079666515463032 5359629.61316891852766275, -185591.76936462195590138 5359634.0053887041285634, -185590.96027150354348123 5359638.97553214617073536, -185589.98234935908112675 5359653.29813140723854303, -185591.22826136177172884 5359669.76821622531861067, -185599.04692942596739158 5359690.53549718763679266)')

# a = c4.accordion(line, 100)

# plot_debug(line, a)

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

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

buildings = [
    loads('POLYGON ((-16445769.90343573503196239 9565194.61930340714752674, -16445792.84602352418005466 9565217.9208535123616457, -16445776.92295048944652081 9565233.54289877600967884, -16445800.75452758930623531 9565257.8121693879365921, -16445810.88958853296935558 9565247.98951656185090542, -16445815.1017750333994627 9565252.34511262737214565, -16445816.81570799462497234 9565255.65360098518431187, -16445803.91874257661402225 9565268.27381659671664238, -16445822.15288663841784 9565286.94194398634135723, -16445841.34366313554346561 9565277.72974181361496449, -16445847.46795775182545185 9565272.00128521397709846, -16445854.27475111372768879 9565278.98447582684457302, -16445860.17558612860739231 9565278.06259039789438248, -16445875.74638394080102444 9565262.71289533749222755, -16445863.91059311293065548 9565250.68171883933246136, -16445858.70656732283532619 9565253.05072155222296715, -16445855.22309414483606815 9565249.4555655550211668, -16445854.39750245772302151 9565243.47427018918097019, -16445853.10021414794027805 9565242.16049247048795223, -16445852.42708230577409267 9565238.37819834798574448, -16445918.42495660670101643 9565173.77619693800806999, -16445913.48404448293149471 9565168.66014488600194454, -16445906.59748032502830029 9565163.39363366365432739, -16445878.55377110280096531 9565134.76883729174733162, -16445866.46533393673598766 9565146.43287067674100399, -16445861.11606256477534771 9565140.9706835076212883, -16445855.78433665446937084 9565146.08628677576780319, -16445811.88466941006481647 9565153.55259451828896999, -16445769.90343573503196239 9565194.61930340714752674))'),
    loads('POLYGON ((-16445673.03684977442026138 9565176.6483513880521059, -16445665.90061257034540176 9565180.34316345863044262, -16445653.5893903411924839 9565192.62301020510494709, -16445640.3486892506480217 9565199.61323594488203526, -16445628.45425108447670937 9565211.50580072216689587, -16445616.37973554059863091 9565199.2317900825291872, -16445624.93457353301346302 9565190.72240895964205265, -16445584.17282082512974739 9565149.86659961007535458, -16445565.70597401633858681 9565168.28639988414943218, -16445555.74040162935853004 9565158.38791372813284397, -16445550.52516151033341885 9565163.51411633379757404, -16445555.37781883217394352 9565172.84971715696156025, -16445542.33458356186747551 9565185.9497199971228838, -16445545.40880368277430534 9565191.62371978349983692, -16445536.96070533618330956 9565199.89408565871417522, -16445571.18202736973762512 9565234.10162506811320782, -16445574.18088417313992977 9565232.5734377671033144, -16445586.96177498623728752 9565245.44969083182513714, -16445585.96509834006428719 9565249.59247013740241528, -16445595.12261356040835381 9565258.84340568818151951, -16445597.70395467802882195 9565263.43709457106888294, -16445604.53970895893871784 9565265.0560989286750555, -16445621.08936811238527298 9565256.38929185084998608, -16445649.86563412100076675 9565262.93190191499888897, -16445655.55329562537372112 9565260.02381126396358013, -16445661.29212603718042374 9565254.27116234041750431, -16445659.8135148286819458 9565251.03017182089388371, -16445669.72556527704000473 9565241.11965942569077015, -16445680.13421580567955971 9565243.47403953783214092, -16445710.07870760932564735 9565213.54897686652839184, -16445673.03684977442026138 9565176.6483513880521059))'),
    loads('POLYGON ((-16445483.29433412849903107 9565178.98152867332100868, -16445477.90432207100093365 9565172.52430536411702633, -16445479.14066466316580772 9565167.62205064855515957, -16445465.98266351781785488 9565151.04736647196114063, -16445459.81279468163847923 9565147.39936141110956669, -16445457.20671865344047546 9565149.38399451225996017, -16445436.7125804927200079 9565144.72876629047095776, -16445427.53108084015548229 9565152.07889371551573277, -16445411.4249127060174942 9565148.25535679422318935, -16445401.92636869288980961 9565156.03714415989816189, -16445399.78957432322204113 9565159.95805237255990505, -16445385.70025909319519997 9565171.41495081596076488, -16445384.95206265710294247 9565172.8014993853867054, -16445379.73355873115360737 9565177.05534337274730206, -16445373.60899900086224079 9565208.20278927311301231, -16445372.0048083458095789 9565211.21463017351925373, -16445369.27848801016807556 9565223.20393527485430241, -16445366.564603291451931 9565225.4273363184183836, -16445387.00854126736521721 9565250.75250991247594357, -16445390.27416198328137398 9565251.3648095391690731, -16445393.71724938787519932 9565248.60845630988478661, -16445400.34361305460333824 9565250.16340492479503155, -16445445.73773754015564919 9565213.46771560423076153, -16445457.35448097996413708 9565216.41374660655856133, -16445467.58224273659288883 9565208.09897370077669621, -16445483.29433412849903107 9565178.98152867332100868))'),
    loads('POLYGON ((-16445298.27468828484416008 9565232.23113539628684521, -16445356.01376059465110302 9565148.00431583635509014, -16445357.0734139047563076 9565139.52773570455610752, -16445337.78744398057460785 9565126.21552732400596142, -16445344.83712434768676758 9565115.98329763673245907, -16445304.18607483617961407 9565088.16255086474120617, -16445295.59602989442646503 9565100.59334020502865314, -16445276.43620028160512447 9565087.53594640456140041, -16445255.21472355723381042 9565118.317164221778512, -16445269.76526298001408577 9565128.30179925449192524, -16445269.03469766117632389 9565133.981042155995965, -16445262.70967242494225502 9565143.36824057810008526, -16445262.21708244271576405 9565146.75859333388507366, -16445264.15107865259051323 9565148.12377315945923328, -16445262.56362100876867771 9565159.22728428803384304, -16445258.59468923695385456 9565165.06241135857999325, -16445255.17615172453224659 9565164.62385800294578075, -16445234.94995610043406487 9565150.7986628282815218, -16445199.97284563630819321 9565202.04580828733742237, -16445223.86822386831045151 9565218.43087673373520374, -16445229.44999330304563046 9565210.31269338168203831, -16445258.55088653974235058 9565230.2818042729049921, -16445267.35833560861647129 9565217.59751206450164318, -16445286.44550728425383568 9565230.73924398235976696, -16445298.27468828484416008 9565232.23113539628684521))'),
    loads('POLYGON ((-16445900.94107409752905369 9565069.69617463834583759, -16445900.52545591071248055 9564993.75357603281736374, -16445867.69554758258163929 9564993.77934299595654011, -16445867.60971730202436447 9564982.23543832451105118, -16445865.33002951554954052 9564981.19866980984807014, -16445851.71750888600945473 9564981.42505143582820892, -16445849.00876138918101788 9564987.53070319816470146, -16445845.85206511057913303 9564987.37340268678963184, -16445838.79554681479930878 9564984.21533236838877201, -16445835.90887295268476009 9564984.38536521233618259, -16445828.14742149785161018 9564980.80443611554801464, -16445806.80445409007370472 9564980.94102218002080917, -16445804.75885204412043095 9564985.58418905548751354, -16445797.46331639215350151 9564985.58991718292236328, -16445789.0494993906468153 9564981.86569732986390591, -16445775.00206642411649227 9564981.99656078778207302, -16445769.25478632934391499 9564994.67151856794953346, -16445717.31261405907571316 9564995.05585910566151142, -16445706.97584365122020245 9565018.24796009995043278, -16445714.84601929411292076 9565021.85278647765517235, -16445714.9088993277400732 9565044.91695499606430531, -16445702.38724144361913204 9565044.84692544303834438, -16445702.48022894933819771 9565055.32044675573706627, -16445716.97200529836118221 9565061.98784920386970043, -16445717.03982073254883289 9565076.20826661214232445, -16445790.48629660904407501 9565075.99060318991541862, -16445806.39153264090418816 9565082.96846438199281693, -16445812.19500652141869068 9565070.03766644187271595, -16445900.94107409752905369 9565069.69617463834583759))'),
    loads('POLYGON ((-16445488.46124071069061756 9565094.3113662376999855, -16445577.87631641142070293 9565095.41829439997673035, -16445585.13654625415802002 9565098.65749361366033554, -16445590.97733942791819572 9565111.32028840109705925, -16445588.28873666748404503 9565117.4034637026488781, -16445592.1689129825681448 9565119.11856903880834579, -16445592.17384812980890274 9565122.96687756851315498, -16445594.83390822634100914 9565124.15769388154149055, -16445636.6060217022895813 9565124.66807053610682487, -16445638.53429365903139114 9564980.46431903913617134, -16445589.08891759440302849 9564979.76224717870354652, -16445586.88411200419068336 9564985.09773928672075272, -16445586.81148847937583923 9564993.40393006056547165, -16445584.18336765840649605 9564999.39364967495203018, -16445577.62026295810937881 9565002.30689920112490654, -16445573.67387440428137779 9565002.1400337778031826, -16445561.472601268440485 9564996.89707169681787491, -16445558.63182720355689526 9564990.68348870053887367, -16445556.63050219602882862 9564995.22251051291823387, -16445556.44834152236580849 9565000.80602226778864861, -16445551.41912153363227844 9565000.86664807423949242, -16445542.20656754449009895 9565004.98257021233439445, -16445537.91938377171754837 9565004.86037549376487732, -16445530.59859562292695045 9565001.71458254754543304, -16445522.52932999655604362 9565005.5095415897667408, -16445515.13666358776390553 9565005.36681438982486725, -16445512.24459870532155037 9565012.24647192656993866, -16445504.57161756977438927 9565012.05495882779359818, -16445496.56281632743775845 9565015.7564508318901062, -16445489.52231262251734734 9565012.65942418947815895, -16445488.46124071069061756 9565094.3113662376999855))'),
    loads('POLYGON ((-16445229.21599313803017139 9565042.37352433428168297, -16445245.13238558359444141 9565041.78410887718200684, -16445245.34804894775152206 9565049.64511938206851482, -16445346.4170769639313221 9565045.98110156133770943, -16445347.12281009741127491 9565065.62201193906366825, -16445401.77523212507367134 9565063.63293547369539738, -16445400.68919301219284534 9565033.77969861961901188, -16445422.50940128788352013 9565033.03942657820880413, -16445422.00232863798737526 9565019.42301953583955765, -16445440.13967283628880978 9565018.67808906547725201, -16445439.76065624505281448 9565006.89049328677356243, -16445424.84369221888482571 9565007.40992887504398823, -16445419.72364374622702599 9564999.62982792221009731, -16445389.44552543759346008 9565000.69980327412486076, -16445389.0639372244477272 9564992.06284805573523045, -16445384.82840951159596443 9564988.94646615348756313, -16445380.22572669014334679 9564982.18030309118330479, -16445376.82241263426840305 9564979.79325822181999683, -16445351.31934093497693539 9564980.52888117171823978, -16445338.68363113701343536 9564997.69083508104085922, -16445316.91416865587234497 9564981.62530761212110519, -16445295.20500842295587063 9564982.35781046003103256, -16445284.98348115757107735 9564989.37437553331255913, -16445282.53785983100533485 9564992.69604298286139965, -16445282.69992635399103165 9564998.19793575443327427, -16445275.12653571926057339 9565003.19133865088224411, -16445275.32647659443318844 9565007.64044425077736378, -16445265.82740355655550957 9565013.81883550994098186, -16445243.89614792726933956 9565014.56688662245869637, -16445243.87914133816957474 9565012.73032645136117935, -16445228.16655077785253525 9565013.04293776303529739, -16445229.21599313803017139 9565042.37352433428168297))'),
]

fig = plt.figure(1, (16, 8))

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

sub2 = fig.add_subplot(212)
sub2.set_aspect('equal')
sub2.axes.get_xaxis().set_visible(False)
sub2.axes.get_yaxis().set_visible(False)

for building in buildings:
    poly = Path.make_compound_path(Path(numpy.asarray(building.exterior.coords)[:, :2]),*[Path(numpy.asarray(ring.coords)[:, :2]) for ring in building.interiors])
    sub1.add_patch(PathPatch(poly, facecolor="lightgray", edgecolor='black'))

    generalized = c4.regularize_building_rectangle(building)
    poly = Path.make_compound_path(Path(numpy.asarray(generalized.exterior.coords)[:, :2]),*[Path(numpy.asarray(ring.coords)[:, :2]) for ring in generalized.interiors])
    sub2.add_patch(PathPatch(poly, facecolor="lightgray", edgecolor='red', linewidth=1.5))

sub1.autoscale_view()
sub2.autoscale_view()

plt.show()