1

I'm using QGIS 2.8 and I'm trying to apply the FlowMapper plugin to create a visualization. I aim to follow the instructions in this blog post and this GIS.SE question, but something seem be going wrong.

The error is as follows:

2020-11-04T19:45:59 1 Traceback (most recent call last): File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/FlowMapper/flowmapper.py", line 2655, in run SaveDirectory = SaveShpName NameError: global name 'SaveShpName' is not defined

I'm not sure what to do about this. So far, I've tried changing the input files by either switching to spaces instead of tabs between the data columns. That did not help though.

Added: Here are the files I've used. First, there is the locations of the cities: enter image description here

Then there's the labels associated with them: enter image description here

And finally, the incidence matrix: enter image description here

All columns are separated by spaces. The paths to the respective files are:

/Users/maxmuller100/Documents/Data_Project/stud-steden-locaties.txt

and

/Users/maxmuller100/Documents/Data_Project/stud-steden-labels.txt

and

/Users/maxmuller100/Documents/Data_Project/stud-steden-matrix.txt

6
  • @Taras Thank you for the link to that document. I'm not really sure how to answer your question. What symbols do you mean? By the way, do you think it'd help If I showed screenshots of the input files I've made?
    – Max Muller
    Nov 5 '20 at 14:43
  • 1
    @Taras I've added the files! I'm very interested to hear what you think about them.
    – Max Muller
    Nov 6 '20 at 12:02
  • @Taras I've added the path names of the text files at the end of the question
    – Max Muller
    Nov 6 '20 at 12:53
  • @Taras I'm afraid not, I get the same error message.
    – Max Muller
    Nov 6 '20 at 13:00
  • @Taras Yeah maybe it's better to try another workflow. I think I'm going to follow the approach in: youtube.com/watch?v=gXp0FJAkql0
    – Max Muller
    Nov 6 '20 at 13:10
2

An error in line 2655 refers to this part of the code in flowmapper.py

#SaveDirectory = os.path.realpath(SaveShpName)
SaveDirectory = SaveShpName
flowpyv07.shapefilemaker(FlowType,CreateShpNodes,IncludeNodeNames,str(SaveDirectory), str(SaveShpName),str(SaveShpNameNodes),str(InputMatrixName),str(InputNodesName),str(InputNodeNamesName),str(combotext))

and it appears because SaveShpName was incorrectly initialized in flowpyv07.py via the function

def shapefilemaker(typeofcalculation,CreateShpNodes,IncludeNodeNames,fulldirectorystring,outputfilename,outputfilenamenodes,fulldirODinput,fulldirPTinput,fulldirPTNamesinput,combotext):

where some(or all) variables fulldirODinput,fulldirPTinput,fulldirPTNamesinput can not be created with a built-in function open(filename, 'r') probably due to issues in the input file content or a path to each of them.

So, there are several solutions I may suggest:


A short-time solution

I could get the desired flows in QGIS Wien 2.8.9, see image below.

result

When I opened your initial file "stud-steden-matrix.txt" in Notepad++ I see this

notepad++

but when I open the same file in simple Windows's Notepad the result is different

notepad

So, all text files have to be formatted appropriately.

This is a FlowMapper's working window:

flow_mapper_window


A long-time solution

  1. I assume that the Plugin's developer (@cempro) will highly appreciate if you can assist with FlowMapper Plugin migration to QGIS 3.

  2. Using a Virtual Layer, implementation was described in this article.

  3. Setting a new workflow for QGIS 3 and putting as a possible solution here. For instance, I just implemented a workflow with native QGIS tools.

    1. Import a text file with points step_11 step_12

    2. Generating all possible line connections between all points, you can use one of the possible approach described in this thread.

      For example, I used solution with a Virtual Layer with the following query

       select a.id || '_' || b.id as keyf, a.id as fromp, b.id as top, makeline(a.geometry, b.geometry) as geometry
       from "stud-steden-locaties" a, "stud-steden-locaties" b
       where a.id <> b.id
      

      Note: Here I created a special field with a.id || '_' || b.id this will play a key role in joining attributes from "stud-steden-matrix-list.csv"

      step_2

    3. Drag&Drop "stud-steden-matrix-list.csv" into QGIS and apply a simple join between lines and .csv-file.

      step_31 step_32

    4. Apply some visualization techniques to get flows, see image below

      result

      It is possibly a complicated solution, so you may find a smarter one.


References:

1
  • 1
    Thank you for all your help!
    – Max Muller
    Nov 7 '20 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.