[GIS] How to insert data into postgis database table

databasepostgis

I am a newbie in spatial database, so I am having lots of issues even in small tasks and now I am having some issue with inserting data to the table. I have followed the postgis documentation but however, I'm getting some error while inserting data to the table.
In the code below, I am trying to insert an array of co-ordinates which are in long/lat format by converting them into points and adding to the table.

INSERT INTO route(ID, ROUTE_NAME, geom)
VALUES (1, 'route 1', ST_GeomFromText('LINESTRING(ST_MakePoint(27.69858, 85.28154), ST_MakePoint(27.69804, 85.28155), ST_MakePoint(27.69337, 85.28174), ST_MakePoint(27.69356, 85.28275), ST_MakePoint(27.69378, 85.28370), ST_MakePoint(27.69409, 85.28449))',900913));

Table create structure:
CREATE TABLE ROUTE( ID int4, ROUTE_NAME varchar(25), geom geometry(LINESTRING,900913) );

But, I am getting "LINESTRING(ST" <– parse error at position 13 within geometry error.

Best Answer

No need for ST_MakePoint, just chain your coordinates in ST_GeomFromText. You can just write something like ST_GeomFromText('LINESTRING(27.69858 85.28154, 27.69804 85.28155, 27.69337 85.28174, 27.69356 85.28275, 27.69378 85.28370, 27.69409 85.28449)', 900913). x and y parts of coordinates are separated by space, coordinate-pairs by commas. See also the ST_GeomFromText documentation for more information.