Skip to content

Commit

Permalink
Use ST_Point
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Nov 19, 2024
1 parent ba95540 commit e756240
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions demo/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
$$
Expand All @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions demo/hexagon.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
$$
Expand Down
4 changes: 2 additions & 2 deletions hugo/content/examples/ex_query_functions_locate_country.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
$$
Expand All @@ -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.

Expand Down

0 comments on commit e756240

Please sign in to comment.