1

I'm trying to create a linestring based on a value in a column in PostGIS. My code looks like this:

create view left_span as 
SELECT st_geomfromtext('LINESTRING(line_att.wkt_left)', 27700) as geom
FROM line_att 

It creates the view but without any results.

When I try to select just LINESTRING:

SELECT st_geomfromtext('LINESTRING(line_att.wkt_left)', 27700) as geom
FROM line_att 

I get this error:

ERROR:  parse error - invalid geometry HINT:  "LINESTRING(li" <--
parse error at position 13 within geometry
********** Error **********

My column structure looks like this:

wkt_left
608499.156438 127925.765696, 608583.734491 127621.137605
609186.961722 128406.984816, 609287.145785 128550.322806

Calling just one row works fine.

6

I think the issue here is with your WKT construction:

SELECT st_geomfromtext('LINESTRING(line_att.wkt_left)', 27700)

will try to create a geometry from the WKT

'LINESTRING(line_att.wkt_left)'

which is invalid.

Try using string concatenation to ensure the wkt_left values are being inserted into the string:

SELECT st_geomfromtext('LINESTRING('||line_att.wkt_left||')', 27700) as geom
FROM line_att 

This should result in the WKT

'LINESTRING(608499.156438 127925.765696, 608583.734491 127621.137605)'

which is a valid linestring.

More info on string on string functions and operators can be found here.

  • Thanks! it solved to problem :) for some weird reason it shows me that result is empty but when i go inside the table is fine. – Losbaltica Jan 24 '17 at 9:14
  • I'm not sure what's going on with your result without seeing the data but I'm glad my answer helped – Ali Jan 24 '17 at 9:35
  • Do you know if i can load view table inside qgis? – Losbaltica Jan 24 '17 at 10:10
  • 1
    You can, just follow the same procedure as you would for a table. You have to also include a primary key column in your view. – Ali Jan 24 '17 at 10:21

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.