I have a polygon shapefile and a (merged) line shapefile (both are zipped). When I use Vector -> Analysis Tools -> Sum Line Lengths on these shapefiles, I get a layer with some of the LENGTHS filled with numeric values. However, a significant portion of the LENGTHS are now 'nan', even when the COUNT is a non-zero value.

Here are a few possible explanations, but I'm not sure which one is correct:

  1. Error with the shapefiles.
  2. Shapefiles are too big.
  3. The data type of the LENGTH field is inappropriate.
  4. I need to unzip them.

I've tried doing the same with a few of the unmerged line shapefiles and this problem still seems to occur.

  • Quick thought - have you checked for any null geometry in your files (and then eliminate any such features)? – MappaGnosis Oct 20 '18 at 9:35

I was having this same problem recently and it turns out that some of my lines had vertices that were too close together. I did not empirically confirm this, but I believe that these segments were too short to be considered as valid given the geoprocessing coordinate precision.

The solution which worked for me was to run Vector Geometry > Simplify with a very low precision (in my case, 0.1). This deleted the invalid segments and had an imperceptible effect on all other lines. After that, I had no more nan values when calculating lengths.

  • You might want to make it even more lower than make it 0,000001. I did mine at 0.1 and I got a 0.50 difference in meters between an Autocad Calculation and the QGIS calculation. This can stack up if you have multiple that have to be simplified, so the lower the better. Now it got me an 0.01 difference, that is way better compared to 0.50. – ThunderSpark Mar 1 at 15:06

I was having the same problem and I tried the solution suggested by wfgeo (Vector Geometry > Simplify), but it didn't work for me.

So I used Clip to clip the road layer with the option "itearte over the polygon layer", the green arrow (one layer for each feature of the polygon layer) and then I merged all the results into one line layer. With the field calculator I found the length of all the single lines and then I summarized on the basis of the polygon layer field.

Some features of the clipped road layer, had the result equal to "-2147483648". This happened when the feature line completely shared the perimeter of a polygon layer feature. I checked the "Sum Line Lengths" result and the "nan" problem occurred exactly for the feature that shared the perimeter with a feature of the line layer.

I think that's why simplify works in some cases.

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.