Add Geometry Attributes (Length, Area, Perimeter) or X / Y Coordinates to Shapefiles in QGIS

Add Geometry Attributes (Length, Area, Perimeter) or X / Y Coordinates to Shapefiles in QGIS

Before adding geometry attributes (length, area, perimeter) to a line or polygon shapefile or X / Y Coordinates to a point shapefiles in QGIS, make sure the shapefiles are in reference to a projected coordinate system such as a UTM Zone, or a State Plane Coordinate System (Refer to this post for the differences between a projected coordinate system and a geographic coordinate system).

  1. To add X, Y coordinates to a point shapefile, select the point shapefile in the layers panel to make it current:
  • Click top menu of Vector, select Geometry Tools and then Add Geometry Attributes… (Figure 1). Type in a new point shapefile name, set “Calculate using” as Layer CRS, and click Run.
Figure 1
  • Open the attribute table of the newly created point shapefile (Figure 2) to verify that X, Y coordinates of each point in reference to the layer’s CRS have been added. In this demo, the CRS is EPSG 2278 (Texas State Plane Coordinate System, South Central Zone, Unit: Survey Foot), so the unit of X, Y coordinates is survey foot.
Figure 2
  1. To add length to a line shapefile or area & perimeter to a polygon shapefile, follow the same procedures of Step 1 above by clicking Vector –> Geometry Tools –> Add Geometry Attributes… (Figure 3 and Figure 4). In this demo, the CRS is EPSG 2278 (Texas State Plane Coordinate System, South Central Zone, Datum NAD83, Unit: Survey Foot), so the unit of length and perimeter is survey foot and the unit of area is square survey foot.
Figure 3
Figure 4
  1. Another way to add length, area, or perimeter to a shapefile attribute table is to use field calculator. Select a line or a polygon shapefile in the layers panel to make it current and then open the field calculator:
  • Check on Create a new field and provide a name for the output field name and field type – decimal number (real).
  • for length, type in or search the expression of $length (Figure 5); for area, type in or search the expression of $area, and for perimeter, type in or search the express of $perimeter.
  • Open the attribute table of (Figure 6 and Figure 7) to verify that the new geometry attributes have been added (field Length_2, Area_2, Perim_2).
Figure 5
Figure 6
Figure 7
  1. As shown in Figure 6 and Figure 7, when using field calculator to calculate length, area, or perimeter, the results are in reference to the unit of ellipsoids. In the demo, since EPSG 2278 is based on Datum of NAD83 and Ellipsoid GRS80 which has unit of meter, the results are in meter or square meter. Ellipsoid GRS80 unit of meter is different from the projected coordinate system of EPSG2278 which has unit of survey foot.
  1. The added geometry attributes are not dynamically linked to the features themselves. So if a feature is revised or edited, its geometry attributes will not be updated automatically and you will have to repeat the above steps to get new values.

Leave a Reply

Your email address will not be published. Required fields are marked *