3

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

union(
    difference(
        buffer(
        case
            when  "EvenCan" is null
            then
                translate(
                            buffer( 
                                smooth(
                                    make_polygon(
                                        make_line(
                                        Project($geometry, "n" ,Radians(0)),
                                        Project($geometry, "e",Radians(90)),
                                        Project($geometry, "s" ,Radians(180)),
                                        Project($geometry, "w" ,Radians(270))
                                        )
                                    )
                                ,5)
                            ,(("n"+"e"+"s"+"w")*0.058),8)

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

        END
        ,2)
    ,aggregate('Zone_2_subtractions_4e7a378a_1173_41b7_bfdd_e98a0218a2c7','collect',$geometry)
    )
,aggregate('zone_2_additions_3e32c88c_f49b_4b5f_9bf5_8253da06c30e','collect',$geometry) 
)

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

select

make_polygon(
    make_line(
    ST_Project(geometry, n,Radians(0)),
    ST_Project(geometry, e, Radians(90)),
    ST_Project(geometry, s,Radians(180)),
    ST_Project(geometry, w,Radians(270))
    )
)
from
BS_TreeSurveyData_df898e14_a741_43f7_aaa8_8f268457f6d8
8
  • 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

0

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.