QGIS Ellipse Marker Line Pattern – Creating Ellipse Marker with Line Pattern Fill in QGIS
fillmarkersqgisstylesymbology
How can I create an ellipse marker with line pattern fill in QGIS?
Like this:
I have already made simpler symbols, but there is no solution with the ellipse
Best Answer
To get the different symbols for each half of the ellipse:
make a Geometry Generator symbol layer
use this expression
with_variable('ellipse',
make_ellipse( $geometry, 10, 5, 0), -- make an ellipse and assign it to a variable
rotate(
intersection( -- get intersection of rectangle and ellipse to 'clip' half of it
make_rectangle_3points( -- make a rectangle that is half the bounding box of the ellipse
project($geometry, y_max(@ellipse) - y($geometry), 0), -- project a point from the original point directly north by half the height of the ellipse
project($geometry, y_max(@ellipse) - y($geometry), radians(180)), -- project a point from the original point directly south by half the height of the ellipse
make_point(x_max(@ellipse), y_min(@ellipse)) -- make a point of the 'lower right' corner of the bounds of the ellipse
),
@ellipse -- @ellipse is the variable name of the ellipse made above
),
120, $geometry -- rotate the half-ellipse, 120 is the rotation angle, $geometry is the center of rotation (the original point geometry)
)
)
duplicate the symbol layer
change angle in rotate by 180 degrees so the new symbol layer aligns with the first (in my case 120->300)
style the 2 symbol layers as desired
don't forget to set Units to Millimeter for a scalable symbol
Select your symbols by either clicking them individually whilst holding Ctrl or click the uppermost symbol, hold Shift and click the last symbol you want selected. Then go to Symbol > Change:
Then select your fill and set the border style:
When you click OK, the selected symbols should be updated with the new border properties:
EDIT:
To keep your pattern fills, a possible workaround is after you have categorised your layer, change it to Rule-based. This will create expressions for each of your symbol which should match the categorised version. Then create a new rule which has a transparent fill and set your border with the required settings and with no filter/rule:
You should now have features which contain your pattern fill but with the border you have set:
ok, sometimes you don't realize that you're almost at the finish line...following SE Question pointed me into the right direction and after adding some lines of code it now works :)
Working Example:
var geojsonObject = 'someGeoJSON'
var source = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
var layer = new ol.layer.Vector({
source: source
});
var cnv = document.createElement('canvas');
var ctx = cnv.getContext('2d');
var img = new Image();
img.src = 'https://mdn.mozillademos.org/files/222/Canvas_createpattern.png';
img.onload = function() {
var pattern = ctx.createPattern(img, 'repeat');
layer.setStyle(new ol.style.Style({
fill: new ol.style.Fill({
color: pattern
})
}));
};
Best Answer
To get the different symbols for each half of the ellipse:
rotate
by 180 degrees so the new symbol layer aligns with the first (in my case120
->300
)Units
toMillimeter
for a scalable symbol