Submind YouTube summaries
Thumbnail for Calculate Headwater Catchments with a QGIS Processing Script

Calculate Headwater Catchments with a QGIS Processing Script

Watch on YouTube

Video summary

Bu videoda QGIS İşleme Kutusu'na yeni bir araç eklenmesi ve bu aracın nasıl kullanılacağı gösterilmektedir. Sunulan çözüm, kullanıcıların stiller, projeler veya işleme betikleri gibi kaynakları paylaşabileceği "QGIS Kaynaklar Hubu" platformunda yer alan özel bir Python betiğidir. Bu tür betiklerin geliştirilmesi eklenti oluşturmaktan daha kolaydır ve PyQGIS yeteneklerini kullanan basit Python kodlaması gerektirir; ancak bu scriptin çalışması için PCRaster gibi ek paketlerin kurulu olması gerekir. Video boyunca, öncelikle Windows işletim sistemi üzerinde OSGeo4W yükleyicisi kullanılarak gerekli olan PCRaster araçları eklentisinin ve ardından QGIS Hub eklentisinin kurulduğu izlenmektedir. İşlem sürecinde, akış yönü haritasından başlanarak yerel drene yönlendirme map'i üzerinden birikim (flow accumulation) hesaplanır ve Strahler sıraları belirlenir. Scriptin temel mantığı, belirli bir ırmak sınıfına ait olan Strahler sıralarını seçmek, bu alanların birikimini hücre alanıyla çarpımından geçirmek ve ardından tanımlanmış maksimum boyutun altında kalan başkaynak havzalarını belirlemektir. Varsayılan olarak bu maksimum büyüklük 1 kilometrekare ayarlaştırılmıştır ancak kullanıcılar bunu değiştirerek farklı ölçeklerde analiz yapabilirler. Bu betik, doğrudan QGIS Kaynaklar Hubu üzerinden indirilip eklenebilir veya PCRaster Araçları Eklentisi aracılığıyla projeye entegre edilerek İşleme Kutusu'na anında eklenir. Araç çalıştırıldıktan sonra elde edilen raster çıktısı, her bir başkaynak havzasının sahip olduğu benzersiz sıfırdan farklı değerleri yansıtan renkli bir paletle stilize edilir ve ardından vektör çokgenlere dönüştürülerek daha detaylı analiz yapılmasına olanak tanınır. Bu dönüşüm sırasında projeksiyonun korunması kritik önem taşımaktadır, çünkü PCRaster araçları bazen projeksiyonu kaybedebilmektedir; bu durum alan hesaplamalarını imkansız hale getireceğinden, çıktı katmanının doğru bir şekilde projeye sahip olduğundan emin olunmalıdır. Son aşamada, sıfır değerleri temsil eden dış alan seçilerek silinir ve kalan çokgenlerin gerçek yüzey alanları metre kare cinsinden hesaplanıp milyonla bölünerek kilometrekareye çevrilir. Sonuç olarak, elde edilen havza alanlarının çoğunun varsayılan 1 kilometrekare hedefine yakın olduğu görülmekte olup, bazı küçük sapmaların rasterdan vektöre dönüşüm sırasında oluşan geometrik hatalardan kaynaklandığı tespit edilmiştir. Bu yöntem sayesinde kullanıcılar, belirli bir maksimum büyüklükteki başkaynak havzalarını hızlıca tanımlayıp haritalandırabilirler. Video sonunda izleyicilere QGIS işleme betikleri hakkında daha fazla bilgi edinmeleri ve kendi scriptlerini oluşturmaları için eğitim taleplerine açık olduğu belirtilerek süreç özetlenmiştir.
Read the full video transcript
[music] >> Hello. In today's video, I'm going to demonstrate a new tool that I've submitted to the resources hub of QGIS. The QGIS resources hub is a place where users can share styles, projects, models, 3D models, layer definition files, their nice maps, or processing scripts. Let's have a look. Creating a QGIS processing script is much easier than creating a plugin. It is a Python script that uses functionality of PyQGIS mixed with other Python code. You can submit your code here and then it will be reviewed. After acceptance, your tool will show up here and users can also read the code. In this case, I use PCRaster as an additional package. >> [gasps] >> And uh you can easily modify these scripts. I have courses where you can learn how to make these scripts. And the real magic happens uh here. So, after all the input is processed from the dialogue, I'm going to create here um the flow accumulation from the local drain direction map, the Strahler orders, and I'm going to select the orders that belong to the stream. And if there's a stream, I'm going to add the flow accumulation and multiply that with the cell area. And then with some threshold, I can determine the headwater maximum areas that I'm looking for. So, this script delineates the headwater catchments of a specified maximum size, and I've set the default of 1 square kilometer. You can, of course, download the script from the QGIS resources hub website, but it's much easier to use a plugin to add it directly to your project. But before I do that, I'm installing the PCRaster tools plugin, which is a dependency of the script. And remember that the PCRaster tools plugin also needs PCRaster to be installed. And for Windows, you can do that easily with the OSGeo4W installer. Now I'm going to install the QGIS Hub plugin, which gives us access to all these resources that you could see on the website. It adds this icon. And after clicking the icon, it will for the first time download all the thumbnails. Then you will find the processing scripts at the bottom. And you can increase the size of the thumbnails to have a better look of what it is. And here I'm going to use the headwater catchments tool. And you see that it shows me the dependency. And I'm going to use the add script to QGIS button, so it will be immediately added to the processing toolbox. Close the dialog. Now let's see if we can find the tool in our processing toolbox. Open the processing toolbox panel, and expand scripts and PCRaster user scripts to find the headwater catchment tool. As the LDD layer, add your flow direction. As a minimum Strahler order, put the threshold for which you consider it a river. And uh add the size of your maximum headwater catchments. And don't forget to save the raster in the PCRaster map format. Click run. And there's the result. You can style it with the paletted unique values renderer, because each headwater catchment has a unique non-zero value. If I remove the zeros, then I find here the headwaters. Now let's check if the result makes sense. I'm going to convert these patches to vector polygons. And I do that by raster conversion polygonize. Make sure the headwater catchments layer is the input and save the output as a polygon vector layer. Here I use a GeoPackage. Remember that we also had the zeros. Easy way to get rid of the zero polygon is to select the outside area and delete it. Also, make sure that you add the projection because with these tools with PCRaster, the projection can get lost and then you can't calculate areas. Next, I open the attribute table and go to the field calculator to calculate the area in square kilometers. I use the area function, which is the area in square meters, and then I divide it by a million to end up with square kilometers. And there's the result and you see that they're all around 1 square kilometer. Some very small values are geometrical errors from the conversion to polygons. Let's style the polygons. And there's the final result. So, in this video I demonstrated how to add a QGIS processing script to the processing toolbox. If you want to learn more about QGIS processing scripts, how to make it yourself, then please contact me if you want a course.