shapely.geos.ReadingError: Could not create geometry because of errors while reading input

烂漫一生 提交于 2021-02-07 20:23:12

问题


I'm getting the error in the title when I try to use shapely.wkt.loads on the following input:

POLYGON((-93.577695846689437 40.813390731817726,-93.577674865779628 40.813444137603014,-93.577722549304582 40.8136196133706,-93.577945709640048 40.814004897950532,-93.5781135556297 40.814165115070466,-93.578243255589527 40.814229965262996,-93.578363418973865 40.814268111930119,-93.578405380213241 40.814252853305611,-93.578418731892242 40.814207077283442,-93.578376770009427 40.81411170971851,-93.578311920291867 40.814050674367543,-93.578300476322624 40.814008712491074,-93.578235626128318 40.813978195044577,-93.5779953002333 40.813646316512269,-93.577934265283389 40.813581466662242,-93.577924728143131 40.813535690301279,-93.577777862415886 40.813383102422016,-93.577695846689437 40.81339073181772))

Saving you the trouble of scrolling through all that, it's in WKT format. It's one of about 100 Polygons I'm reading in, and it's the only one throwing this error. To be clear, when I call:

p = loads('POLYGON((-93.577695846689437 40.813390731817726,-93.577674865779628 40.813444137603014,-93.577722549304582 40.8136196133706,-93.577945709640048 40.814004897950532,-93.5781135556297 40.814165115070466,-93.578243255589527 40.814229965262996,-93.578363418973865 40.814268111930119,-93.578405380213241 40.814252853305611,-93.578418731892242 40.814207077283442,-93.578376770009427 40.81411170971851,-93.578311920291867 40.814050674367543,-93.578300476322624 40.814008712491074,-93.578235626128318 40.813978195044577,-93.5779953002333 40.813646316512269,-93.577934265283389 40.813581466662242,-93.577924728143131 40.813535690301279,-93.577777862415886 40.813383102422016,-93.577695846689437 40.81339073181772))')

I get the error: shapely.geos.ReadingError: Could not create geometry because of errors while reading input.

I even went through the trouble of parsing it up into regular shapely.geometry.Polygon format. Then, it works fine. But I'd rather not clutter code with annoying string parsing (and an ugly try/except). And, of course, the shapely/wky.py file tells me absolutely nothing... If anyone knows what's going on/how to fix it, I'd appreciate it. Thanks!


回答1:


The geometry contains non-closed rings. Looking at the first and last coordinate:

  • -93.577695846689437 40.813390731817726
  • -93.577695846689437 40.81339073181772

Adding 6 at the end of the last coordinate string will make the two equal, and the outer shell a closed linear ring required to make a polygon.



来源:https://stackoverflow.com/questions/19862863/shapely-geos-readingerror-could-not-create-geometry-because-of-errors-while-rea

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!