0

I am developing a plug-in in QGIS. By using two points I am creating a circular string to reshape sharp polygon edges to round. The plugin is reshaping 3 edges perfectly but failing reshaping near start/end point of the polygon. Code to execute on right-click given below.

final_vert=[]
if self.layer.selectedFeatureCount() == 1:
   for feat in self.layer.selectedFeatures():
       geom = feat.geometry()
                   
if geom.wkbType() == QgsWkbTypes.MultiPolygon: 
    ver_list=geom.asPolygon()
    close1 = min([geom.closestSegmentWithContext(self.coor[0])])
    idx1 = close1[2]
                    
    close2 = min([geom.closestSegmentWithContext(self.coor[-1])])
    idx2 = close2[2]
    ver_lis = ver_list[0][0]
                 
    if idx1 > idx2:             
       self.poi.reverse()
       geom_part1 = ver_lis[idx1:]
       geom_part2 = ver_lis[:idx2]
       final_vert.append(geom_part2)
       final_vert.append(self.poi)
       final_vert.append(geom_part1)
                        
       pass
  else:
       geom_part1 = ver_lis[:idx1]
       final_vert.append(geom_part1)
       final_vert.append(self.poi)
       geom_part2 = ver_lis[idx2:]
       final_vert.append(geom_part2)
                    
   ab = itertools.chain.from_iterable(final_vert)
   geom_vert = list(ab)                
   blade = QgsGeometry.fromPolygonXY([geom_vert])
   self.layer.changeGeometry(feat.id(), blade)

The code is working well for 3 sides as shown in in the 1st image below. But while reshaping near to start/end point of the polygon it results in removing rest of the portion while keeping the source point at place.

How do I avoid this problem?

Reshaped

Failed

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.