Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. vpoly = QgsVectorLayer("Polygon", "pointbuffer", "memory")
  2. feature = QgsFeature()
  3. feature.setGeometry( QgsGeometry.fromPoint(QgsPoint(3517601,5406205)).buffer(10000,5))
  4. provider = vpoly.dataProvider()
  5. vpoly.startEditing()
  6. provider.addFeatures( [feature] )
  7. vpoly.commitChanges()
  8.  
  9. vpoly = QgsVectorLayer("Polygon", "pointbuffer", "memory")
  10. feature = QgsFeature()
  11. feature.setGeometry( QgsGeometry.fromPoint(QgsPoint(3517601,5406205)).buffer(10000,5))
  12. provider = vpoly.dataProvider()
  13. vpoly.startEditing()
  14. provider.addFeatures( [feature] )
  15. vpoly.commitChanges()
  16.  
  17. def circle_geometry(self, pt, radius=0, segments=0, mapunits=False):
  18. """
  19. Draw a circle at a canvas point
  20.  
  21. :type pt: qgis.core.QgsPoint
  22. :param pt: canvas point, in layer crs
  23. :type radius: float
  24. :param radius: cicle radius, considered to be in layer units
  25. :type segments: int
  26. :param segments: number of segments usually divisible by 8, e.g. 32
  27. :type mapunits: bool
  28. :param mapunits: whether the radius should be considered in map units
  29. :return: QgsGeometry of type QGis.Polygon
  30. """
  31. if not radius:
  32. radius = self.circleradius # default of 5 for this project
  33. if not mapunits:
  34. ctx = self.canvas.mapRenderer().rendererContext()
  35. # as mm (converted to map pixels, then to map units)
  36. radius *= ctx.scaleFactor() * ctx.mapToPixel().mapUnitsPerPixel()
  37. if not segments:
  38. segments = self.circlesegments # usually divisible by 8, e.g. 32
  39. pts = []
  40. for i in range(segments):
  41. theta = i * (2.0 * math.pi / segments)
  42. p = QgsPoint(pt.x() + radius * math.cos(theta),
  43. pt.y() + radius * math.sin(theta))
  44. pts.append(p)
  45. return QgsGeometry.fromPolygon([pts])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement