# Offset regular point grid inside polygon by a defined angle from north

Is there anyway to fill an irregular polygon with regular points but to also offset this regular point pattern with a defined angle offset from north? I make reference to an older answered post regarding the filling of polygons

Filling polygons with points or polygons

• is this for cartographic reasons (to do stippling) or do you actually need the points e.g. to do sampling? Jun 1 '17 at 17:36
• The points are representative of a wind turbine points within an array. so i would like to adjust the angle of the points to a defined value or another layer attribute value Jun 2 '17 at 9:13
• @user95443 any news about the solution?
– mgri
Jul 2 '17 at 19:10

You may run this code (adapted from this post I wrote some time ago) from the Python Console for controlling the spacing of your points and the inset from the North:

``````from qgis.core import *

# Set the spacing
spacing = 10
# Set the inset
inset_x = 5
inset_y = 5

# Get the Coordinate Reference System and the extent from the loaded layer
layer = iface.activeLayer() # load the layer as you want
crs = layer.crs().toWkt()
ext=layer.extent()

# Create a new vector point layer
points_layer = QgsVectorLayer('Point?crs=' + crs, 'grid', "memory")
prov = points_layer.dataProvider()

# Create the coordinates of the points in the grid
points = []

for ft in layer.getFeatures():
feat_geom = ft.geometry()
# Set the extent of the new layer
xmin = ext.xMinimum() + inset_x
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum() - inset_y
y = ymax
while y >= ymin:
x = xmin
while x <= xmax:
geom = QgsGeometry().fromPoint(QgsPoint(x, y))
feat = QgsFeature()
point = QgsPoint(x,y)
feat.setGeometry(QgsGeometry.fromPoint(point))
if feat_geom.contains(feat.geometry()):
points.append(feat)
x += spacing
y = y - spacing

For example, using a high value for the insets (`inset_x = 50` and `inset_y = 30`), I get this result: 