Skip to content
Permalink
Browse files

fix 6dfedc3

  • Loading branch information
jef-n committed Feb 16, 2018
1 parent 6dfedc3 commit b6111d296e7ad8c66a1914dbf1b741cd4edef997
Showing with 75 additions and 75 deletions.
  1. +75 −75 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
@@ -143,19 +143,19 @@ def rectangles(self, sink, source, width, height, rotation, feedback):
angle = feat[rotation]
if not w or not h or not angle:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'Skipping…').format(feat.id())))
'width, height or angle. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
phi=angle * math.pi / 180
xOffset = w / 2.0
yOffset = h / 2.0
phi = angle * math.pi / 180

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[(-xOffset, -yOffset), (-xOffset, yOffset), (xOffset, yOffset), (xOffset, -yOffset)]
polygon=[[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = [(-xOffset, -yOffset), (-xOffset, yOffset), (xOffset, yOffset), (xOffset, -yOffset)]
polygon = [[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
-i[0] * math.sin(phi) + i[1] * math.cos(phi) + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
@@ -171,22 +171,22 @@ def rectangles(self, sink, source, width, height, rotation, feedback):
if not feat.hasGeometry():
continue

w=feat[width]
h=feat[height]
w = feat[width]
h = feat[height]
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width or height. '
'Skipping…').format(feat.id()))
'width or height. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
xOffset = w / 2.0
yOffset = h / 2.0

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[(-xOffset, -yOffset), (-xOffset, yOffset), (xOffset, yOffset), (xOffset, -yOffset)]
polygon=[[QgsPointXY(i[0] + x, i[1] + y) for i in points]]
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = [(-xOffset, -yOffset), (-xOffset, yOffset), (xOffset, yOffset), (xOffset, -yOffset)]
polygon = [[QgsPointXY(i[0] + x, i[1] + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
ft.setAttributes(feat.attributes())
@@ -195,10 +195,10 @@ def rectangles(self, sink, source, width, height, rotation, feedback):
feedback.setProgress(int(current * total))

def diamonds(self, sink, source, width, height, rotation, feedback):
features=source.getFeatures()
ft=QgsFeature()
features = source.getFeatures()
ft = QgsFeature()

total=100.0 / source.featureCount() if source.featureCount() else 0
total = 100.0 / source.featureCount() if source.featureCount() else 0
if rotation >= 0:
for current, feat in enumerate(features):
if feedback.isCanceled():
@@ -207,24 +207,24 @@ def diamonds(self, sink, source, width, height, rotation, feedback):
if not feat.hasGeometry():
continue

w=feat[width]
h=feat[height]
angle=feat[rotation]
w = feat[width]
h = feat[height]
angle = feat[rotation]
if not w or not h or not angle:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'Skipping…').format(feat.id()))
'width, height or angle. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
phi=angle * math.pi / 180
xOffset = w / 2.0
yOffset = h / 2.0
phi = angle * math.pi / 180

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[(0.0, -yOffset), (-xOffset, 0.0), (0.0, yOffset), (xOffset, 0.0)]
polygon=[[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = [(0.0, -yOffset), (-xOffset, 0.0), (0.0, yOffset), (xOffset, 0.0)]
polygon = [[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
-i[0] * math.sin(phi) + i[1] * math.cos(phi) + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
@@ -239,33 +239,33 @@ def diamonds(self, sink, source, width, height, rotation, feedback):
if not feat.hasGeometry():
continue

w=feat[width]
h=feat[height]
w = feat[width]
h = feat[height]
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width or height. '
'Skipping…').format(feat.id()))
'width or height. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
xOffset = w / 2.0
yOffset = h / 2.0

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[(0.0, -yOffset), (-xOffset, 0.0), (0.0, yOffset), (xOffset, 0.0)]
polygon=[[QgsPointXY(i[0] + x, i[1] + y) for i in points]]
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = [(0.0, -yOffset), (-xOffset, 0.0), (0.0, yOffset), (xOffset, 0.0)]
polygon = [[QgsPointXY(i[0] + x, i[1] + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
ft.setAttributes(feat.attributes())
sink.addFeature(ft, QgsFeatureSink.FastInsert)
feedback.setProgress(int(current * total))

def ovals(self, sink, source, width, height, rotation, segments, feedback):
features=source.getFeatures()
ft=QgsFeature()
features = source.getFeatures()
ft = QgsFeature()

total=100.0 / source.featureCount() if source.featureCount() else 0
total = 100.0 / source.featureCount() if source.featureCount() else 0
if rotation >= 0:
for current, feat in enumerate(features):
if feedback.isCanceled():
@@ -274,26 +274,26 @@ def ovals(self, sink, source, width, height, rotation, segments, feedback):
if not feat.hasGeometry():
continue

w=feat[width]
h=feat[height]
angle=feat[rotation]
w = feat[width]
h = feat[height]
angle = feat[rotation]
if not w or not h or not angle:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'Skipping…').format(feat.id()))
'width, height or angle. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
phi=angle * math.pi / 180
xOffset = w / 2.0
yOffset = h / 2.0
phi = angle * math.pi / 180

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[]
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = []
for t in [(2 * math.pi) / segments * i for i in range(segments)]:
points.append((xOffset * math.cos(t), yOffset * math.sin(t)))
polygon=[[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
polygon = [[QgsPointXY(i[0] * math.cos(phi) + i[1] * math.sin(phi) + x,
-i[0] * math.sin(phi) + i[1] * math.cos(phi) + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
@@ -308,24 +308,24 @@ def ovals(self, sink, source, width, height, rotation, segments, feedback):
if not feat.hasGeometry():
continue

w=feat[width]
h=feat[height]
w = feat[width]
h = feat[height]
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width or height. '
'Skipping…').format(feat.id()))
'width or height. '
'Skipping…').format(feat.id()))
continue

xOffset=w / 2.0
yOffset=h / 2.0
xOffset = w / 2.0
yOffset = h / 2.0

point=feat.geometry().asPoint()
x=point.x()
y=point.y()
points=[]
point = feat.geometry().asPoint()
x = point.x()
y = point.y()
points = []
for t in [(2 * math.pi) / segments * i for i in range(segments)]:
points.append((xOffset * math.cos(t), yOffset * math.sin(t)))
polygon=[[QgsPointXY(i[0] + x, i[1] + y) for i in points]]
polygon = [[QgsPointXY(i[0] + x, i[1] + y) for i in points]]

ft.setGeometry(QgsGeometry.fromPolygonXY(polygon))
ft.setAttributes(feat.attributes())

0 comments on commit b6111d2

Please sign in to comment.
You can’t perform that action at this time.