Ich bin auch in QGIS 3 auf dieses Problem gestoßen und habe diese Lösung im Stapelüberlauf gefunden
Grundsätzlich besteht die Idee darin, den Winkel auf das Polygon anzuwenden, auf dem die Ausdehnung definiert ist, bevor das Raster erstellt wird. Wenn Ihr Polygon kein Rechteck ist, müssen Sie zunächst eine Ebene aus der Ausdehnung Ihres Polygons erstellen und dann drehen. Dann können Sie das Raster entsprechend dieser neuen Ausdehnung erstellen und dann Ihr Polygon und das Raster wieder auf die ursprüngliche Ausdehnung des Polygons drehen. Dies alles, während sichergestellt wird, dass in beiden Ebenen dieselbe x, y-Koordinate als Ankerpunkt verwendet wird.
#Define extent of Polygon
ext = QgsVectorLayer('path_to_polygon.shp', '', 'ogr' ).extent()
xmin = ext.xMinimum()
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum()
coords = "%f,%f,%f,%f" %(xmin, xmax, ymin, ymax)
#Define The angle of rotation. Change value to yours
azimut = 70.043
#define anchor point for rotation
anchor = "%f, %f" % (xmin, ymax)
#define x and y spacing of grid. Update to your desired spacing.
x = 3
y = 6
#create new polygon from extent
processing.run("native:extenttolayer", {'INPUT':coords,'OUTPUT':'Path_to_Output.shp'})
#Rotate Extent
processing.run("native:rotatefeatures", {'INPUT': 'Path_to_extent_Polygon.shp','ANGLE': azimut,'ANCHOR':anchor + '[EPSG:4326]','OUTPUT': 'Path_to_rotated_extent.shp'})
#Define extent of Rotated Polygon
ext1 = QgsVectorLayer('Path_to_Rotated_Extent.shp', '', 'ogr' ).extent()
xmin1 = ext1.xMinimum()
xmax1 = ext1.xMaximum()
ymin1 = ext1.yMinimum()
ymax1 = ext1.yMaximum()
coords1 = "%f,%f,%f,%f" %(xmin1, xmax1, ymin1, ymax1)
#Create grid
processing.run("qgis:creategrid", {'TYPE':0,'EXTENT': coords1 +'[EPSG:4326]','HSPACING':x,'VSPACING':y,'HOVERLAY':0,'VOVERLAY':0,'CRS':'EPSG:4326','OUTPUT': 'Path_to_grid.shp'})
#Rotate Grid to original extent
processing.run("native:rotatefeatures", {'INPUT': 'path_to_grid.shp','ANGLE': -
azimut,'ANCHOR':rotate + '[EPSG:4326]','OUTPUT': 'path_to_rotated_grid.shp'})
# Clip Grid to Original Polygon
processing.run("native:clip", {'INPUT':'path_to_rotated_grid.shp','OVERLAY':
'path_to_original_Polygon.shp','OUTPUT':'path_to_final_grid.shp'})