Closed caver456 closed 2 years ago
commented out the removeSpurs call for the tracks, and the crop error persists - for all tracks:
That's more than a coincidence... looking in the log, there's now just one occurrence of 'spur removed' and it appears to be talking about a spur on the boundary shape at the opposite corner of the assignment:
That might or might not be relevant. But - take a look at the corner below the bad crops - it's a crossover, so that is probably where the problem resides. Looks like the 'beyond' argument is resulting in an inward growth where the crossover happens, rather than an outward growth. So - need to look at the coordinates at each step around the buffer command, around line 1961:
if boundaryType=='Polygon':
cgc=cg['coordinates'][0]
cgc=self.removeSpurs(cgc)
boundaryGeom=Polygon(cgc).buffer(beyond) # Shapely object
Sure enough, adding the grown boundary to the sartopo map shows it:
The shapely docs say that doing a buffer of zero will split bowties into two polygons at the crossover point. So, split the bowties, do a buffer on each resulting polygon, then OR the results together into one polygon.
Holy cow that worked:
def buffer2(self,boundaryGeom,beyond):
a=boundaryGeom.buffer(0) # split bowties into separate polygons
merged=unary_union(a)
return merged.buffer(beyond)
...
in crop:
# boundaryGeom=Polygon(cgc).buffer(beyond) # Shapely object
boundaryGeom=self.buffer2(Polygon(cgc),beyond)
if this fails in the future, note that the shapely docs say that results may vary when trying to fix bowties using zero size buffer and also when using unary_union, and that some users reported better success when using small positive values. So, if needed, could try progressively larger buffer values until is_valid is true for each resulting polygon, or something to that effect.
First guess: maybe this is due to a flaw in removeSpurs.. The log shows that several spurs were removed, including at coordinates very close to the split. Try the same crop operation without doing removeSpurs first.