From e756240e0edecec51b11a410626be0f9bfa74677 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Mon, 18 Nov 2024 18:19:05 -0800 Subject: [PATCH] Use ST_Point --- demo/functions.sql | 6 +++--- demo/hexagon.sql | 14 +++++++------- .../examples/ex_query_functions_locate_country.md | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/demo/functions.sql b/demo/functions.sql index ab4a6355..ed2de3eb 100644 --- a/demo/functions.sql +++ b/demo/functions.sql @@ -143,7 +143,7 @@ BEGIN SELECT c.name::text, c.abbrev::text, c.postal::text FROM ne.admin_0_countries c WHERE ST_Intersects(c.geom, - ST_SetSRID( ST_MakePoint(lon, lat), 4326)) + ST_Point(lon, lat, 4326)) LIMIT 1; END; $$ @@ -167,7 +167,7 @@ BEGIN SELECT n.name::text, n.geom FROM (SELECT c.geom FROM ne.admin_0_countries c WHERE ST_Intersects(c.geom, - ST_SetSRID( ST_MakePoint(lon, lat), 4326)) + ST_Point(lon, lat, 4326)) LIMIT 1) AS t JOIN LATERAL (SELECT * FROM ne.admin_0_countries n WHERE ST_Touches(t.geom, n.geom)) AS n ON true; @@ -188,7 +188,7 @@ RETURNS TABLE(name text, dist double precision, geom geometry) AS $$ BEGIN RETURN QUERY - SELECT gn.name, gn.geom <-> ST_SetSRID( ST_MakePoint(pt_lon, pt_lat), 4326) AS dist, gn.geom + SELECT gn.name, gn.geom <-> ST_Point(pt_lon, pt_lat, 4326) AS dist, gn.geom FROM geonames gn ORDER BY dist LIMIT k; END; diff --git a/demo/hexagon.sql b/demo/hexagon.sql index 88fa550c..32cd844c 100644 --- a/demo/hexagon.sql +++ b/demo/hexagon.sql @@ -10,13 +10,13 @@ cx float8 := 1.5*i*edge; cy float8 := h*(2*j+abs(i%2)); BEGIN RETURN ST_MakePolygon(ST_MakeLine(ARRAY[ - ST_MakePoint(cx - 1.0*edge, cy + 0), - ST_MakePoint(cx - 0.5*edge, cy + -1*h), - ST_MakePoint(cx + 0.5*edge, cy + -1*h), - ST_MakePoint(cx + 1.0*edge, cy + 0), - ST_MakePoint(cx + 0.5*edge, cy + h), - ST_MakePoint(cx - 0.5*edge, cy + h), - ST_MakePoint(cx - 1.0*edge, cy + 0) + ST_Point(cx - 1.0*edge, cy + 0), + ST_Point(cx - 0.5*edge, cy + -1*h), + ST_Point(cx + 0.5*edge, cy + -1*h), + ST_Point(cx + 1.0*edge, cy + 0), + ST_Point(cx + 0.5*edge, cy + h), + ST_Point(cx - 0.5*edge, cy + h), + ST_Point(cx - 1.0*edge, cy + 0) ])); END; $$ diff --git a/hugo/content/examples/ex_query_functions_locate_country.md b/hugo/content/examples/ex_query_functions_locate_country.md index 048b6163..5c7527df 100644 --- a/hugo/content/examples/ex_query_functions_locate_country.md +++ b/hugo/content/examples/ex_query_functions_locate_country.md @@ -25,7 +25,7 @@ BEGIN SELECT c.name::text, c.abbrev::text, c.postal::text FROM ne.countries c WHERE ST_Intersects(c.geom, - ST_SetSRID(ST_MakePoint(lon, lat), 4326)) + ST_Point(lon, lat, 4326)) LIMIT 1; END; $$ @@ -37,7 +37,7 @@ IS 'Finds the country at a geographic location'; Notes: -* The function generates a [Point](https://postgis.net/docs/ST_MakePoint.html) based on the longitude and latitude values provided in the parameters. +* The function generates a [Point](https://postgis.net/docs/ST_Point.html) based on the longitude and latitude values provided in the parameters. * The `ne.countries` table is filtered based on whether the point [intersects](https://postgis.net/docs/ST_Intersects.html) a country polygon. * It's possible that a point lies exactly on the boundary between two countries. Both country records will be included in the query result set, but `LIMIT 1` restricts the result to a single record.