6

After my experiences with a custom Python linestyle expression function (Wavy Edge on polygon in QGIS using geometry generators) I modified the code to support Polygons with holes, MultiPolygons and MultiLineStrings as well. See the following picture using the same Geometry generator styling for all layer types:

smooth(customLineStyle( $geometry,'45 30,45 0,45 -30,45 0'),5)

enter image description here

enter image description here

Unfortunately, QGIS crashes with MultiLineStrings in Windows 10 (QGIS 3.14.16-Pi).

I don't know, is it a bug or is there something wrong with my code (see below)?

import itertools, math, re
from qgis.core import qgsfunction,QgsPoint,QgsGeometry,QgsWkbTypes,QgsPointXY

def createCustomLine(geom,param):
    geom = QgsGeometry(geom)
    dst = geom.length()
    vertices = geom.asPolyline()
    start = (vertices[0].x(),vertices[0].y())
    end = (vertices[-1].x(),vertices[-1].y())
    l = [list(map(float,x.split(' '))) for x in param.split(',')]
    steps,offsets = zip(*l)
    d = sum(steps)
    newdst = dst / int(dst / d)
    newsteps = [x / d  * newdst for x in steps]
    d = sum(newsteps)
    cnt = int(dst / d)
    distances = list(itertools.chain.from_iterable(itertools.repeat(newsteps,cnt)))[0:-1]
    alloffsets = list(itertools.chain.from_iterable(itertools.repeat(offsets,cnt)))
    alloffsets.insert(0,0)
    distances = list(itertools.accumulate(distances))
    points2d = [(lambda g,d: (g.x(), g.y(),d))(geom.interpolate(d).asPoint(),d) for d in distances]
    distances.insert(0,0)
    points2d.insert(0,start) # prepend start point
    points = [QgsPoint(start[0],start[1])]
    for i,pt in enumerate(points2d[1:]):
        if distances[i+1] > distances[i]:
            corrAngle = -90
        else:
            corrAngle = 90
        qgsPt = QgsPoint(pt[0],pt[1])
        points.append(qgsPt.project(alloffsets[i+1],QgsPoint(points2d[i][0],points2d[i][1]).azimuth(qgsPt) + corrAngle))

    points.append(QgsPoint(end[0],end[1])) # append end point
    return QgsGeometry.fromPolyline(points)

def createCustomPolygon(geom,param):
    wkt = geom.asWkt()
    geometries = [QgsGeometry.fromWkt('LineString(%s)' % g) for g in re.findall('[^()]+',wkt) if g != ','][1:]
    geom = geometries[0]
    rings = geometries[1:]
    geom = createCustomLine(geom,param)
    geom = geom.convertToType(QgsWkbTypes.PolygonGeometry)
    if rings:
        for ring in rings:
            ring = createCustomLine(ring,param)
            ptArray = [QgsPointXY(pt.x(),pt.y()) for pt in list(ring.vertices())]
            geom.addRing(ptArray)
    return geom
    
@qgsfunction(args='auto', group='Custom', usesGeometry=False, referencedColumns=[])
def customLineStyle(geom,param,feature,parent):
    rings = None
    if geom.wkbType() == QgsWkbTypes.LineString:
        newGeom = createCustomLine(geom,param)
    elif geom.wkbType() == QgsWkbTypes.MultiLineString:
        wkt = "MultiLineString("+",".join([re.findall('^[^(]+(.+)',createCustomLine(part,param).asWkt())[0] for part in geom.parts()])+")"
        newGeom = QgsGeometry.fromWkt(wkt)
    elif geom.wkbType() == QgsWkbTypes.Polygon:
        newGeom = createCustomPolygon(geom,param)
    elif geom.wkbType() == QgsWkbTypes.MultiPolygon:
        wkt = "MultiPolygon("+",".join([re.findall('^[^(]+(.+)',createCustomPolygon(part,param).asWkt())[0] for part in geom.parts()])+")"
        newGeom = QgsGeometry.fromWkt(wkt)
      
    return newGeom
6

After a lot of changes in my terrible inefficient code, it's now working with all geometry types. I could add some caching to make it a little bit faster, but for the moment it's ok.

import itertools, math, re
from qgis.core import qgsfunction,QgsGeometry,QgsWkbTypes,QgsPointXY

def createCustomLine(vertices,param):
    geom = QgsGeometry.fromPolylineXY(vertices)
    dst = geom.length()
    start = (vertices[0].x(),vertices[0].y())
    end = (vertices[-1].x(),vertices[-1].y())
    l = [list(map(float,x.split(' '))) for x in param.split(',')]
    steps,offsets = zip(*l)
    d = sum(steps)
    newdst = dst / int(dst / d)
    newsteps = [x / d  * newdst for x in steps]
    d = sum(newsteps)
    cnt = int(dst / d)
    distances = list(itertools.chain.from_iterable(itertools.repeat(newsteps,cnt)))[0:-1]
    alloffsets = list(itertools.chain.from_iterable(itertools.repeat(offsets,cnt)))
    alloffsets.insert(0,0)
    distances = list(itertools.accumulate(distances))
    points2d = [(lambda g,d: (g.x(), g.y(),d))(geom.interpolate(d).asPoint(),d) for d in distances]
    distances.insert(0,0)
    points2d.insert(0,start) # prepend start point
    points = [QgsPointXY(start[0],start[1])]
    for i,pt in enumerate(points2d[1:]):
        if distances[i+1] > distances[i]:
            corrAngle = -90
        else:
            corrAngle = 90
        qgsPt = QgsPointXY(pt[0],pt[1])
        points.append(qgsPt.project(alloffsets[i+1],QgsPointXY(points2d[i][0],points2d[i][1]).azimuth(qgsPt) + corrAngle))

    points.append(QgsPointXY(end[0],end[1])) # append end point
    return points

def createCustomPolygon(geom,param):
    if not geom.isMultipart():
        geom = QgsGeometry.fromPolygonXY([createCustomLine(ring,param) for ring in geom.asPolygon()])
    else:
        geom = QgsGeometry.fromMultiPolygonXY([[createCustomLine(ring,param) for ring in polyg] for polyg in geom.asMultiPolygon()])

    return geom
    
@qgsfunction(args='auto', group='Custom', usesGeometry=False, referencedColumns=[])
def customLineStyle(geom,param,feature,parent):
    """
    <style>
    span { color: red }

    </style>
    <h2>apply a custom linestyle to a (multi)linestring or (multi)polygon</h2>

    customLineStyle(<span>geometry</span>,<span>param</span>)<br/>

    <table>
        <tr><td><span>geometry</span></td><td>linestring geometry</td></tr>
        <tr><td><span>param</span></td><td>list of linear point distances followed by perpendicular offsets</tr>
    </table>
    <br/><br/>
    Example:
    <img src='data:image/svg+xml;utf8,<svg width="55.471mm" height="29.561mm" version="1.2" viewBox="0 0 436.78 232.76" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="#000000" fill-opacity="0" fill-rule="evenodd" font-size="22.917" font-weight="400" stroke-linecap="square" stroke-linejoin="bevel"><rect width="787" height="394"/></g><g fill="none" font-size="22.917" font-weight="400" stroke-linecap="square" stroke-linejoin="bevel"><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" stroke="#c40000" stroke-width="5.5118"><path d="m169.4 223.02 103.14-58.768 206.27 117.54 103.14-58.768" fill-rule="evenodd"/></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" stroke="#5d5d5d" stroke-dasharray="78.7402, 31.4961" stroke-width="2.0472"><path d="m169.4 223.02h412.54" fill-rule="evenodd"/></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)"><path d="m272.8 164.31 1.058 58.707" fill-rule="evenodd" vector-effect="non-scaling-stroke"/></g></g><g font-size="22.917" font-weight="400" stroke-linecap="square" stroke-linejoin="bevel"><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="#000000" fill-rule="evenodd"><path d="m335.78 163.17-11.596 12.022 11.022-0.199 0.632 35.09-11.022 0.198 12.022 11.597 11.596-12.022-11.021 0.198-0.633-35.089 11.022-0.199-12.022-11.596" fill-rule="evenodd"/></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="none" fill-rule="evenodd" stroke="#000000"><path d="m351.52 162.89-78.728 1.419" vector-effect="non-scaling-stroke"/><path d="m352.58 221.6-78.728 1.418" vector-effect="non-scaling-stroke"/></g><g><g transform="matrix(.99822 0 0 .99822 227.13 140.57)" fill="#000000" fill-rule="evenodd"><path d="m-8.2374-47.064c3.7445-0.0675 6.5367 0.9234 8.3767 2.9726 1.5291 1.712 2.3162 3.8183 2.3613 6.3188 0.05009 2.7799-0.81972 5.0684-2.6094 6.8655-1.7897 1.7972-4.2902 2.7248-7.5016 2.7826-2.6022 0.0469-4.656-0.3065-6.1615-1.0603s-2.6843-1.8689-3.5362-3.3455-1.2938-3.0971-1.3256-4.8615c-0.051-2.8306 0.8154-5.1349 2.5991-6.9129 1.7836-1.778 4.3827-2.6978 7.7972-2.7593m0.06347 3.5224c-2.5894 0.0466-4.5182 0.6464-5.7862 1.7993s-1.8865 2.5862-1.8557 4.2998c0.0307 1.7009 0.7035 3.1045 2.0186 4.2109 1.3151 1.1063 3.299 1.6356 5.9519 1.5878 2.5006-0.045 4.3848-0.6472 5.6527-1.8064 1.2679-1.1593 1.8866-2.583 1.8562-4.2712-0.030876-1.7136-0.6975-3.1237-1.9999-4.2303-1.3024-1.1066-3.2483-1.6366-5.8377-1.5899m-9.7396 20.751 17.555-0.3163-0.054546-3.0274 2.6656-0.048 0.05455 3.0273 2.1515-0.0387c1.3582-0.0245 2.3695 0.0779 3.0339 0.3072 0.89448 0.314 1.6253 0.8817 2.1924 1.7032 0.56716 0.8214 0.86416 1.9811 0.89116 3.4789 0.0174 0.9647-0.0776 2.033-0.2851 3.2049l-2.9985-0.4603c0.11412-0.7131 0.16547-1.387 0.15403-2.0216-0.01875-1.0409-0.25415-1.7731-0.70619-2.1966-0.45204-0.4236-1.2873-0.6244-2.5059-0.6024l-1.8659 0.0336 0.07102 3.9412-2.6656 0.0481-0.071014-3.9413-17.555 0.3163-0.0614-3.4081m0.1982 10.998 17.555-0.3163-0.054547-3.0274 2.6656-0.048 0.05454 3.0273 2.1515-0.0387c1.3582-0.0245 2.3695 0.0779 3.0339 0.3072 0.89447 0.314 1.6253 0.8817 2.1924 1.7032 0.5671 0.82146 0.8642 1.9811 0.8912 3.4789 0.0174 0.96469-0.0777 2.033-0.2851 3.2049l-2.9985-0.46021c0.11413-0.71311 0.16547-1.387 0.15404-2.0217-0.01876-1.0408-0.25415-1.773-0.70619-2.1966s-1.2873-0.62437-2.5059-0.60241l-1.8659 0.03362 0.07101 3.9412-2.6656 0.04803-0.071014-3.9413-17.555 0.31631-0.0614-3.4081m6.2123 9.6997 0.5942 3.3795c-1.3547 0.21487-2.386 0.76356-3.0939 1.6461-0.7078 0.88252-1.0477 2.1044-1.0195 3.6657 0.0283 1.574 0.3699 2.736 1.0246 3.486 0.6547 0.75 1.4137 1.1173 2.2768 1.1017 0.7743-0.0139 1.3775-0.3613 1.8096-1.042 0.29618-0.47516 0.66228-1.6499 1.0983-3.5243 0.58938-2.5247 1.107-4.2767 1.5528-5.2561 0.44581-0.97938 1.0736-1.7271 1.8832-2.2433 0.80968-0.51614 1.7096-0.78312 2.6996-0.80096 0.90122-0.01623 1.7395 0.17499 2.5149 0.57369 0.77538 0.39869 1.4233 0.94888 1.9439 1.6505 0.4031 0.52603 0.74939 1.2467 1.0389 2.1621 0.28949 0.91535 0.44372 1.8998 0.46271 2.9533 0.02858 1.5867-0.17479 2.9839-0.61014 4.1916-0.43534 1.2077-1.0382 2.1042-1.8085 2.6895-0.77034 0.5852-1.8073 0.9975-3.1108 1.2369l-0.51733-3.3428c1.0381-0.1711 1.8425-0.6268 2.4133-1.3672s0.8441-1.777 0.82009-3.1098c-0.02836-1.574-0.30881-2.6926-0.84136-3.356-0.53254-0.66337-1.1479-0.98876-1.846-0.97618-0.44427 8e-3 -0.84159 0.15483-1.192 0.44049-0.36307 0.28588-0.65982 0.72929-0.89024 1.3302-0.12076 0.345-0.39452 1.3594-0.82129 3.0431-0.60367 2.4361-1.1031 4.137-1.4984 5.1028-0.39527 0.9658-0.98147 1.7286-1.7586 2.2886s-1.7496 0.8505-2.9174 0.8716c-1.1424 0.0206-2.2241-0.2932-3.2452-0.9415-1.0212-0.6482-1.8191-1.5956-2.3939-2.8423-0.5748-1.2467-0.8765-2.6634-0.9051-4.25-0.0473-2.6275 0.4624-4.6397 1.5292-6.0366 1.0668-1.3969 2.6693-2.3051 4.8076-2.7245m1.0924 34.201-0.3741 3.5493c-2.079-0.5212-3.7034-1.5268-4.873-3.0167s-1.7756-3.409-1.8179-5.7572c-0.0533-2.9576 0.8152-5.3191 2.6055-7.0845 1.7903-1.7655 4.3292-2.6778 7.6167-2.737 3.4018-0.0613 6.0578 0.7669 7.9679 2.4848 1.9102 1.7178 2.8904 3.9729 2.9407 6.7655 0.04871 2.7036-0.83175 4.9288-2.6414 6.6756-1.8096 1.7467-4.3836 2.6502-7.722 2.7103-0.20309 0.0037-0.50784 0.0028-0.91425-0.0025l-0.27171-15.08c-2.219 0.1669-3.9086 0.8259-5.0688 1.9769-1.1601 1.1509-1.7249 2.5705-1.6945 4.2587 0.0226 1.2566 0.372 2.3233 1.048 3.1999 0.6761 0.8767 1.7423 1.5621 3.1987 2.0565m5.3379-11.352 0.20343 11.291c1.6982-0.1829 2.966-0.6375 3.8037-1.3636 1.3004-1.1154 1.935-2.5426 1.9036-4.2816-0.02836-1.574-0.57897-2.8877-1.6518-3.9413-1.0729-1.0536-2.4925-1.6217-4.2589-1.7041m-8.5023 27.052-3.0185 0.5496c-0.2204-0.961-0.3375-1.8224-0.3513-2.584-0.0224-1.2439 0.157-2.2121 0.5381-2.9046 0.3812-0.6926 0.8897-1.1842 1.5257-1.475s1.9821-0.4548 4.0384-0.4918l11.633-0.2096-0.045284-2.5133 2.6656-0.048 0.04528 2.5132 5.0075-0.0902 2.1177 3.3711-7.0638 0.1273 0.06209 3.4462-2.6656 0.048-0.062094-3.4462-11.824 0.2131c-0.9774 0.0176-1.6047 0.0892-1.8817 0.2148-0.2771 0.1256-0.4957 0.3264-0.6558 0.6022-0.1601 0.2759-0.2356 0.6677-0.2264 1.1755 0.0068 0.3807 0.0603 0.8813 0.1604 1.5017" fill-rule="evenodd"/></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="none"><path d="m168.08 163.78h104.46" fill-rule="evenodd" vector-effect="non-scaling-stroke"/></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="#000000" fill-rule="evenodd"><path d="m168.08 100.79 11.811 11.811v-11.024h80.835v11.024l11.811-11.811-11.811-11.811v11.023h-80.835v-11.023l-11.811 11.811" fill-rule="evenodd"/></g></g><g transform="matrix(.99822 0 0 .99822 -147.87 -50.91)" fill="none" fill-rule="evenodd" stroke="#000000"><path d="m168.08 85.04v78.74" vector-effect="non-scaling-stroke"/><path d="m272.53 85.04v78.74" vector-effect="non-scaling-stroke"/></g><g transform="matrix(.99822 0 0 .99822 72.039 10.398)" fill="#000000" fill-rule="evenodd"><path d="m-57.809 17.5v-2.5518c-1.2822 2.0059-3.1675 3.0088-5.6558 3.0088-1.6123 0-3.0944-0.4443-4.4465-1.333-1.352-0.8887-2.3994-2.1296-3.1421-3.7229s-1.114-3.4246-1.114-5.4939c0-2.0186 0.3364-3.8498 1.0093-5.4939 0.6728-1.644 1.6821-2.9041 3.0278-3.78 1.3457-0.87598 2.8501-1.314 4.5132-1.314 1.2188 0 2.3042 0.25708 3.2563 0.77124 0.9522 0.51416 1.7266 1.1838 2.3233 2.009v-10.017h3.4087v27.917h-3.1802m-10.835-10.093c0 2.5898 0.5459 4.5259 1.6377 5.8081 1.0917 1.2822 2.3803 1.9234 3.8657 1.9234 1.498 0 2.7707-0.6126 3.8181-1.8377s1.571-3.0945 1.571-5.6081c0-2.7676-0.5332-4.7988-1.5996-6.0938-1.0664-1.2949-2.3803-1.9424-3.9419-1.9424-1.5234 0-2.7961 0.62207-3.8181 1.8662-1.022 1.2441-1.5329 3.2056-1.5329 5.8843m19.734-13.882v-3.9419h3.4278v3.9419h-3.4278m0 23.975v-20.224h3.4278v20.224h-3.4278m7.6099-6.0366 3.3897-0.5332c0.1904 1.3584 0.7204 2.3994 1.59 3.123 0.8697 0.7236 2.0852 1.0855 3.6468 1.0855 1.5742 0 2.7422-0.3206 3.5039-0.9617s1.1426-1.3933 1.1426-2.2566c0-0.7744-0.3365-1.3838-1.0093-1.8281-0.4697-0.30471-1.6377-0.69191-3.5039-1.1616-2.5137-0.63477-4.2561-1.1838-5.2273-1.6472s-1.7075-1.1045-2.209-1.9233-0.7522-1.7234-0.7522-2.7136c0-0.90137 0.2063-1.7361 0.6189-2.5042 0.4126-0.76807 0.9744-1.406 1.6853-1.9138 0.5332-0.39356 1.26-0.72681 2.1804-0.99976s1.9075-0.40942 2.9612-0.40942c1.5869 0 2.9802 0.22852 4.1799 0.68555s2.0852 1.0759 2.6565 1.8567c0.5713 0.78076 0.9649 1.825 1.1807 3.1326l-3.3516 0.45703c-0.1523-1.041-0.5935-1.8535-1.3235-2.4375-0.7299-0.58398-1.7614-0.87598-3.0944-0.87598-1.5743 0-2.6978 0.26025-3.3707 0.78076-0.6728 0.52051-1.0092 1.1299-1.0092 1.8281 0 0.44433 0.1396 0.84423 0.4189 1.1997 0.2793 0.36817 0.7173 0.67285 1.314 0.91407 0.3428 0.12695 1.352 0.41894 3.0278 0.87597 2.4248 0.64746 4.1165 1.1775 5.075 1.5901s1.7107 1.0124 2.2566 1.7996 0.8188 1.7646 0.8188 2.9326c0 1.1426-0.3332 2.2185-0.9998 3.2278-0.6665 1.0092-1.6281 1.79-2.885 2.3423-1.2568 0.5522-2.6787 0.8283-4.2656 0.8283-2.6279 0-4.6306-0.5459-6.008-1.6377-1.3775-1.0918-2.2566-2.7104-2.6375-4.8559m27.855 2.9707 0.4951 3.0278c-0.9648 0.2031-1.8281 0.3047-2.5898 0.3047-1.2442 0-2.209-0.1968-2.8946-0.5903-0.6855-0.3936-1.1679-0.9109-1.4472-1.552s-0.419-1.99-0.419-4.0467v-11.635l-2.5137-4e-7v-2.666h2.5137v-5.0083l3.4087-2.0566v7.0649h3.4468v2.666l-3.4468-6e-7v11.826c0 0.9775 0.0603 1.6059 0.1809 1.8852s0.3174 0.5015 0.5903 0.6665c0.273 0.1651 0.6634 0.2476 1.1712 0.2476 0.3808 0 0.8823-0.0445 1.5044-0.1333m16.713 0.5713c-1.2695 1.0791-2.4915 1.8408-3.6658 2.2851-1.1743 0.4444-2.4343 0.6665-3.78 0.6665-2.2217 0-3.9292-0.5427-5.1226-1.6281-1.1933-1.0855-1.79-2.4725-1.79-4.1609 0-0.9903 0.2253-1.8948 0.676-2.7137 0.45069-0.81884 1.041-1.4758 1.771-1.9709 0.72998-0.49512 1.552-0.86963 2.4661-1.1235 0.67286-0.17773 1.6885-0.34912 3.0469-0.51416 2.7676-0.33008 4.8052-0.72363 6.1128-1.1807 0.0127-0.46973 0.01905-0.76807 0.01905-0.89502 0-1.3965-0.32373-2.3804-0.97119-2.9517-0.87598-0.77441-2.1773-1.1616-3.9038-1.1616-1.6123 0-2.8025 0.28247-3.5706 0.84741-0.76807 0.56494-1.3362 1.5647-1.7044 2.9993l-3.3516-0.45704c0.3047-1.4346 0.80616-2.593 1.5044-3.4753 0.69824-0.88232 1.7075-1.5615 3.0278-2.0376 1.3203-0.47608 2.8501-0.71411 4.5894-0.71411 1.7266 0 3.1294 0.20312 4.2085 0.60937s1.8726 0.91724 2.3804 1.533c0.50781 0.61572 0.86328 1.3933 1.0664 2.3328 0.11425 0.58399 0.17138 1.6377 0.17138 3.1611v4.5703c0 3.1865 0.073 5.2019 0.219 6.0461 0.14599 0.8443 0.43481 1.6536 0.86645 2.428h-3.5801c-0.35547-0.7109-0.58398-1.5425-0.68554-2.4946m-0.28565-7.6553c-1.2441 0.50781-3.1103 0.93945-5.5986 1.2949-1.4092 0.20312-2.4058 0.43164-2.9898 0.68555-0.58398 0.2539-1.0347 0.62524-1.352 1.114-0.31738 0.4887-0.47607 1.0315-0.47607 1.6282 0 0.914 0.34594 1.6757 1.0378 2.2851 0.69189 0.6094 1.7043 0.9141 3.0374 0.9141 1.3203 0 2.4946-0.2888 3.523-0.8665 1.0283-0.5776 1.7837-1.3679 2.2661-2.3708 0.36816-0.7744 0.55224-1.917 0.55224-3.4278v-1.2568m9.0889 10.15v-20.224h3.085v2.8755c1.4853-2.2217 3.6308-3.3325 6.4365-3.3325 1.2187 0 2.3391 0.21899 3.3611 0.65698 1.0219 0.43799 1.7868 1.0124 2.2946 1.7234 0.5079 0.71094 0.8633 1.5552 1.0665 2.5327 0.1269 0.63476 0.1904 1.7456 0.1904 3.3325v12.435h-3.4278v-12.302c0-1.3965-0.1333-2.4407-0.3999-3.1326-0.2666-0.6919-0.7395-1.2441-1.4187-1.6567-0.6792-0.4126-1.4758-0.6189-2.3898-0.6189-1.46-1e-6 -2.72 0.46338-3.7801 1.3901-1.06 0.92676-1.5901 2.6851-1.5901 5.2749v11.045h-3.4277m35.197-7.4077 3.3706 0.438c-0.3682 2.3232-1.3108 4.1418-2.8279 5.4558s-3.3801 1.9709-5.5891 1.9709c-2.7676 0-4.9924-0.9045-6.6746-2.7136-1.6821-1.8091-2.5232-4.4021-2.5232-7.779 0-2.1836 0.3619-4.0942 1.0855-5.7319 0.7236-1.6377 1.8249-2.866 3.3039-3.6848 1.479-0.81884 3.0882-1.2283 4.8274-1.2283 2.1963 0 3.9927 0.55542 5.3892 1.6663 1.3965 1.1108 2.2915 2.6882 2.6851 4.7322l-3.3326 0.51416c-0.3173-1.3584-0.8791-2.3804-1.6853-3.0659-0.8061-0.68555-1.7805-1.0283-2.9231-1.0283-1.7265 0-3.1294 0.6189-4.2085 1.8567-1.0791 1.2378-1.6186 3.196-1.6186 5.8748 0 2.7168 0.5205 4.691 1.5615 5.9224 1.041 1.2315 2.3994 1.8472 4.0752 1.8472 1.3457 0 2.4692-0.4126 3.3706-1.2378s1.4727-2.0947 1.7139-3.8086m20.647 0.895 3.542 0.438c-0.5586 2.0693-1.5932 3.6753-3.104 4.8179-1.5107 1.1426-3.4404 1.7138-5.789 1.7138-2.958 0-5.3035-0.9108-7.0364-2.7326s-2.5994-4.3767-2.5994-7.6648c0-3.4023 0.876-6.043 2.628-7.9219 1.7519-1.8789 4.0244-2.8184 6.8173-2.8184 2.7041 0 4.9131 0.92041 6.627 2.7612 1.7139 1.8408 2.5708 4.4307 2.5708 7.7695 0 0.20312-0.0064 0.50781-0.0191 0.91406h-15.082c0.127 2.2216 0.7554 3.9228 1.8853 5.1035 1.1298 1.1806 2.539 1.771 4.2275 1.771 1.2568 0 2.3296-0.3301 3.2183-0.9903 0.8886-0.6601 1.5932-1.7138 2.1137-3.1611m-11.254-5.5415h11.292c-0.1523-1.7012-0.584-2.977-1.2949-3.8276-1.0918-1.3203-2.5073-1.9805-4.2466-1.9805-1.5742-1e-6 -2.8977 0.52686-3.9704 1.5806-1.0728 1.0537-1.6663 2.4629-1.7806 4.2275" fill-rule="evenodd"/></g></g></svg>'>
    <ul>
        <li>customLineStyle($geometry,'45 30,45 0,45 -30,45 0') -> zig-zag line</li>
    </ul>
    


    Use smooth function to create wavelines:<br/><br/>
    Example:
    <ul><li>smooth(customLineStyle( $geometry,'45 30,45 0,45 -30,45 0'),5)</li></ul>
    """
    rings = None
    if geom.wkbType() == QgsWkbTypes.LineString:
        geom = QgsGeometry.fromPolylineXY(createCustomLine(geom.asPolyline(),param))
    elif geom.wkbType() == QgsWkbTypes.MultiLineString:
        geom = QgsGeometry.fromMultiPolylineXY([createCustomLine(line,param) for line in geom.asMultiPolyline()])
    elif geom.wkbType() in [QgsWkbTypes.Polygon,QgsWkbTypes.MultiPolygon]:
        geom = createCustomPolygon(geom,param)
      
    return geom
7
  • Can you please add some screenshots on where pasting the code and how it shall work.
    – Taras
    Oct 14 '20 at 6:54
  • 1
    also you declare the variable 'd' twice. maybe declare the second 'd' as a new variable.
    – nr_aus
    Oct 14 '20 at 7:29
  • 1
    @Taras: added a screenshot to my original question to make it a bit clearer
    – christoph
    Oct 14 '20 at 8:03
  • Thank you @christoph
    – Taras
    Oct 14 '20 at 8:04
  • When I try use the function I always get an error: Eval Error: float division by zero. Any hints. thanks
    – user16032
    Jul 31 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.