This simple script retrieving a value of raster pixel size works in Python console, but can't be processed in Script editor: "No script found. Seems there is no valid script in the file." How could it be solved?
from qgis.core import QgsRasterLayer
ras = QgsRasterLayer(r"C:\Users123円123円.tif")
pixelsizeX = ras.rasterUnitsPerPixelX()
pixelsizeY = ras.rasterUnitsPerPixelY()
print (pixelsizeX)
print (pixelsizeY)
-
Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site worksIan Turton– Ian Turton2023年10月03日 10:04:00 +00:00Commented Oct 3, 2023 at 10:04
-
This is not a valid processing script. Start your learning journey here. And pay attention to the tip hereBen W– Ben W2023年10月03日 10:32:48 +00:00Commented Oct 3, 2023 at 10:32
-
Also check out: qgistutorials.com/en/docs/3/processing_python_scripts.html and: anitagraser.com/…Ben W– Ben W2023年10月03日 10:39:09 +00:00Commented Oct 3, 2023 at 10:39
1 Answer 1
That may be a valid pyqgis script, but it's not a valid processing script. You can run it from the console script editor, not the processing script editor.
answered Oct 3, 2023 at 11:53
-
To add to this: Scripts in the console editor can be opened in a different editor (which makes it easier to see everything imo) with the "Open in External Editor" button. This editor can be set in "Settings - Options - System - Environment". So far I've only tested it with PyCharm and changes are synched pretty much instantly between them when you save the file.Neph– Neph2025年09月04日 14:13:55 +00:00Commented Sep 4 at 14:13
lang-py