TransWikia.com

Creating Line (MultiLineString) layer out of CSV file

Geographic Information Systems Asked by Malibu JJ on November 6, 2020

I need to replicate a *.qgs-file that has 4 different layers as shown in the picture below:

layers

The layer that I am currently trying to replicate is the "links" layer. The information of the layer property is as below:

layer information

The attribute table of this layer looks like this:

Attribute Table

The csv file, which is the source of the layer in question, looks exactly the same with the exception of the last two columns.

I was able to display the layer visualization using the "Points to Path", that comes from the "Processing Toolbox". However, I don’t get the same attribute table as shown previously. In addition, it is not that straightforward as I had to manipulate the csv files beforehand.

I created a "To_From" column and created one csv file for "To_From" filled with "to" and one csv file for "To_From" filled with "from". After that, I add both files using "Add>Add Layer>Add Delimited Text Layer". Subsequently, I merge the layers and create a column "order" with 0 for "to" and 1 for "from". Only after this, I am able to use the "Points to Path".

I wonder if there is an alternative way for my current approach in which I am able to get the attribute table attached previously…

I am using QGIS 3.10.5-A Coruña.

2 Answers

I'm not sure whethter I understand your question correctly! But I would try something like the following steps:

  1. Open the csv with "Layer -> Add Layer -> Add Delimited Text Layer" using "No geometry"
  2. Open the File Calculator in the Attribute Table and create a new field with code similar to: geom_to_wkt( make_line( make_point( "xFrom" , "yFrom" ) , make_point( "xTo" , "yTo" ) ) )
  3. export the table to a csv file
  4. Import the new csv file with "Layer -> Add Layer -> Add Delimited Text Layer" using the new column as wkt-geometry

Good luck!

Answered by oekoplaner on November 6, 2020

Put eye on the following workflow

  1. Drag&Drop your .csv-file with attributes into QGIS

    input

  2. Deploy a Virtual Layer through Layer > Add Layer > Add/Edit Virtual Layer... to obtain a layer with geometry, i.e. flows.

    SELECT *, setsrid(
                      make_line(
                                make_point("X_From","Y_From"),
                                make_point("X_To","Y_To")
                                ),
                      #here use your SRID, e.g. 25833
                      ) 
    FROM "test"
    
  3. Get the Output

    result

Answered by Taras on November 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP