Coder Social home page Coder Social logo

biglimp / phdcoursevt2021 Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 1.0 55.07 MB

This repo include teaching materials for the PhD-course "Automate your GIS - Scripting in Python" (NGEO306)

Batchfile 2.65% Python 25.98% Makefile 7.25% CSS 12.58% JavaScript 43.59% HTML 5.67% Shell 1.39% QML 0.89%

phdcoursevt2021's People

Contributors

biglimp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

karlstefanrehn

phdcoursevt2021's Issues

Need help with this code shown below

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

Struggling with a loop

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!

Accessing unique attributes from vector layer and showing unique values in a scroll bar QGIS-Plugin

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?

image

Help with nested loop

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())

check attributes in vector layers

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()]

we check if we can add an attribute to the layer

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')

calculate area of polygons

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.