A word of warning - there's no documentation nor anything particularly useful below, just my angry rants against someone else's coding style, culture or ecosystem or whatever you may call it.
Judging by the number of "reads" (5) on the blog that nobody visits except robots, I figured out that using the phrase "pyqgis features" for the title was rather stupid, since it's now most likely seen as two search keywords. Sorry, that was not my intention, even though I should have been able to figure it out, recently having finished some code that makes use of the QgsFeature object, among others. All I had in mind was something along the lines of "it's not a bug, it's a feature" ...
I get a lot of fun doing some voluntary work in the python/qgis world, just to help someone I like a lot - for the two magic words - "thank you". Helps me become a human being again. Not the too well known piece of a sociopath with empty eyes and no soul, paranoid psychotic heart of stone, my blood runs cold ...
So now goes my small donation for QGIS. Didn't mean anything bad, guyesses and guys and persons etc. - it's just me being a beginner, somewhat awkward and retarded.
---
Let ust seeth:
virtualLayer = QgsVectorLayer(
path = fileName,
baseName = 'New CSV',
providerLib = 'delimtedtext'
)
assert virtualLayer.isValid()
Note the "i" lacking from providerLib's value.
And all I get is isValid() == False. Same with a non-existent file.
PyQgis is nice, but from time to time just too fucking obscure. Looks as if it's so bad
w.r.t. python as python is, related to any decent language. Struggle, push your abilities to
the limit ...
Another pitfall: trying to add a fixed input file to a "processing tool", sitting in the scripts
directory. Hidden from the user, which may be ok - requiring them to choose the file from the
qgis' scripts directory seems like too much nonsense labour.
Nb. - the tool doesn't even permit logging to a file, disregards exception throwing etc.,
tries its best on any data whatsoever and giving rather poor information on what went
wrong. Anyways, after fiddling around with absolute paths, all I got was some strange
file not found error, showing my file name with extension removed and glued together
with some GUID-like bunch of numbers and dashes or underscores. Shit! Ok, why not try
p = Path.cwd() / 'some_file_name.csv'
path = p.resolve()
self.SecretInput = path.split('_')[0:3] + '.csv'
so as to cut out the GUID and give the correct file path to the "INPUT" part of the run call?
Guess what - the GUID is still there in the error message! Oh my.
Seems, according to wizards, that something like
class FixedCsvPath:
def Get() -> str:
return os.path.dirname(os.path.realpath(__file__)) + '/some_file_name.csv'
and calling FixedCsvPath.Get() in place of 'INPUT' : ... does the trick. Perhaps the same stuff
called explicitly gives the same result, but let's just follow the good book on b.s. like "separation
of concerns" etc. The code is dirty enough already.
No comments:
Post a Comment