biglimp / PhDCourseVT2021

This repo include teaching materials for the PhD-course "Automate your GIS - Scripting in Python" (NGEO306)
7 stars 1 forks source link

Need help with this code shown below #1

Open Pramods11 opened 3 years ago

Pramods11 commented 3 years ago

Some problem with this code shown below ( it doesn't shows any kind of error in QGIS python console but it is not responding) , When I tried to run it in Visual code it shows error " Exception has occurred: ModuleNotFoundError No module named 'qgis' File "C:\Users\xsurpr\Desktop\WEIBULL\Hojddatapython.py", line 3, in from qgis.core import QgsRasterLayer, QgsApplication "

code :

from qgis.core import QgsRasterLayer, QgsApplication from osgeo import gdal

import numpy as np

starting a QGIS application

qgishome = 'C:/OSGeo4W64/apps/qgis' app = QgsApplication ([], True) QgsApplication.setPrefixPath(qgishome, True) QgsApplication.initQgis()

Loading raster layer

Name = 'C:/temp3/bergyta_hojd_50x50m.tif' bigraster = gdal.Open(Name)

band1 = bigraster.GetRasterBand(1).ReadAsArray() print = (band1)

Thanks in advance

biglimp commented 3 years ago

Did you open VSCode using your .bat-file?

Pramods11 commented 3 years ago

Yes, I saved those codes in .bat and tried to open the file but it shows like don't have an extension for debugging Batch

biglimp commented 3 years ago

No, you cannot debugg a batch file, only Python files with the setup we make use of. The code you have should be saved in a .py file and runned (or debugged) inside VSCode. Try again and let me know if you still have issues.

Pramods11 commented 3 years ago

Not showing any error now on Vscode but when I tried to do it in a pyhton console within QGIS I got something like attached below :

Crash ID: 35b66b519dd8360a1ef8949e7f0bb2e422bc1a7e

Stack Trace

QMutex::lock : QNetworkConfigurationManagerPrivate::enablePolling : QNetworkConfigurationManager::QNetworkConfigurationManager : QNetworkAccessManager::QNetworkAccessManager : QNetworkAccessManager::QNetworkAccessManager : QgsNetworkAccessManager::QgsNetworkAccessManager qgsnetworkaccessmanager.cpp:139 QgsNetworkAccessManager::instance qgsnetworkaccessmanager.cpp:124 meth_QgsApplication_initQgis sip_corepart10.cpp:147392 PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyEval_EvalCodeEx : PyEval_EvalCode : PyArena_Free : PyRun_StringFlags : PyImport_Import : PyImport_Import : PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyImport_Import : PyImport_Import : PyMethodDef_RawFastCallKeywords : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyEval_EvalCodeWithName : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyMethodDef_RawFastCallKeywords : PyEval_EvalFrameDefault : PyFunction_FastCallDict : PyMethodDef_RawFastCallDict : PyObject_Call : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : PyInit_QtCore : QMetaObject::activate : QAction::activate : QAbstractButton::click : QAbstractButton::mouseReleaseEvent : QToolButton::mouseReleaseEvent : QWidget::event : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify qgsapplication.cpp:475 sipQgsApplication::notify sip_corepart10.cpp:144549 QCoreApplication::notifyInternal2 : QApplicationPrivate::sendMouseEvent : QSizePolicy::QSizePolicy : QSizePolicy::QSizePolicy : QApplicationPrivate::notify_helper : QApplication::notify : QgsApplication::notify qgsapplication.cpp:475 sipQgsApplication::notify sip_corepart10.cpp:144549 QCoreApplication::notifyInternal2 : QGuiApplicationPrivate::processMouseEvent : QWindowSystemInterface::sendWindowSystemEvents : QEventDispatcherWin32::processEvents : UserCallWinProcCheckWow : DispatchMessageWorker : QEventDispatcherWin32::processEvents : qt_plugin_query_metadata : QEventLoop::exec : QCoreApplication::exec : main main.cpp:1638 BaseThreadInitThunk : RtlUserThreadStart :

Not loading anything on QGIS . Can you help me with this ?

biglimp commented 3 years ago

@nilswallenberg , can you help Pramod. I have a meeting.