5

When it comes to 'Add polygon feature', if it is possible to make a polygon square so that user can input length(s) of the sides, then how do I do that?

4 Answers 4

6

Here's a way to do it without any digitizing or coding. I used 3.18.1:

  1. Start with a point layer. Below, I have a layer containing three points, located within Washington state, USA. The CRS is EPSG:2927.

enter image description here

  1. Buffer the points by one-half of the desired square side length. In my example, I want my final square polygons to be 40 miles on a side, so I set the buffer width to 20 miles.

enter image description here

  1. Run the tool Processing > Toolbox > Vector General > Bounding Boxes, where the input layer is the buffer polygon from step 2:

enter image description here

Voila! The resulting squares have the desired 40-mile dimension. If desired, the squares can be rotated with the Processing > Toolbox > Vector Geometry > Rotate tool.

6

Check "Rectangles, Ovals, Diamonds (Variable)" geoalgorithm in the QGIS's Toolbox, where user need to put equal width and height for a square, see image below

result

Mind that a point layer has to be created in advance. Those points will, later on, serve as square's geocentroid.

1
5

There are at least two options:

  1. Use Advanced Digitizing Toolbar, see documentation, so I will not insist on this.
  2. Use QGIS expressions - what the following explanations will be about.

Use QGIS expressions to either create the square dynamically, but only for visualization purpose using Geometry generator or create actual geometries with Menu Processing / Toolbox / Geometry by expression. In both cases, you can use the same expression (see below).

Drawing a line will automatically add a square in the pre-defined size. See animation how to do it: Draw line / add symbol layer: Geometry generator: polygon / paste expression / change size: enter image description here

The solution consists of two steps:

  1. Create a line layer and draw a line. Click once for the first point: this will be the starting edge of your square. Click a second time to create the line: it's direction (not it's length) will define the orientation (azimuth, angle, rotation) of your square. You're done with the line, toggle edit mode.

  2. Now use the following expression with geometry generator or geometry by espression as stated before: it will create a square on the right side of your line, starting on the first point you clicked, using the line for one side of the square and with a length that you can define in third line of the expression - in my case: 5000. Change this accordingly:

with_variable (
    'side',
    5000,
    make_square( 
         project (
            project (
                start_point ($geometry),
                @side,
                azimuth(
                    start_point ($geometry), 
                    end_point($geometry)
                )
            )
            , 
            @side,
            azimuth (
                end_point($geometry), 
                start_point ($geometry)
            )-radians (90))
        ,
        start_point ($geometry)
    )
)

Screenshot: see the version with geometry generator: the red dot is the starting point of the black line. The orange polygon is the square created by the expression. Note that the length of the line does not play any role, it's just for the rotation:

enter image description here

3

I am not sure it helps to you but I hope.

enter image description here

Your Answer

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

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