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

Sethinacan
  • 1,724
  • 11
  • 19
  • 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 Jan 08 '24 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 Jan 08 '24 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 https://gis.stackexchange.com/questions/244192/cant-export-geometry-generator-styling-to-dxf-alternatives 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 Jan 08 '24 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 Jan 08 '24 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 Jan 08 '24 at 21:53
  • @she_weeds I think I have another work around. Didn't know you could starts chats on SE. – Sethinacan Jan 09 '24 at 08:41
  • I think they're a sort of semi public room that others can see but not necessarily join, mainly to reduce clutter on the actual questions. Sometimes a "continue this in chat" prompt appears when there's been a long string of comments to a post. I think that link lets you create a targeted room, otherwise you can set one up here: https://chat.stackexchange.com/?tab=site&sort=active&nohide=true&host=gis.stackexchange.com I've been in one before but for the love of me I can't find where it went to. – she_weeds Jan 09 '24 at 09:23
  • https://chat.stackexchange.com/rooms/150758/qfield-and-qgis-tree-surveys this might work. – Sethinacan Jan 09 '24 at 10:29

0 Answers0