@@ -81,8 +81,10 @@ def processAlgorithm(self, progress):
81
81
height = bbox .height ()
82
82
centerX = bbox .center ().x ()
83
83
centerY = bbox .center ().y ()
84
- originX = centerX - width / 2.0
85
- originY = centerY - height / 2.0
84
+ #~ originX = centerX - width / 2.0
85
+ #~ originY = centerY - height / 2.0
86
+ originX = bbox .xMinimum ()
87
+ originY = bbox .yMaximum ()
86
88
87
89
if hSpacing <= 0 or vSpacing <= 0 :
88
90
raise GeoAlgorithmExecutionException (
@@ -130,15 +132,15 @@ def _rectangleGridLine(self, writer, width, height, originX, originY,
130
132
hSpacing , vSpacing ):
131
133
ft = QgsFeature ()
132
134
133
- columns = int (math .floor (float (width ) / hSpacing ))
134
- rows = int (math .floor (float (height ) / vSpacing ))
135
+ columns = int (math .ceil (float (width ) / hSpacing ))
136
+ rows = int (math .ceil (float (height ) / vSpacing ))
135
137
136
138
# Longitude lines
137
139
for col in xrange (0 , columns + 1 ):
138
140
polyline = []
139
141
x = originX + (col * hSpacing )
140
142
for row in xrange (0 , rows + 1 ):
141
- y = originY + (row * vSpacing )
143
+ y = originY - (row * vSpacing )
142
144
polyline .append (QgsPoint (x , y ))
143
145
144
146
ft .setGeometry (QgsGeometry .fromPolyline (polyline ))
@@ -148,7 +150,7 @@ def _rectangleGridLine(self, writer, width, height, originX, originY,
148
150
# Latitude lines
149
151
for row in xrange (0 , rows + 1 ):
150
152
polyline = []
151
- y = originY + (row * vSpacing )
153
+ y = originY - (row * vSpacing )
152
154
for col in xrange (0 , columns + 1 ):
153
155
x = originX + (col * hSpacing )
154
156
polyline .append (QgsPoint (x , y ))
@@ -161,8 +163,8 @@ def _rectangleGridPoly(self, writer, width, height, originX, originY,
161
163
hSpacing , vSpacing ):
162
164
ft = QgsFeature ()
163
165
164
- columns = int (math .floor (float (width ) / hSpacing ))
165
- rows = int (math .floor (float (height ) / vSpacing ))
166
+ columns = int (math .ceil (float (width ) / hSpacing ))
167
+ rows = int (math .ceil (float (height ) / vSpacing ))
166
168
167
169
for col in xrange (0 , columns ):
168
170
# (column + 1) and (row + 1) calculation is used to maintain
@@ -171,8 +173,8 @@ def _rectangleGridPoly(self, writer, width, height, originX, originY,
171
173
x1 = originX + (col * hSpacing )
172
174
x2 = originX + ((col + 1 ) * hSpacing )
173
175
for row in xrange (0 , rows ):
174
- y1 = originY + (row * vSpacing )
175
- y2 = originY + ((row + 1 ) * vSpacing )
176
+ y1 = originY - (row * vSpacing )
177
+ y2 = originY - ((row + 1 ) * vSpacing )
176
178
177
179
polyline = []
178
180
polyline .append (QgsPoint (x1 , y1 ))
@@ -192,8 +194,8 @@ def _diamondGrid(self, writer, width, height, originX, originY,
192
194
halfHSpacing = hSpacing / 2
193
195
halfVSpacing = vSpacing / 2
194
196
195
- columns = int (math .floor (float (width ) / halfHSpacing ))
196
- rows = int (math .floor (float (height ) / vSpacing ))
197
+ columns = int (math .ceil (float (width ) / halfHSpacing ))
198
+ rows = int (math .ceil (float (height ) / vSpacing ))
197
199
198
200
for col in xrange (0 , columns ):
199
201
x1 = originX + ((col + 0 ) * halfHSpacing )
@@ -202,13 +204,13 @@ def _diamondGrid(self, writer, width, height, originX, originY,
202
204
203
205
for row in xrange (0 , rows ):
204
206
if (col % 2 ) == 0 :
205
- y1 = originY + (((row * 2 ) + 0 ) * halfVSpacing )
206
- y2 = originY + (((row * 2 ) + 1 ) * halfVSpacing )
207
- y3 = originY + (((row * 2 ) + 2 ) * halfVSpacing )
207
+ y1 = originY - (((row * 2 ) + 0 ) * halfVSpacing )
208
+ y2 = originY - (((row * 2 ) + 1 ) * halfVSpacing )
209
+ y3 = originY - (((row * 2 ) + 2 ) * halfVSpacing )
208
210
else :
209
- y1 = originY + (((row * 2 ) + 1 ) * halfVSpacing )
210
- y2 = originY + (((row * 2 ) + 2 ) * halfVSpacing )
211
- y3 = originY + (((row * 2 ) + 3 ) * halfVSpacing )
211
+ y1 = originY - (((row * 2 ) + 1 ) * halfVSpacing )
212
+ y2 = originY - (((row * 2 ) + 2 ) * halfVSpacing )
213
+ y3 = originY - (((row * 2 ) + 3 ) * halfVSpacing )
212
214
213
215
polyline = []
214
216
polyline .append (QgsPoint (x1 , y2 ))
@@ -232,8 +234,8 @@ def _hexagonGrid(self, writer, width, height, originX, originY,
232
234
233
235
halfVSpacing = vSpacing / 2
234
236
235
- columns = int (math .floor (float (width ) / hSpacing ))
236
- rows = int (math .floor (float (height ) / vSpacing ))
237
+ columns = int (math .ceil (float (width ) / hSpacing ))
238
+ rows = int (math .ceil (float (height ) / vSpacing ))
237
239
238
240
for col in xrange (0 , columns ):
239
241
# (column + 1) and (row + 1) calculation is used to maintain
@@ -246,13 +248,13 @@ def _hexagonGrid(self, writer, width, height, originX, originY,
246
248
247
249
for row in xrange (0 , rows ):
248
250
if (col % 2 ) == 0 :
249
- y1 = originY + (((row * 2 ) + 0 ) * halfVSpacing ) # hi
250
- y2 = originY + (((row * 2 ) + 1 ) * halfVSpacing ) # mid
251
- y3 = originY + (((row * 2 ) + 2 ) * halfVSpacing ) # lo
251
+ y1 = originY - (((row * 2 ) + 0 ) * halfVSpacing ) # hi
252
+ y2 = originY - (((row * 2 ) + 1 ) * halfVSpacing ) # mid
253
+ y3 = originY - (((row * 2 ) + 2 ) * halfVSpacing ) # lo
252
254
else :
253
- y1 = originY + (((row * 2 ) + 1 ) * halfVSpacing ) # hi
254
- y2 = originY + (((row * 2 ) + 2 ) * halfVSpacing ) # mid
255
- y3 = originY + (((row * 2 ) + 3 ) * halfVSpacing ) # lo
255
+ y1 = originY - (((row * 2 ) + 1 ) * halfVSpacing ) # hi
256
+ y2 = originY - (((row * 2 ) + 2 ) * halfVSpacing ) # mid
257
+ y3 = originY - (((row * 2 ) + 3 ) * halfVSpacing ) # lo
256
258
257
259
polyline = []
258
260
polyline .append (QgsPoint (x1 , y2 ))
0 commit comments