[Qgis-user] Point Fill Polygon

Martin Bain Martin.Bain at lismore.nsw.gov.au
Sun Oct 8 18:40:22 PDT 2017


Hi Tyler,
Good question.  I couldn’t see how to do it with a “Point Pattern Fill”

But you could do it with a “Geometry Generator” style and a custom function.

Here’s a custom function I wrote to generate a grid of points from the feature polygon’s bounding box.

It intersects the point grid with the polygon to return a multipoint object of all the points within the polygon.
---------------------------------------------------------------------------------------------------------
"""
Define new functions using @qgsfunction. feature and parent must always be the
last args. Use args=-1 to pass a list of values as arguments
"""

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def pointGrid(step, feature, parent):
                geom=feature.geometry()
                mbr=feature.geometry().boundingBox()
                x1=mbr.xMinimum()
                x2=mbr.xMaximum()
                y1=mbr.yMinimum()
                y2=mbr.yMaximum()
                gPnt =[]
                while x1<x2:
                                while y1<y2:
                                                gPnt.append(QgsPoint(x1,y1))
                                                y1=y1+step
                                y1=mbr.yMinimum()
                                x1=x1+step
                mpt = QgsGeometry.fromMultiPoint(gPnt)
                points=geom.intersection(mpt)
                return points
--------------------------------------------------------------------------------------------------------------------

You enter the function on the “Function Editor” tab next to the “Expression” tab, I just typed over the example function that was already there.

Once you define the function you need to click the Load button.

You can then use the function in the expression editor, you will find it in the “Custom” group.

The function has one argument, which is for the spacing of the points, for example if the expression was “pointGrid(5)” they will be 5 metres apart.

Don’t know how you would go if you are using a lat long coordinate system, sorry.

Its just a quick proof of concept – no doubt the code could be written a lot more elegantly, my knowledge of both python and the QGIS API isn’t that deep.

Hope it helps.

I did have some screenshots attached but they prevented the message from getting posted.

Martin.



From: Qgis-user [mailto:qgis-user-bounces at lists.osgeo.org] On Behalf Of Tyler Veinot
Sent: Saturday, 7 October 2017 5:08 AM
To: QGIS User List <qgis-user at lists.osgeo.org<mailto:qgis-user at lists.osgeo.org>>
Subject: [Qgis-user] Point Fill Polygon

Hi;
In a point/symbol fill polygon is there anyway to allow the point/svg symbol to extrude over the polygon border and not be cut off. Or only show symbols that are completely contained by the polygon? The polygon is only a rough area of forest and I am trying to fill it with little tree triangles but I don't want symbol slivers at the polygon edge.
Tyler


This email is intended for the named recipient only.  The information it contains may be confidential.  If you are not the intended recipient you must not reproduce or distribute any part of this email, disclose its contents to any other party or take any action in reliance on it.  If you have received this email in error, please contact the sender immediately and delete the message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20171009/d6ab9c39/attachment.html>


More information about the Qgis-user mailing list