I have a table with MULTILINESTRING objects and I want to build a query that outputs the shortest distances between every MULTILINESTRING object and a specific point (the same for all records) using PostGIS. The coordinate system is WGS84.
I'd like a result like the following:
MULTILINESTRING(....) distance1 MULTILINESTRING(....) distance2 MULTILINESTRING(....) distance3
I have tried commands like the following:
SELECT ST_AsText(ST_Distance(geom, st_GeomFromText('POINT(25.3622 35.3621)'), 4326)) FROM my_table;
But it raises the following error:
ERROR: function st_distance(geometry, geometry, integer) does not exist LINE 1: SELECT ST_AsText(ST_Distance(geom, st_GeomFromText('POINT(25... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. ********** Error ********** **********
I feel that the answer is easy but I have no much experience in SQL.
After more searching I think that I'm closer to the solution. I run the following SQL code in order to calculate the shortest distance between a Point and Multilinestring records from "my_table" table:
SELECT geom FROM my_table ORDER BY ST_Distance(geom, ST_SetSRID(ST_GeogFromText('POINT(25.3622 35.3621)'), 4326), true ) ASC LIMIT 1;
This code works and gives me the geometry with the shortest distance:
geom geometry(MultiLineString,4326) <geometry object>
But how can I take the corresponding number (distance) ?