According to this SO answer, the way to convert a lat/long to a geography type is
ST_SetSRID(ST_MakePoint(long, lat), 4326)::geography
but so far I've just been using ST_MakePoint(long, lat)::geography
and it seems to work fine. My queries include checks for
ST_Covers(shape, ST_MakePoint(long, lat)::geography)
and I haven't seen that give an incorrect answer. But that doesn't mean it's always going to work.
The shape
column is defined as
shape geography(MULTIPOLYGON, 4326)
so I thought maybe having the SRID in the column definition was doing the same work as ST_SetSRID
. But I really don't know.
Probably not relevant, but just in case: the data comes from Natural Earth's countries data, converted to SQL with
shp2pgsql -GD ne_10m_admin_0_countries.shp table_name
That creates a table with a geog
column also defined as geography(MULTIPOLYGON, 4326)
, and I've copied some of the data from that into the table with shape
.