2

I have a CSV file with bbox extents in xmin, ymin, xmax, ymax format. I can import these as pairs of delimited text layers and see the diagonal extents of these boxes on my map document.

Can I take that one step further and turn them into boxes? Each xmin,ymin and xmax, ymax pair have a unique "ID" so they can be matched.

3

3 Answers 3

3

You can run geometry by expression from processing toolbox. Choose "polygon" as output and use this expression:

make_polygon(
make_line(
make_point("xmin","ymax"), -- upper left
make_point("xmax","ymax"), -- upper right
make_point("xmax","ymin"), -- lower right
make_point("xmin","ymin"), -- lower left
make_point("xmin","ymax") -- upper left (closing point)
)
)
2

Let's assume there is a CSV file called 'test' with its content, see image below.

input

Step 1. Drag&drop your CSV into QGIS, so it is viewable in the Layers Panel

step_1

Step 2. Create a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

With the following query, it is possible to turn the extents in xmin, ymin, xmax, ymax into boxes.

SELECT "id", "name",
        make_polygon(
            make_line(
                make_point("xmin","ymax"),
                make_point("xmax","ymax"),
                make_point("xmax","ymin"),
                make_point("xmin","ymin")
                )
            ) AS geom
FROM "test"

and get the desired output:

result

2

Simply add the csv-layer and create a bounding box with either Geometry generator or Geometry by expression (see here for details) using the function bounds with this expression:

bounds (collect ($geometry, group_by:=id))

The result using Geometry generator: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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