IndexError: list index out of range-QGIS - python

I Try to make plugin in qgis and I have a problem. Below is my code:
destination_layer = QgsProject.instance().mapLayersByName('Destination')[0]
matrix = QgsProject.instance().mapLayersByName('join')[0]
for f in matrix.getFeatures():
origin_expr = QgsExpression('Site Name={}'.format(f['Site Name']))
destination_expr = QgsExpression('Site Name={}'.format(f['Site Name_2']))
origin_feature = origin_layer.getFeatures(QgsFeatureRequest(origin_expr))
origin_coords = [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in origin_feature]
destination_feature = destination_layer.getFeatures(QgsFeatureRequest(destination_expr))
destination_coords = [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in destination_feature]
params = {
'INPUT':'NCR Road',
'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),
'STRATEGY':0,
'ENTRY_COST_CALCULATION_METHOD':0,
'DIRECTION_FIELD':'',
'VALUE_FORWARD':'',
'VALUE_BACKWARD':'',
'VALUE_BOTH':'',
'DEFAULT_DIRECTION':2,
'SPEED_FIELD':'',
'DEFAULT_SPEED':50,
'TOLERANCE':0,
'OUTPUT': 'Shortest Path Layer' }
print('Executing analysis')
processing.runAndLoadResults("qneat3:shortestpathpointtopoint", params)
Then when I run my code, it show this error:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS32~1.0\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 16, in <module>
IndexError: list index out of range
Why it is not working in plugin?

We need more information like which code is on line 90? Anyway I would double check and making sure your index is doing correct things
'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),
And
destination_layer = QgsProject.instance().mapLayersByName('Destination')[0]
matrix = QgsProject.instance().mapLayersByName('join')[0]

Related

Problems when I run ML-GCN

'''
PS D:\ML-GCN\ML-GCN-master> python demo_voc2007_gcn.py data/voc --image-size 448 --batch-size 1 -e --resume checkpoint/voc/voc_checkpoint.pth.tar
[dataset] read data/voc\data\data\data\voc\data\voc\files\VOC2007\classification_trainval.csv
Traceback (most recent call last):
File "D:\ML-GCN\ML-GCN-master\demo_voc2007_gcn.py", line 75, in <module>
main_voc2007()
File "D:\ML-GCN\ML-GCN-master\demo_voc2007_gcn.py", line 44, in main_voc2007
train_dataset = Voc2007Classification(args.data, 'trainval', inp_name='data/voc/voc_glove_word2vec.pkl')
train_dataset = Voc2007Classification(args.data, 'trainval', inp_name='data/voc/voc_glove_word2vec.pkl')
File "D:\ML-GCN\ML-GCN-master\voc.py", line 242, in __init__
self.images = read_object_labels_csv(file_csv)
File "D:\ML-GCN\ML-GCN-master\voc.py", line 95, in read_object_labels_csv
name = row[0]
IndexError: list index out of range
'''
The problem encountered when running ML-GCN, why does the problem of list index out of range appear, and how can I solve it

KeyError with custom derived quantity

I have defined a new derived dimension with
[molar_energy] = [energy] / [substance]
However, if I do the following it complains:
>>> UR.get_compatible_units('[molar_energy]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 881, in get_compatible_units
equiv = self._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 2082, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 1835, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 891, in _get_compatible_units
return self._cache.dimensional_equivalents[src_dim]
KeyError: <UnitsContainer({'[length]': 2, '[mass]': 1, '[substance]': -1, '[time]': -2})
I saw that there is a conversion included in a context but I don't use it. What I am doing wrong?
Thanks for your help
PS: logged issue https://github.com/hgrecco/pint/issues/1418
Just leaving the solution here for anyone who faces this issue as well.
I just added a made-up unit and it worked
# Molar Energy
[molar_energy] = [energy] / [substance]
mol_en = J / mol

Error while using mloginfo m-tools

I want to analyze log file of mongodb. I am referred to use m-tools. But I'm getting following error.
I've typed in terminal
mlonginfo /..logfilelocation../ --queries
Error:
QUERIES [============================== ] 74.1 % Traceback (most recent call last):
File "/usr/local/bin/mloginfo", line 9, in <module>
load_entry_point('mtools==1.1.8', 'console_scripts', 'mloginfo')()
File "/usr/local/lib/python2.7/dist-packages/mtools/mloginfo/mloginfo.py", line 82, in main
tool.run()
File "/usr/local/lib/python2.7/dist-packages/mtools/mloginfo/mloginfo.py", line 77, in run
section.run()
File "/usr/local/lib/python2.7/dist-packages/mtools/mloginfo/sections/query_section.py", line 51, in run
for i, le in enumerate(logfile):
File "/usr/local/lib/python2.7/dist-packages/mtools/util/logfile.py", line 208, in __iter__
le = self.next()
File "/usr/local/lib/python2.7/dist-packages/mtools/util/logfile.py", line 190, in next
ret = le.set_datetime_hint(self._datetime_format, self._datetime_nextpos, self.year_rollover)
File "/usr/local/lib/python2.7/dist-packages/mtools/util/logevent.py", line 246, in set_datetime_hint
if not self.split_tokens[self._datetime_nextpos-1][0].isdigit():
IndexError: list index out of range
Thanks in advance.

Can I use a field called size in a MongoEngine document?

I have a document:
class Hamburger(Document):
size = IntField(default=0, required=True)
which I can use fine
h = Hamburger()
h.size = 5
h.save()
until I try an update_one for example
Hamburger.objects().update_one(set__size=5)
which throws this exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 467, in update_one
upsert=upsert, multi=False, write_concern=write_concern, **update)
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 430, in update
update = transform.update(queryset._document, **update)
File "/usr/local/lib/python2.7/site-packages/mongoengine/queryset/transform.py", line 207, in update
field = cleaned_fields[-1]
IndexError: list index out of range
It is possible to have a Document with a field called size? Is there any way to achieve this?

wheezy template dictionary variable lookup

I have the following wheezy template:
#for i in pos:
#i[0] : #swi['x'] : #i[1]
#end
which for instance would output:
Z:val:x
yet, I would like to do something like:
#swi[#i[1]!s]
but it returns syntax error.
I need to lookup in swi using the current iteration data.
Traceback (most recent call last):
File "toto.py", line 53, in <module>
template = engine.get_template('x')
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/engine.py", line 41, in get_template
self.compile_template(name)
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/engine.py", line 89, in compile_template
source, name)['render']
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/compiler.py", line 26, in compile_source
source = adjust_source_lineno(source, name, self.source_lineno)
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/comp.py", line 21, in adjust_source_lineno
source = compile(source, name, 'exec', ast.PyCF_ONLY_AST)
File "x", line 7
w(' '); w(i[0]); w(' : '); w(swi[#i[1]]); w(' : '); w(i[1]); w('\n')
^
SyntaxError: invalid syntax
i've tried:
#swi[#i[1]!s]
#swi['#i[1]!s']
#swi[#i[1]]
#swi['#i[1]']
the answer is:
#swi[i[1]]
I'm not sure why the # is not allowed here...

Categories

Resources