How to distinguish latitude, longitude coordinates as a type of geography postgres

My table has two floating point columns for latitude and longitude coordinates.

I want to use PostGIS ST_DWithin to find all records that are at a certain distance from a given point.

The signature ST_DWithinexpects the first two parameters to be geometric or geographic data types, so I'm sure the solution is to convert lat / lng coordinates to geopolitics, but I can't get it to work.

Here what does not work:

SELECT * 
FROM stops 
WHERE ST_DWithin( ST_GeogFromText('SRID=4326;POINT(-77.09 38.89)'),
                  ST_GeogFromText('SRID=4326;POINT(' || stops.lng || ' ' || stops.lat || ')'), 10000.0)

I get this error:

ERROR: st_geogfromtext function (unknown) does not exist

LINE 1: SELECT * FROM stops WHERE ST_DWithin (ST_GeogFromText ('SRID = ...

What am I doing wrong?

+4
2

Woops.

, () . , PostGIS:

psql -d <DATABASE_NAME_HERE> -c "CREATE EXTENSION postgis";

, , . .

, , .

+1

Gilbert Le Blanc :

SELECT ST_Distance('LINESTRING(-122.33 47.606, 0.0 51.5)'::geography, 
    'POINT(-21.96 64.15)':: geography);

?

0

Source: https://habr.com/ru/post/1620210/


All Articles