QGIS – How to Fix $area Field Calculator Producing NULL

qgis

Error occurs under Windows in QGIS 2.8.3 and 2.10.1, answers to similar questions e.g. 57418 have not helped.

The shapefile in question was created as follows:

  1. Vector/GPS/GPS tools/Load GPX file (Routes)
  2. Layer / save as ESRI shapefile [….\epsg4326\routes.shp]

The failing sequence is:

  • Start a new map/add vector layer [routes.shp]
  • Open attribute table
  • Add new column AREA [decimal real width=17 precision=8]
  • Manually edit both AREA values to verify format.
  • Select all entries [2 entries]
  • Field calculator / existing /AREA / geometry / $area

Always get NULL

I have tried countless combinations of width and precision for AREA. I have uninstalled/reinstalled/installed different releases. All to no avail.

What's up Doc?

Beginning to smell a rat in the direction of either the GPS tool or the shapefile. Starting with the shapefile, how may I independently verify it?

Best Answer

There are two things you get wrong:

  1. GPX data is always in EPSG:4326 latlong degrees. If you want measurements in meters, you have to reproject the data to your local UTM zone. Use Save As ..., not Set Layer CRS for that.
  2. GPX only knows about points and lines. If you want polygons, you have to close the line. If you have any self-intersection within your track, you will not get a valid polygon. So you have to sanitize your data first if you want to get a polygon out of GPS data.

A closed way is not automatically a polygon. In QGIS, you can use Vector -> Geometry Tools -> Lines to Polygons to create a polygon layer from the data. If you still get no result, try Vector -> Geometry Tools -> Check Geometry Vailidity.

Self-intersection means that the line crosses itself somewhere (not necessarily at the ends). GPS data is prone for that, if you stand still, and the unit is improving its reception quality.

Related Question