QGIS: add polygon by inputting coordinates

2 min read 07-10-2024
QGIS: add polygon by inputting coordinates


Adding Polygons to Your QGIS Project with Coordinates: A Simple Guide

Creating polygons in QGIS can be done in various ways, including digitizing directly on the map. However, if you have a set of coordinates representing your desired polygon, you might find yourself wondering: How can I create a polygon by simply inputting the coordinates? This guide will walk you through the process, making it easy to import your data and visualize your polygons in QGIS.

The Problem: Directly inputting coordinates for polygons

While QGIS offers tools for drawing polygons, directly inputting coordinates is not a built-in feature. However, with a bit of creative problem-solving, we can achieve this using the powerful features of QGIS.

The Solution: Leveraging QGIS's Data Import Capabilities

Here's a straightforward method to add polygons to your QGIS project using coordinates:

1. Prepare your Coordinates:

  • Organize your coordinates in a spreadsheet or text file. Each row should represent a point on the polygon, with columns for longitude and latitude (or X and Y coordinates).
  • Make sure the coordinates are in the correct format, such as decimal degrees (e.g., -74.0059, 40.7128).

2. Create a New Shapefile:

  • In QGIS, go to "Layer" > "Create Layer" > "New Shapefile Layer".
  • Choose "Polygon" as the geometry type and select your desired coordinate reference system (CRS).
  • Click "OK" to create the empty shapefile.

3. Import Your Coordinates:

  • Open the newly created shapefile in the attribute table.
  • Right-click on the header of the column where you want to import your coordinates and select "Paste".
  • Paste the coordinates from your spreadsheet or text file. Ensure that each row corresponds to a point in your polygon and the order of the points matters for polygon formation.

4. Convert Coordinates to Geometry:

  • Open the QGIS processing toolbox (Processing > Toolbox).
  • Search for "Create geometries from attribute values" and select it.
  • Choose your shapefile as the input layer and select the columns containing your coordinates.
  • Set the geometry type to "Polygon" and click "Run".

5. Verify and Adjust:

  • View your newly created polygon layer. You should now see your polygon visualized on the map.
  • Check for any errors or inconsistencies. If needed, adjust your coordinates or edit the polygon using QGIS's editing tools.

Example: Adding a Square Polygon

Let's illustrate with an example. Suppose you have the following coordinates for a square polygon:

Longitude Latitude
-74.0059 40.7128
-74.0059 40.7138
-74.0159 40.7138
-74.0159 40.7128
-74.0059 40.7128

You would follow the steps mentioned above to import these coordinates into a new shapefile and then use the "Create geometries from attribute values" tool to convert them into a polygon.

Additional Insights:

  • CRS Consistency: Ensure that the CRS of your coordinates matches the CRS of your QGIS project to avoid distortion.
  • Closing the Polygon: Remember that the last coordinate should be the same as the first, closing the polygon.
  • Multiple Polygons: If you have multiple sets of coordinates representing different polygons, you can repeat the process for each set.

Conclusion:

By following these simple steps, you can seamlessly add polygons to your QGIS projects based on your own coordinates. This method empowers you to visualize data from various sources and analyze them effectively within QGIS.

Further Resources: