0

From an answer in the below question, I can generate a polygon around a LineString input to generate an Atlas. The polygon represents the Atlas view area, given the map's scale, width and height.

Creating an overview polygon from a Atlas Print Layout map extent in canvas?

I am trying to expand on this and rotate the polygon to match the map rotation in print composer. The map rotation is defined as:

90-"Rotation"

where "Rotation" is an attribute in the LineString.

--layout map scale
with_variable('print_scale',1000,(
--layout map height
with_variable('H_map',606.787,(
--layout map width
with_variable('W_map',964.142,(
with_variable('ex', centroid(bounds($geometry)),(
with_variable('H_coverage',((@H_map*0.0005)*@print_scale),(
with_variable('W_coverage',((@W_map*0.0005)*@print_scale),(

    rotate(
        (geom_from_wkt( 'POLYGON(('|| 
            (x(@ex) + @W_coverage)||' '||(y(@ex) + @H_coverage)||','||
            (x(@ex) + @W_coverage)||' '||(y(@ex) - @H_coverage)||','||
            (x(@ex) - @W_coverage)||' '||(y(@ex) - @H_coverage)||','||
            (x(@ex) - @W_coverage)||' '||(y(@ex) + @H_coverage)||','||
            (x(@ex) + @W_coverage)||' '||(y(@ex) + @H_coverage)||'))')
        ),
    -1*(90-"Rotation"),center:=centroid($geometry), per_part:=False
    )
))))))))))))

The problem I'm facing is the rotation offsets the polygon slightly (see red box in below image). In theory, when the polygon is displayed in print composer it shouldn't be visible. It appears to work when there is no rotation.

I suspect it could be due to the centre of rotation? In addition to the above I have tried not defining the centre point leaving it as default (NULL) and used the x(@ex) and y(@ex) to define the centre. This sets it further off. Does anyone have any ideas?

enter image description here

1 Answer 1

0

I appear to have solved it by rotating the line first and using the centre point of the bounding box of the rotated line to:

a) calculate the vertices of the polygon b) provide a centre point of rotation for the polygon

--rotate line
with_variable('rotated_line', 
    rotate(
        $geometry,
        (90-"Heading"),
        center:=centroid(bounds($geometry))
        ),(
--layout map scale
with_variable('print_scale',1000,(
--layout map height
with_variable('H_map',606.787,(
--layout map width
with_variable('W_map',964.142,(
--center point
with_variable('ex', centroid(bounds(@rotated_line)),(
--height/width offsets from center
with_variable('H_coverage',((@H_map*0.0005)*@print_scale),(
with_variable('W_coverage',((@W_map*0.0005)*@print_scale),(
--calculation
    --rotate polygon
    rotate(
        --define polygon with coordinates of map extent
        (geom_from_wkt( 'POLYGON(('|| 
            (x(@ex) + @W_coverage)||' '||(y(@ex) + @H_coverage)||','||
            (x(@ex) + @W_coverage)||' '||(y(@ex) - @H_coverage)||','||
            (x(@ex) - @W_coverage)||' '||(y(@ex) - @H_coverage)||','||
            (x(@ex) - @W_coverage)||' '||(y(@ex) + @H_coverage)||','||
            (x(@ex) + @W_coverage)||' '||(y(@ex) + @H_coverage)||'))')
        ),
        -1*(90-"Rotation"),
        center:=centroid(bounds(@rotated_line))
    )
))))))))))))))

Your Answer

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

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