Skip to content
Permalink
Browse files

[processing] fixes for Create Grid algorithm (fix #14303)

  • Loading branch information
alexbruy committed Feb 17, 2016
1 parent ead88a3 commit 08577ac15d09b6998e4e4ad177cda2c3e936711e
Showing with 28 additions and 26 deletions.
  1. +28 −26 python/plugins/processing/algs/qgis/Grid.py
@@ -81,8 +81,10 @@ def processAlgorithm(self, progress):
height = bbox.height()
centerX = bbox.center().x()
centerY = bbox.center().y()
originX = centerX - width / 2.0
originY = centerY - height / 2.0
#~ originX = centerX - width / 2.0
#~ originY = centerY - height / 2.0
originX = bbox.xMinimum()
originY = bbox.yMaximum()

if hSpacing <= 0 or vSpacing <= 0:
raise GeoAlgorithmExecutionException(
@@ -130,15 +132,15 @@ def _rectangleGridLine(self, writer, width, height, originX, originY,
hSpacing, vSpacing):
ft = QgsFeature()

columns = int(math.floor(float(width) / hSpacing))
rows = int(math.floor(float(height) / vSpacing))
columns = int(math.ceil(float(width) / hSpacing))
rows = int(math.ceil(float(height) / vSpacing))

# Longitude lines
for col in xrange(0, columns + 1):
polyline = []
x = originX + (col * hSpacing)
for row in xrange(0, rows + 1):
y = originY + (row * vSpacing)
y = originY - (row * vSpacing)
polyline.append(QgsPoint(x, y))

ft.setGeometry(QgsGeometry.fromPolyline(polyline))
@@ -148,7 +150,7 @@ def _rectangleGridLine(self, writer, width, height, originX, originY,
# Latitude lines
for row in xrange(0, rows + 1):
polyline = []
y = originY + (row * vSpacing)
y = originY - (row * vSpacing)
for col in xrange(0, columns + 1):
x = originX + (col * hSpacing)
polyline.append(QgsPoint(x, y))
@@ -161,8 +163,8 @@ def _rectangleGridPoly(self, writer, width, height, originX, originY,
hSpacing, vSpacing):
ft = QgsFeature()

columns = int(math.floor(float(width) / hSpacing))
rows = int(math.floor(float(height) / vSpacing))
columns = int(math.ceil(float(width) / hSpacing))
rows = int(math.ceil(float(height) / vSpacing))

for col in xrange(0, columns):
# (column + 1) and (row + 1) calculation is used to maintain
@@ -171,8 +173,8 @@ def _rectangleGridPoly(self, writer, width, height, originX, originY,
x1 = originX + (col * hSpacing)
x2 = originX + ((col + 1) * hSpacing)
for row in xrange(0, rows):
y1 = originY + (row * vSpacing)
y2 = originY + ((row + 1) * vSpacing)
y1 = originY - (row * vSpacing)
y2 = originY - ((row + 1) * vSpacing)

polyline = []
polyline.append(QgsPoint(x1, y1))
@@ -192,8 +194,8 @@ def _diamondGrid(self, writer, width, height, originX, originY,
halfHSpacing = hSpacing / 2
halfVSpacing = vSpacing / 2

columns = int(math.floor(float(width) / halfHSpacing))
rows = int(math.floor(float(height) / vSpacing))
columns = int(math.ceil(float(width) / halfHSpacing))
rows = int(math.ceil(float(height) / vSpacing))

for col in xrange(0, columns):
x1 = originX + ((col + 0) * halfHSpacing)
@@ -202,13 +204,13 @@ def _diamondGrid(self, writer, width, height, originX, originY,

for row in xrange(0, rows):
if (col % 2) == 0:
y1 = originY + (((row * 2) + 0) * halfVSpacing)
y2 = originY + (((row * 2) + 1) * halfVSpacing)
y3 = originY + (((row * 2) + 2) * halfVSpacing)
y1 = originY - (((row * 2) + 0) * halfVSpacing)
y2 = originY - (((row * 2) + 1) * halfVSpacing)
y3 = originY - (((row * 2) + 2) * halfVSpacing)
else:
y1 = originY + (((row * 2) + 1) * halfVSpacing)
y2 = originY + (((row * 2) + 2) * halfVSpacing)
y3 = originY + (((row * 2) + 3) * halfVSpacing)
y1 = originY - (((row * 2) + 1) * halfVSpacing)
y2 = originY - (((row * 2) + 2) * halfVSpacing)
y3 = originY - (((row * 2) + 3) * halfVSpacing)

polyline = []
polyline.append(QgsPoint(x1, y2))
@@ -232,8 +234,8 @@ def _hexagonGrid(self, writer, width, height, originX, originY,

halfVSpacing = vSpacing / 2

columns = int(math.floor(float(width) / hSpacing))
rows = int(math.floor(float(height) / vSpacing))
columns = int(math.ceil(float(width) / hSpacing))
rows = int(math.ceil(float(height) / vSpacing))

for col in xrange(0, columns):
# (column + 1) and (row + 1) calculation is used to maintain
@@ -246,13 +248,13 @@ def _hexagonGrid(self, writer, width, height, originX, originY,

for row in xrange(0, rows):
if (col % 2) == 0:
y1 = originY + (((row * 2) + 0) * halfVSpacing) # hi
y2 = originY + (((row * 2) + 1) * halfVSpacing) # mid
y3 = originY + (((row * 2) + 2) * halfVSpacing) # lo
y1 = originY - (((row * 2) + 0) * halfVSpacing) # hi
y2 = originY - (((row * 2) + 1) * halfVSpacing) # mid
y3 = originY - (((row * 2) + 2) * halfVSpacing) # lo
else:
y1 = originY + (((row * 2) + 1) * halfVSpacing) # hi
y2 = originY + (((row * 2) + 2) * halfVSpacing) # mid
y3 = originY + (((row * 2) + 3) * halfVSpacing) # lo
y1 = originY - (((row * 2) + 1) * halfVSpacing) # hi
y2 = originY - (((row * 2) + 2) * halfVSpacing) # mid
y3 = originY - (((row * 2) + 3) * halfVSpacing) # lo

polyline = []
polyline.append(QgsPoint(x1, y2))

0 comments on commit 08577ac

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