2

Field Calculator: using the x- or yat or (0 "or-1" ) expression, I keep receiving an error:

An error occurred while evaluating the calculation string: Index is out of range.

I have shut down and restarted a few times, sometimes the error does not return.

Why is this happening and what can I do to fix it?

  • What version of QGIS are you using? Does this happen to all datasets or just a single table? – Jakob Jan 29 '14 at 12:18
  • Are you using the function on line features? – underdark Jan 29 '14 at 19:46
  • Hi. That is an affirmative, Underdark. I am using it on a line vector dataset. It has been working fine for a while now, even on larger datasets, but tried a few smaller sets yesterday and i kept getting this result. Dont know if this is also related, but if I edited these same data sets, editing meaning using the merge and cut tools, i would get errors or attribute records for non-existent lines. – VeM Jan 30 '14 at 7:46
2

This could be the solution to your issue.
My line dataset had lines dissolved by an attribute, so that two (or more) lines in separate locations were merged (the dissolve command has an option for this or the merge command may have been used) to a single record of the attribute table.

Dissolve

Merge record

Merge Command

vertexedit

When editing the vertices of such a record you can see the multiparts.

Multipart

When you define the starting vertex (xat(0), yat(0)) of the line there are actually two. I think that this is where the error originates from.

A way to avoid this is to use the 'Explode lines' tool from the processing toolbox (from the "Processing" plugin) or the explode tool from the edit toolbar.
Edit Toolbar
This will create a new record in your attribute table for every line segment meaning there is only one start and end vertex for each record. I used this on my line dataset and the x- or yat or (0 "or-1" ) expressions worked without error.

After your calculations you can dissolve your lines again using any of the dissolve functions from the processing toolbox.

  • 1
    wasn't the question about QGIS? – MrXsquared Jul 7 at 20:56

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.