Answers:
如果您正在寻找一个PostGIS函数,该函数将告诉您多边形内的点,则ST_PointOnSurface函数可能会为您提供所需的信息。
SELECT
ST_AsText(ST_PointOnSurface('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'::geometry));
st_astext
----------------
POINT(2.5 2.5)
(1 row)
在PostGIS邮件列表中找到此功能。我想这就是您的要求:
CREATE OR REPLACE FUNCTION point_inside_geometry(param_geom geometry)
RETURNS geometry AS
$$
DECLARE
var_cent geometry := ST_Centroid(param_geom);
var_result geometry := var_cent;
BEGIN
-- If the centroid is outside the geometry then
-- calculate a box around centroid that is guaranteed to intersect the geometry
-- take the intersection of that and find point on surface of intersection
IF NOT ST_Intersects(param_geom, var_cent) THEN
var_result := ST_PointOnSurface(ST_Intersection(param_geom, ST_Expand(var_cent, ST_Distance(var_cent,param_geom)*2) ));
END IF;
RETURN var_result;
END;
$$
LANGUAGE plpgsql IMMUTABLE STRICT
COST 100;