I am reading GeoJSON into shapely objects and need help,
I have a massive MultiPolygon with several nested Polygons in it. I believe this is why it is not considered a valid shape?
as_shape.is_valid
-> False
explain_validity(as_shape)
-> 'Nested shells[-118.752368927 36.63641068]'
Are the inner polygons actually the problem?
Right now we attempt to fix all invalid poly/multipolygons we get using the first buffer ring, and throw an error if that does not make the shape valid
first_buffer = as_shape.buffer(0)
if not first_buffer.is_valid:
raise Exception('Invalid geo json contains invalid geometries')
return mapping(first_buffer)
In Many cases this works, but in the case of a multipolygon with several complex holes, the MultiPolygon gets oversimplified (holes go away and we get the outer shell).
What's the right way to make all inner polygons holes while keeping the outer MultiPolygon in tact?
My attempts so far seem overly complicated --
all_ps = list(as_shape)
get = {
'shells': [ g for g in all_ps if g and not len([ g.buffer(0).within(i) for i in all_ps if i!=g ]) > 2],
'holes': [ g for g in all_ps if g and len([ g.buffer(0).within(i) for i in all_ps if i!=g ]) > 2],
}