TransWikia.com

Getting error while trying to read multipolygon data using shapely wkt.loads (Python)

Geographic Information Systems Asked by user3733504 on July 3, 2021

I have a CSV file from which I’m trying to read multipolygons using wkt.loads of shapely.

While this works:

from shapely import wkt
x='MULTIPOLYGON(((18.62981086588664 73.79447461830097,18.62987224993655 73.79446458707679,18.62984444555452 73.79444858335238,18.62981086588664 73.79447461830097)),((18.60366850268919 73.83258527981431,18.60293379925239 73.83366107940675,18.60408738269134 73.8323100884229,18.60366850268919 73.83258527981431)),((18.61529797450824 73.84546279907228,18.61480993199179 73.84567737579347,18.61468792114388 73.84576320648195,18.61529797450824 73.84546279907228)),((18.62966110851256 73.79432285536272,18.6297911827829 73.79436403543156,18.62965393195597 73.79430770874025,18.62966110851256 73.79432285536272)),((18.6297911827829 73.79436403543156,18.63038593129738 73.79460811614992,18.63042659783501 73.79456520080568,18.6297911827829 73.79436403543156)),((18.60030744889924 73.83558000367456,18.60041204796367 73.83563518524171,18.60138821418421 73.83512020111085,18.60030744889924 73.83558000367456)),((18.5938933851391 73.84556664541741,18.59398548064061 73.84584903717042,18.59404784572125 73.84583377153093,18.5938933851391 73.84556664541741)),((18.59404784572125 73.84583377153093,18.59418885674043 73.84610652923585,18.59569383233065 73.84743690490724,18.59698993308361 73.847904734012,18.59404784572125 73.84583377153093)),((18.59698993308361 73.847904734012,18.59772756199739 73.84842395782472,18.59800438242932 73.84831247842672,18.59698993308361 73.847904734012)),((18.60090477734195 73.84951703332172,18.5968733984958 73.84533405303956,18.59800438242932 73.84831247842672,18.60090477734195 73.84951703332172)),((18.60090477734195 73.84951703332172,18.60106282606597 73.84958267211915,18.60207966187046 73.84984016418458,18.60313716466402 73.84988307952882,18.60377279605911 73.84983517423227,18.60090477734195 73.84951703332172)),((18.60377279605911 73.84983517423227,18.60792455608189 73.85041926980503,18.60752979824853 73.85026931762697,18.60590291013964 73.84979724884035,18.60427600647906 73.84979724884035,18.60377279605911 73.84983517423227)),((18.60792455608189 73.85041926980503,18.60937697515843 73.8509709838614,18.60927868561922 73.85078430175783,18.60838390827974 73.85048389434816,18.60792455608189 73.85041926980503)),((18.60937697515843 73.8509709838614,18.60948204344929 73.85117053985597,18.61180030553372 73.84915351867677,18.60956338651327 73.85104179382326,18.60937697515843 73.8509709838614)),((18.56343563400318 73.79241943359376,18.56347631653302 73.79276275634767,18.5641272356913 73.79323482513429,18.56522565613935 73.79490852355958,18.56587656862307 73.79529476165773,18.56644611500894 73.79585266113283,18.56693429611186 73.79589557647706,18.56685293269173 73.79606723785402,18.56835814968169 73.79808425903322,18.56900905021195 73.79980087280275,18.56953790506375 73.80177497863771,18.56953790506375 73.80340576171876,18.56909041260358 73.80482196807863,18.56835814968169 73.80795478820802,18.56742247581762 73.81155967712404,18.56778860968005 73.81263256072999,18.56839883103761 73.81507873535158,18.56937518066862 73.81979942321779,18.56937518066862 73.82246017456056,18.5689683690016 73.82413387298585,18.56791065412622 73.82692337036134,18.56742247581762 73.82795333862306,18.56795133558887 73.8285541534424,18.56888700655174 73.82984161376955,18.57088037539931 73.83074283599855,18.5740534450911 73.83301734924318,18.57462296417025 73.83353233337404,18.57478568355774 73.83374691009523,18.57478568355774 73.83520603179933,18.57441956471749 73.83627891540529,18.5751518016118 73.83597850799562,18.57669762472794 73.83542060852052,18.57686034213534 73.83542060852052,18.57877226003835 73.83481979370119,18.57897565429798 73.83490562438966,18.57905701193389 73.83503437042238,18.57926040585373 73.83507728576662,18.57946379953089 73.83533477783205,18.57991126476635 73.83559226989748,18.58353162210409 73.83700847625734,18.58397907665962 73.8369655609131,18.5841417871158 73.83683681488039,18.58426381985597 73.83662223815919,18.58450788507413 73.83645057678224,18.58471127248891 73.83649349212648,18.58495533706621 73.83670806884767,18.58597226904206 73.83709430694581,18.58674513328456 73.83825302124025,18.58690784109942 73.83825302124025,18.58906370497702 73.8389825820923,18.59052804978777 73.8395404815674,18.59036534543042 73.84014129638673,18.59154494850029 73.84061336517335,18.59252116555283 73.84095668792726,18.59170765173093 73.84318828582765,18.59345670164452 73.84499073028566,18.5938933851391 73.84556664541741,18.59268386785095 73.84185791015626,18.59382277958591 73.83833885192873,18.60030744889924 73.83558000367456,18.59886644000087 73.83481979370119,18.60020867929654 73.8340473175049,18.60366591359715 73.83250236511232,18.60346254881724 73.83263111114503,18.60305581852853 73.83297443389894,18.60366591359715 73.8325881958008,18.60390995101232 73.83220195770265,18.60366591359715 73.83233070373537,18.6037472594411 73.83211612701417,18.60386927813409 73.83215904235841,18.60560659519579 73.83070960510427,18.60565887558194 73.8309144973755,18.60549618568243 73.82971286773683,18.60508946025324 73.82868289947511,18.60519407441151 73.8290928932427,18.60488609717417 73.82833957672121,18.60525215054155 73.8270950317383,18.60667568393053 73.82615089416505,18.60748912623535 73.82537841796876,18.60777383012345 73.82494926452638,18.61257305254242 73.82404804229738,18.60691971703023 73.82224559783937,18.60630963362487 73.8219451904297,18.60537416815573 73.82121562957765,18.60472340653597 73.8204860687256,18.60517080541683 73.81954193115236,18.60529282308932 73.81859779357912,18.60529282308932 73.81396293640138,18.60464206115854 73.81186008453371,18.60480475187451 73.81113052368165,18.60464206115854 73.8106155395508,18.60423533368829 73.8100576400757,18.60305581852853 73.80877017974855,18.60297447235416 73.80683898925783,18.60305581852853 73.80422115325929,18.60268976043773 73.80276203155519,18.60484542452919 73.80263328552248,18.60862793892986 73.80297660827638,18.60874995412367 73.80383491516115,18.61066151407092 73.80374908447267,18.6118409765164 73.80426406860353,18.61241036925331 73.80525112152101,18.61281707718437 73.80580902099611,18.61395585421871 73.80683898925783,18.61562333540797 73.80799770355226,18.61668075403393 73.80885601043703,18.61712812147367 73.80808353424074,18.61765682693083 73.80756855010988,18.61891757946533 73.8060235977173,18.62042233638452 73.80443572998048,18.62497719508798 73.80173206329347,18.62733591324319 73.80263328552248,18.62847459305244 73.803448677063,18.63010126526146 73.80203247070314,18.62997926538582 73.79615306854249,18.63091459552767 73.79529476165773,18.63062993037725 73.79495143890382,18.6305079308811 73.79495143890382,18.63038593129738 73.79499435424806,18.63018259846324 73.79486560821535,18.63006059864598 73.79473686218263,18.63001993202076 73.79456520080568,18.62949126500752 73.79452228546144,18.62969459866876 73.79439353942873,18.62965393195597 73.79430770874025,18.62961326523345 73.79430770874025,18.62953193175922 73.79422187805177,18.62932859790337 73.79417896270753,18.62892192946189 73.79396438598634,18.62867792792995 73.79396438598634,18.62851526004741 73.79379272460939,18.62827125793168 73.79370689392091,18.62806792256766 73.7935781478882,18.62770191829949 73.79353523254396,18.62696990739883 73.79327774047853,18.62635989590698 73.79271984100343,18.62782391980976 73.78997325897218,18.62753924948288 73.78907203674318,18.62680723788171 73.78885746002199,18.6233098056137 73.7889862060547,18.62095103160052 73.78890037536623,18.61977163232369 73.78829956054689,18.61851088612052 73.78735542297365,18.61729080025092 73.78576755523683,18.61627405534037 73.78520965576173,18.61489127250845 73.78555297851564,18.61448456953623 73.7855100631714,18.61220701492318 73.78465175628664,18.61196298940617 73.78435134887697,18.61013278687228 73.78280639648439,18.60687904487124 73.78018856048585,18.60691971703023 73.7800168991089,18.60358456771434 73.77739906311037,18.60305581852853 73.77778530120851,18.60232370155975 73.77860069274904,18.59650732711204 73.78246307373048,18.59325332467041 73.78443717956544,18.59227711181423 73.78508090972902,18.59187035480613 73.78542423248292,18.5879654381086 73.78911495208742,18.58678581025284 73.79083156585695,18.58690784109942 73.79018783569337,18.58735528678913 73.78859996795656,18.58804679145276 73.78538131713869,18.59077210603243 73.78619670867921,18.59288724550504 73.7846088409424,18.59366007837577 73.78237724304201,18.59182967905191 73.78164768218996,18.59008061243109 73.77941608428956,18.58869761680755 73.77684116363527,18.58886032275777 73.77641201019289,18.58780273130373 73.77666950225831,18.58646039423466 73.77812862396242,18.58495533706621 73.77885818481447,18.58247399757517 73.77980232238771,18.5787315811573 73.78074645996095,18.57877226003835 73.78074645996095,18.5787315811573 73.78083229064943,18.57804003869419 73.78139019012453,18.5769417007808 73.78267765045167,18.57433820486846 73.78628253936769,18.5728737209472 73.78847122192384,18.57144990507632 73.78997325897218,18.57022948201088 73.79035949707033,18.56929381841284 73.79031658172609,18.56848019372033 73.78997325897218,18.56815474275657 73.78975868225099,18.56746315739671 73.78885746002199,18.56721906777668 73.78868579864503,18.56693429611186 73.78855705261232,18.56648679682087 73.78851413726808,18.56575452272156 73.78851413726808,18.56494088114674 73.78859996795656,18.56449337662647 73.7889862060547,18.56437132973539 73.78877162933351,18.56404587093234 73.7901020050049,18.56351699905318 73.79194736480714,18.56343563400318 73.79241943359376)))'
wkt.loads(x)

When the same data is read from the csv file, this results in an error:

df['geo_fence'] = df['geo_fence'].apply(wkt.loads)

WKTReadingError: Could not create geometry because of errors while reading input.

The error appears when the row data is in form of MULTIPOLYGON(P1,P2,P3) etc but not for MULTIPOLYGON(P1)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP