cleder/pygeoif

Wrong Multipolygon

mindflayer opened this issue · 5 comments

Hi there, I am reading a shapefile with pyshp:

sf = shapefile.Reader(os.path.join(cwd, shapefile_name))

for i in range(3):
    print(pygeoif.as_shape(sf.shape(i)).wkt)

The print result is the following one, with three single Polygon:

POLYGON((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054))
POLYGON((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905))
POLYGON((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964))

Now, I am using pygeoif to create a Multipolygon with these given Polygon:

m = pygeoif.MultiPolygon(sf.shapes())
print(m.wkt)

and the result is broken (missing comma separation).

MULTIPOLYGON(((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054))((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905))((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964)))

If I add comma as separator, I get this:

MULTIPOLYGON(((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054)),((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905)),((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964)))

Broken Multipolygon out of pygeoif:
broken

Good Multipolygon manually fixed:
fine

Thanks I look into it ASAP (as possible means I cannot do it before easter)

Hi @cleder, any news?

Published 0.7 on pypi