Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vpoly = QgsVectorLayer("Polygon", "pointbuffer", "memory")
- feature = QgsFeature()
- feature.setGeometry( QgsGeometry.fromPoint(QgsPoint(3517601,5406205)).buffer(10000,5))
- provider = vpoly.dataProvider()
- vpoly.startEditing()
- provider.addFeatures( [feature] )
- vpoly.commitChanges()
- vpoly = QgsVectorLayer("Polygon", "pointbuffer", "memory")
- feature = QgsFeature()
- feature.setGeometry( QgsGeometry.fromPoint(QgsPoint(3517601,5406205)).buffer(10000,5))
- provider = vpoly.dataProvider()
- vpoly.startEditing()
- provider.addFeatures( [feature] )
- vpoly.commitChanges()
- def circle_geometry(self, pt, radius=0, segments=0, mapunits=False):
- """
- Draw a circle at a canvas point
- :type pt: qgis.core.QgsPoint
- :param pt: canvas point, in layer crs
- :type radius: float
- :param radius: cicle radius, considered to be in layer units
- :type segments: int
- :param segments: number of segments usually divisible by 8, e.g. 32
- :type mapunits: bool
- :param mapunits: whether the radius should be considered in map units
- :return: QgsGeometry of type QGis.Polygon
- """
- if not radius:
- radius = self.circleradius # default of 5 for this project
- if not mapunits:
- ctx = self.canvas.mapRenderer().rendererContext()
- # as mm (converted to map pixels, then to map units)
- radius *= ctx.scaleFactor() * ctx.mapToPixel().mapUnitsPerPixel()
- if not segments:
- segments = self.circlesegments # usually divisible by 8, e.g. 32
- pts = []
- for i in range(segments):
- theta = i * (2.0 * math.pi / segments)
- p = QgsPoint(pt.x() + radius * math.cos(theta),
- pt.y() + radius * math.sin(theta))
- pts.append(p)
- return QgsGeometry.fromPolygon([pts])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement