Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two PostGIS tables, one where I store points, named "nodes" and another with where I store multilinestrings, named "lines". I'm trying to append a new vertex to a line using one of the nodes executing a query similar to the following SQL sentence:

the_geom = ST_AddPoint(the_geom, (select the_geom from nodes where id_node='XXXXX')  )
WHERE id_line='YYYY'

But I get:

ERROR: lwline_deserialize: attempt to deserialize a line which is really a Invalid type

Any suggestions?

share|improve this question
Maybe it only works with LineString, not MultiLineString. – underdark Apr 23 '11 at 19:49
up vote 3 down vote accepted

You have version 1.5? That's the error you get if you attempt to use ST_AddPoint() with a MULTILINESTRING geometry.

For this type, you need to specify which part of the line needs to be appended to, then use a messy combination of ST_Dump()/ST_Collect() to modify that part.

For example, to append the point to the last LineString:

SELECT id_line, ST_AsEWKT(ST_Collect(geom))
  SELECT id_line, CASE
    WHEN (dump).path[1] = ngeo THEN
      ST_AddPoint((dump).geom, (select the_geom from nodes where id_node='XXXXX'))
    END AS geom
  FROM (
    select id_line, ST_NumGeometries(geom) ngeo, ST_Dump(geom) as dump from lines
  ) AS foo
) AS foo
GROUP BY id_line;

where id_line is your primary key. You can modify this to an UPDATE query.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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