6

I have a CSV file with the coordinates of the vertices of my polygons (in the picture they correspond to "left", "right", "top", "bottom"). Actually is a grid of polygons. How can I import the file in QGIS as polygons and not as points?

enter image description here

4

I'm assuming you want the rectangles with diagonal (left,top) and (right,bottom) as the required polygons.

You could import the CSV as points, say x=left, y=top, and then use processing (or even expressions) which access right and bottom as attributes and transform to the desired rectangles.

However, it will be faster to preprocess within Excel (or whatever your spreadsheet program is) by combining the attributes into a WKT Polygon string, which unambiguously specifies the polygons in a standard format.

In cell G2 (or row 2 of a new column if G is used), put ="POLYGON(("&B2&" "&C2&", "&D2&" "&C2&", "&D2&" "&E2&", "&B2&" "&E2&", "&B2&" "&C2&"))" and copy it down. It generates a polygon WKT string that goes around the points clockwise. You can then import the CSV taking the geometry from this column and QGIS will interpret it as a polygon (rectangle) for each line.

6

You can do it with expressions, even loading your excel file, without converting to .csv, load your excel file as if it was a vectorial layer

On the process toolbox > vector geometry > geometry by expression. enter image description here

enter image description here

The expression, although it looks a little long, is simply to write a wkt polygon using the fields, then you convert it to geometry. enter image description here

Simply run this expression

 geom_from_wkt( concat('POLYGON((',to_string("left")+' '+to_string("top")+',',to_string("right")+' '+to_string("top")+', ', to_string("right")+' '+to_string("bottom")+',', to_string("left")+' '+to_string("bottom"),'))

You will get a result like this:

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.