PostGIS 中最近邻搜索错误
Error in nearest neighbor search in PostGIS
我正在尝试编写一个 PostGIS 最近邻查询,其中选择了一组坐标并确定了距最近的洪水多边形的距离。然后我想将距离分类为“外部,'CLOSE' 或 'INSIDE':
WITH
point_loc (geom) AS (
SELECT ST_SetSRID(ST_MakePoint(531673.0, 180848.2),27700) ),
distances (gid, distance) AS (
SELECT
fl.gid,
ST_Distance(fl.geom, p.geom) AS distance
FROM
point_loc p, flooding fl
WHERE ST_DWithin(p.geom, fl.geom, 400)
SELECT
gid,
CASE WHEN distance > 300 THEN 'OUTSIDE'
WHEN distance > 50 AND <= 300 THEN 'CLOSE'
ELSE 'INSIDE'
END as flood_result
FROM distances;
我在最后的 SELECT 调用中不断收到语法错误。谁能看出我做错了什么?
您的第二个 CTE 缺少右括号。
这一行:
WHERE ST_DWithin(p.geom, fl.geom, 400)
应该是:
WHERE ST_DWithin(p.geom, fl.geom, 400) )
我正在尝试编写一个 PostGIS 最近邻查询,其中选择了一组坐标并确定了距最近的洪水多边形的距离。然后我想将距离分类为“外部,'CLOSE' 或 'INSIDE':
WITH
point_loc (geom) AS (
SELECT ST_SetSRID(ST_MakePoint(531673.0, 180848.2),27700) ),
distances (gid, distance) AS (
SELECT
fl.gid,
ST_Distance(fl.geom, p.geom) AS distance
FROM
point_loc p, flooding fl
WHERE ST_DWithin(p.geom, fl.geom, 400)
SELECT
gid,
CASE WHEN distance > 300 THEN 'OUTSIDE'
WHEN distance > 50 AND <= 300 THEN 'CLOSE'
ELSE 'INSIDE'
END as flood_result
FROM distances;
我在最后的 SELECT 调用中不断收到语法错误。谁能看出我做错了什么?
您的第二个 CTE 缺少右括号。
这一行:
WHERE ST_DWithin(p.geom, fl.geom, 400)
应该是:
WHERE ST_DWithin(p.geom, fl.geom, 400) )