Baru saja menemukan skrip daring yang dengan beberapa penyesuaian berfungsi dengan qgis 3.5.x
Saya kehilangan posting asli sehingga tidak bisa kredit penulis.
Apa yang Anda lakukan adalah:
- buat fill layer ubah menjadi "generator geometri"
- ubah "tipe geometri" menjadi titik
- untuk ekspresi, klik tombol "sigma" langsung ke bidang teks
- di jendela "dialog ekspresi", ubah tab menjadi "Editor fungsi" dan rekatkan kode di bawah sana
- Sekarang kembali ke "dialog ekspresi" tempel panggilan fungsi seperti itu: fillGrid (0.001,0.001,1) (2 nilai pertama adalah ukuran acak)
- Simpan perubahan dan perbarui tampilan.
- Poin acak yang mengagumkan ada di sana.
Terima kasih kepada penulis naskah aslinya.
from qgis.core import *
from qgis.gui import *
import math
import random
"""
Define a grid based on the interval and the bounding box of
the feature. Grid will minimally cover the feature and be centre aligned
Create a multi-point geometry at the grid intersections where
the grid is enclosed by the feature - i.e. apply a clipping mask
Random value determines amount of randomness in X/Y within its
grid square a particular feature is allowed to have
"""
@qgsfunction(args='auto', group='Custom')
def fillGrid(xInterval, yInterval, rand, feature, parent):
box = feature.geometry().boundingBox()
#Create a grid that minimally covers the boundary
#using the supplied intervals and centre it
countX = math.ceil(box.width() / xInterval)
countY = math.ceil(box.height() / yInterval)
#Align the grid
gridX = countX * xInterval
gridY = countY * yInterval
dX= gridX - box.width()
dY= gridY - box.height()
xMin = box.xMinimum() - (dX/2)
yMin = box.yMinimum() - (dY/2)
points = []
#+1 to draw a symbol on the n+1th grid element
for xOff in range(countX+1):
for yOff in range(countY+1):
ptX = xMin + xOff*(xInterval) + rand * random.uniform(0,xInterval)
ptY = yMin + yOff*(yInterval) + rand * random.uniform(0,xInterval)
pt = QgsPointXY(ptX,ptY)
point = QgsGeometry.fromPointXY(pt)
if feature.geometry().contains(point):
points.append(pt)
return QgsGeometry.fromMultiPointXY(points)