[GIS] Add rectangle polygon

polygonqgisvector

I have a polygon shapefile layer. I want to add a rectangle polygon (just like in Arcmap), and another one using the previous polygon edge. I need it to be accurate, my hands do not meet this condition.

Maybe this draw will explain better:

rectangle polygon

Best Answer

I think the easiest way to do this is to construct the rectangles by number, rather than manually. I know two ways to do this:

  1. QuickWKT plugin
  2. Vector grid

QuickWKT

This plugin allows you to create geometries using Well-Known Text. You enter the vertices as XY coordinates, and make sure the last vertex is the same as the first vertex so that the polygon closes correctly. An example of two squares that are exactly next to each other:

POLYGON ((10 10, 10 20, 20 20, 20 10, 10 10))
POLYGON ((20 10, 20 20, 30 20, 30 10, 20 10))

Enter each geometry on its own line in the QuickWKT text box, and make sure to check the "Create new layer for every geometry type checkbox". I don't know what that name is supposed to imply, but if you don't check it, each polygon will in a separate layer, and if you do check it, they will be in the same layer (which I assume is what you want).

enter image description here

When you hit OK, you will be prompted for the desired SRID. The best approach is to set the project SRID, use the mouse to find the coordinates of the desired vertices, then when you run QuickWKT, choose the same SRID as your project.

The new layer exists only in memory, so right click on the layer in the Layers pane and choose Save As, to save it to a shapefile or your desired format.

Vector grid tool

Go to Vector→Research Tools→Vector grid. Set the minimum X and Y values and the maximum X and Y values for the whole layer (i.e. both polygons). The oddly named "Parameters" are the X and Y resolution (i.e. width and height of each polygon in the grid) and make sure to pick "Output grid as polygons" (otherwise you will end up with a fishnet of lines).

It appears that if the resolution exactly matches the min/max parameters, the tool will create one more polygon than desired. But if you reduce the max - min distance to less than the resolution, the maximum trumps the minimum dimension. You can play around with that, or just create more than necessary and use edit tools to delete the extra polygons.

There is a similar tool as part of the MMQGIS plugin (MMQGIS→Create→Create Grid Layer) which also lets you create diamond and hexagon grids.

A disadvantage of this tool is that the polygons can only be orthogonal to the coordinate system. Selecting between them, I would probably choose as follows:

  1. For just two or three polygons, I would use QuickWKT.
  2. For more polygons, I would use the Vector grid tool so as to avoid having to enter so many coordinates manually.
  3. If the polygons are not orthogonal to the coordinate system, and I had to do more than two or three, I would construct the WKT programmatically, then paste it into the QuickWKT tool.

Hope this helps.

Related Question