I have some expressions for drawing tree canopy zones ultimately I want to merge the zones for trees, hedges and woodland together but for now I would be happy if I can get the following expression to work as an SQL query to generate a virtual layer. I am new to virtual layers but have managed to create a basic buffer, however when I try to build up my canopy expression the query runs but either generates nothing or points only.

This is my main expression

            when  "EvenCan" is null
                                        Project($geometry, "n" ,Radians(0)),
                                        Project($geometry, "e",Radians(90)),
                                        Project($geometry, "s" ,Radians(180)),
                                        Project($geometry, "w" ,Radians(270))

                ,0 , 0 )
            when  "EvenCan" is not null
            then buffer($geometry,"EvenCan")


I have tried to translate the basic bit as follows but that generates an empty layer


    ST_Project(geometry, n,Radians(0)),
    ST_Project(geometry, e, Radians(90)),
    ST_Project(geometry, s,Radians(180)),
    ST_Project(geometry, w,Radians(270))
  • 1
    You can construct the polygon by creating new points using st_x(geometry)+e (etc), but be careful with the distance unit of your layer CRS. (though either it is already in meters and the use of st_project is wrong, or it is in degrees and the use of the st_buffer is wrong, so in any case the output is artistic only)
    – JGH
    Commented Jan 8 at 19:25
  • @JGH seems like ST_ functions expecting data in degrees might be part of the issue with the bit I have tried to translate - the longer expression is a geometry generator expression which works fine and uses buffer not st_buffer. Can I get the X Coordinate to add e to if working in meters?
    – Sethinacan
    Commented Jan 8 at 20:15
  • 2
    You could try using st_translate() instead of st_project(), and shift the point using x/y values instead of a distance and bearing. Like modifying the canopy expression in this question gis.stackexchange.com/questions/244192/… which is for geometry generator, but a very similar approach can be used in virtual layer which was deleted out of my original answer to that question.
    – she_weeds
    Commented Jan 8 at 20:59
  • @she_weeds yep just worked up something using translate (not ST_Translate) and that's good, but Virtual layers don't appear to support Smooth functions so my idea to dissolve trees, hedges and woodland into one manageable layer seems dead for now. I assume you solved your DXF issues - I've spent some time down that rabbit hole.
    – Sethinacan
    Commented Jan 8 at 21:26
  • Well you can still use collect/union without smoothing and merge them together - would suffice for impact analysis IMO, just that it won't look very nice :) Unless you have run into other problems? That particular dxf issue (geom generator export) was long since resolved, but if you have any others, post a question or start a chat, happy to try and assist as I do similar work.
    – she_weeds
    Commented Jan 8 at 21:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.