biglimp / phdcoursevt2021 Goto Github PK
View Code? Open in Web Editor NEWThis repo include teaching materials for the PhD-course "Automate your GIS - Scripting in Python" (NGEO306)
This repo include teaching materials for the PhD-course "Automate your GIS - Scripting in Python" (NGEO306)
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
qgishome = 'C:/OSGeo4W64/apps/qgis'
app = QgsApplication ([], True)
QgsApplication.setPrefixPath(qgishome, True)
QgsApplication.initQgis()
Name = 'C:/temp3/bergyta_hojd_50x50m.tif'
bigraster = gdal.Open(Name)
band1 = bigraster.GetRasterBand(1).ReadAsArray()
print = (band1)
Thanks in advance
I've managed to write a working loop that (I think) calculates the distance between each vector point of one layer val_lokaler
and each vector point of another layer centroids
.
for x in val_lokaler.getFeatures():
x_geom = x.geometry()
for y in centroids.getFeatures():
y_geom = y.geometry()
dist_m = y_geom.distance(x_geom)
print(x.id(), y.id(), dist_m)
However, what I want to do is calculate the distance between each point in val_lokaler
and one specific point in centroids
. The point it should calculate the distance from shares a common field and value in both layers (VALDISTRIK = e.g. 1234). I think I only need one loop for this (not the nested loop) but I can't figure out how to access the corresponding points in the centroid
layer.
Thanks for your help!
Hello (unsure which language to use, but someone else may be interested I dont know)
I am struggling with how to make get unique attribues from a selected field from a vector layer into a scroll list
So in the box called Class: in the picture below i would like to be able to select fields from the selected attributes
# Reharvested code from UAVPrepare
self.layerComboManagerPoint = QgsMapLayerComboBox(self.dlg.comboBoxVector)
self.layerComboManagerPoint.setCurrentIndex(-1)
self.layerComboManagerPoint.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.layerComboManagerPoint.setFixedWidth(175)
self.layerComboManagerPointField = QgsFieldComboBox(self.dlg.comboBoxField)
self.layerComboManagerPointField.setFilters(QgsFieldProxyModel.AllTypes) # All types?
self.layerComboManagerPoint.layerChanged.connect(self.layerComboManagerPointField.setLayer)
# Somewhere here I am looking for like
self.layerComboManagerPointFieldAttribute = QgsFieldComboBox(self.dlg.comboBoxAttribute)
self.layerComboManagerPointFieldAttribute.setFilters(QgsFieldProxyModel.AllTypes)
self.layerComboManagerPointFieldAttribute.layerChanged.connect(
self.layerComboManagerPointFieldAttribute.setATTRIBUTE(??)) # here i just wrote something
I might be missing an important step, do you have any tips on google-words or code too search for?
Hi..
Finally I could managed to calculate the area of my polygons ( I had to fix geometries but finally it runs kakaka) for one of the months of my data but now I would like to run the script for other months and plot the graphs with differences. But I am bit confusing of how can I do it. The data as same format (.shp files).
#Loading a vector layer
vlayer = QgsVectorLayer ('c:/Cossa/Thesis_Data/FixedJulyScars_2020.shp', 'FixedJulyScars_2020','ogr')
print(vlayer.isValid())
vlayer2 = QgsVectorLayer ('c:/Cossa/Thesis_Data/DugongScars_Aug20.shp', 'DugongScars_Aug20','ogr')
print(vlayer2.isValid())
for features in vlayer.getFeatures():
attrs = features.attributes()
print(attrs[0])
for features in vlayer2.getFeatures():
attrs = features.attributes()
print(attrs[0])
geom = features.geometry()
if geom.isMultipart() :
print (vlayer.name(), ': Warning: Multipart', features. id())
print (vlayer2.name(), ': Warning: Multipart', features. id())
#vlayer = iface.activeLayer()
caps = vlayer.dataProvider().capabilities()
fields_name = [f.name() for f in vlayer.fields()]
if caps & QgsVectorDataProvider.AddAttributes:
if 'Area' not in fields_name:
vlayer.dataProvider().addAttributes ( [ QgsField ('Area',QVariant.Double) ] )
vlayer.updateFields()
fields_name = [f. name() for f in vlayer.fields()]
fareaidx = fields_name.index ('Area')
if caps & QgsVectorDataProvider.ChangeAttributeValues:
for gFeat in vlayer.getFeatures():
d = QgsDistanceArea()
d.setSourceCrs(vlayer.crs(), QgsProject.instance().transformContext())
d.setEllipsoid (QgsProject.instance().ellipsoid())
for features in vlayer.getFeatures():
geom = features.geometry()
area = [0]
landArea = gFeat ['Area']
if geom.isMultipart():
polyg = geom.asMultiPolygon()
for polyg in polyg:
area = d.measurePolygon(polyg[0])
landArea = area
print(landArea)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.