2

I created a dataset with the capacity and production of a product per country.

I am interested in calculating the balances between these different countries. For example, France has a positive balance of 50, Belgium a balance of 10, and Germany a balance of -50.

I am interested in creating a PyQGIS function that calculates balances between these countries based on the distance to optimize these flows; E.G: Germany to Belgium 10, Germany to France 40, equilibrium reached! Are there any existing functions of which I am not familiar with?


output_folder = 'C:/Users/*/Desktop/Extr-act/Output/'
layer5 = QgsVectorLayer(output_folder + "Distance matrix.shp", "Distance matrix", "ogr")
layer6 = QgsVectorLayer(output_folder + "Centroids.shp", "Centroids", "ogr")

with edit(layer6):
    for f in layer6.getFeatures():
        if f["BC_Balance"] < 0:
            for i in layer5.getFeatures():
                if f["CNTR_CODE"] == i["InputID"]:

                    f["Dest"] = ["InputID"]
                    f["Amount"] = 0
            layer5.updateFeature(f)

I have added the question with the code I came up with so far.

enter image description here enter image description here

https://drive.google.com/drive/folders/1WCllWC2dgSCsqQ3TokB9obO90jd4ZAoT?usp=sharing

10
  • I am just asking if anyone has an idea of where to start Commented Sep 15, 2020 at 12:00
  • 3
    It seems like your problem can be broken into two pieces. First, figuring out the distances between countries, and then second working in the trade portion. Another piece you need to consider is how the countries will impact each other via shared neighbors. For example, in your France-Belgium-Germany example above, what happens when you get to Poland and Austria - will they change Germany situation? Or would Spain's interaction with France impact how France interacts with Germany? Consider if this might require multiple iterations over each country, rather than a single pass. Commented Sep 15, 2020 at 12:15
  • 1
    Sorry, I don't know QGIS well enough to suggest specific tools. If you edit your original post to include these details on what you've tried so far it might help other people provide better answers. Commented Sep 16, 2020 at 13:33
  • 1
    @BERA I tried to edit my post according to the requests, do you understand my question better now? Commented Sep 16, 2020 at 14:11
  • 1
    No to much work. You could ask this as a pandas question on stackoverflow.
    – Bera
    Commented Sep 21, 2020 at 8:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.