2

I have a data set with a large number of start and end positions. I am trying to generate lines between start and end positions using the Geometry Generator but it does not work. I get no errors when running it, but the lines do not appear. I have found several answers to a similar qestion, e.g. this one, : Creating a line from two points in QGIS I select geometry Type as "LineString. Here is the code I have been trying to use. make_line(make_point("shootlon" ,"shootlat"), make_point("haullon", "haullat"))

enter image description here

Small screenshot of the data, which is a text ("txt") file.
What could be the problem? Some of the older plugins e.g. "Points2one", do not work in QGIS 3.4.4.

Vince
  • 20,017
  • 15
  • 45
  • 64
  • Welcome to GIS.SE. Are your points displayed properly? – Erik Mar 13 '19 at 10:45
  • Thanks. Yes, they are displayed well. The strange this is that the layers show the line symbol in front of the variable for few seconds but then disappears. – Stefán Áki Ragnarsson Mar 13 '19 at 10:47
  • I don't know what you're doing, but the first two rows of your data work fine with your code. Check the symbology and whether your layer is visible or not. – Erik Mar 13 '19 at 10:56
  • Thanks Erik. I also tried with the first two lines and it does not work. In the symbology it says I have created a line but he line is not visible. – Stefán Áki Ragnarsson Mar 13 '19 at 11:21
  • The projection of the generated unseen line layer is "EPSG:4326-WGS84", while some other layers are in "EPSG:3395/World Mercator" – Stefán Áki Ragnarsson Mar 13 '19 at 11:23
  • Hello @Stefán, did you change the Geometry Type to Linestring? – Yannick Arthur DOUNGMO Mar 13 '19 at 11:24
  • Hi Yannick. Yes, using the Geometry type to Linestring /multiLineString – Stefán Áki Ragnarsson Mar 13 '19 at 11:27
  • So, in you have as the Output preview : ? – Yannick Arthur DOUNGMO Mar 13 '19 at 11:31
  • No. Actually I got In the "Expression Dialog" the following "Output preview: NULL" – Stefán Áki Ragnarsson Mar 13 '19 at 11:37
  • I have cracked the problem. The text file from the R (using write.table) had all column names with quotation marks, e.g. "shootlat", "shootlon". These quotation marks do not show up in the Qgis attribute table or in the R itself (wehre I took the screenshot). Furthermore, the script runs but with Output preview: NULL. . So I simply removed the quotation marks and it plots the lines and now I get the Output preview <geometry:linestring Thanks guys for your help. – Stefán Áki Ragnarsson Mar 13 '19 at 11:52
  • Ok then, 1- Import your data (Layer > Add Layer > Add Delimited Text Layer), 2- Select the format or the delimiter, your X (shootlong) and Y (shootlat) fields and be sure that the preview corresponds to what you expect. 3- Load the layer, you should have your points displayed in the Layer Panel.
    1. Follow the answer I suggested with screenshots below
    – Yannick Arthur DOUNGMO Mar 13 '19 at 12:00
  • 1
    Thanks.It works now. I use "quote = FALSE" in the R write table command, i.e." write.table(df, "C://x/x/df.txt", row.names = F, quote = FALSE) and get column headings wtithout quotation marks. – Stefán Áki Ragnarsson Mar 13 '19 at 12:13

1 Answers1

4

This is how my attribute table looks like

enter image description here

This is the expression to use :

make_line(make_point( "Xstart" , "Ystart" ),make_point( "Xend" , "Yend" ))

enter image description here

Then press Ok

Snaileater
  • 5,743
  • 1
  • 15
  • 26